router / dnsmasq

CONTAINER=router
 
lxc launch ubuntu:18.04 ${CONTAINER}
lxc file push --uid 0 --gid 0 --mode 600 ~/.ssh/id_rsa.pub ${CONTAINER}/root/.ssh/authorized_keys
lxc exec ${CONTAINER} -- bash -c "apt update -qq && apt dist-upgrade -y"
 
apt install dnsmasq
 
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sysctl -w net.ipv4.ip_forward=1
 
root@router:~# cat  /etc/netplan/50-cloud-init.yaml 
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
        eth1:
            dhcp4: no
            addresses:
              - 192.168.0.1/24
 
 
 
# cat /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
 
 
systemctl enable masquerade.service
 
 
root@router:~# diff /etc/dnsmasq.conf.org /etc/dnsmasq.conf
106c106
< #interface=
---
> 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