21 NAT gateway
A Linux gateway gives a private LAN DHCP, DNS and NAT to the internet, like a home router.
What you practice
- Running your own DHCP and DNS (dnsmasq) on a switch with
dhcp: false - Masquerade and a forward policy in nftables
- Following one connection through NAT with
conntrackandtcpdump
Topology
| Node | Image | CPUs / memory | Addresses | Role |
|---|---|---|---|---|
gw | debian-13 | 1 / 1GiB | mgmt 10.121.0.11; lan 10.121.1.254/24 | DHCP, DNS and NAT for the LAN |
c1 | debian-13 | 1 / 1GiB | lan DHCP | Client, address from gw |
c2 | debian-13 | 1 / 1GiB | lan DHCP | Client, address from gw |
Before you start
bash
vz image pull disk debian-13Run it
bash
cd examples/21-nat-gateway
vz validate
vz up
vz node ls
ssh lab@10.121.0.11 # password: labFirst boot installs packages; give it a minute or two after vz up returns.
Try it
bash
ssh lab@10.121.0.11 'cat /var/lib/misc/dnsmasq.leases' # the clients' addresses
vz node console c1
# ip route; resolvectl status; curl -sI https://deb.debian.org | head -1
ssh lab@10.121.0.11 'sudo nft list ruleset; sudo tcpdump -ni mgmt -c 5'Notes
The Mac is a member of every vmnet switch, so it also has an address on lan (10.121.1.1). It does not route; the clients' default route is the gateway. The clients have no mgmt NIC: their only way out is through gw.
Clean up
bash
vz down
vz destroy --yes # deletes the overlays and state of this lab