router / dnsmasq

Install LXD

CONTAINER=router
 
lxc launch ubuntu:20.04 ${CONTAINER}
lxc file push --uid 0 --gid 0 --mode 600 ~/.ssh/id_rsa.pub ${CONTAINER}/root/.ssh/authorized_keys
 
lxc config device add router eth1 nic nictype=physical parent=enp7s0
 
lxc exec ${CONTAINER} -- bash -c "apt update -qq && apt dist-upgrade -y"
 
ssh root@${CONTAINER}
 
apt install -y dnsmasq
 
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sysctl -w net.ipv4.ip_forward=1
 
cat <<EOF> /etc/netplan/50-cloud-init.yaml 
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
        eth1:
            dhcp4: no
            addresses:
              - 192.168.0.1/24
EOF
 
netplan apply
 
# configure dns
systemctl disable systemd-resolved
systemctl stop systemd-resolved
 
echo "nameserver 8.8.8.8" > /etc/resolv.conf
 
 
cat <<EOF> /etc/systemd/system/masquerade.service
[Unit]
Description=Enable MASQUERADE
After=network.target
 
[Service]
ExecStart=/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 
[Install]
WantedBy=multi-user.target
EOF
 
systemctl enable masquerade.service
 
 
diff /etc/dnsmasq.conf.org /etc/dnsmasq.conf
106c106
< #/etc/dnsmasq.conf.org /etc/dnsmasq.conf/etc/dnsmasq.conf.org /etc/dnsmasq.conf
---
> interface=eth1
157c157
< #dhcp-range=192.168.0.50,192.168.0.150,12h
---
> dhcp-range=192.168.0.50,192.168.0.150,12h
653c653
< #log-queries
---
> log-queries
656c656,658
< #log-dhcp
---
> log-dhcp
> 
> log-facility=/var/log/dnsmasq.log
 
service dnsmasq restart