1.5 KiB
1.5 KiB
Linux+ 3.2.3: NAT and IP forwarding
Turning this VM into a router for a private network with firewalld zones, a policy and masquerading.
Before you start
RHEL family only. The peer, at 10.99.0.2, stands in for the Ubuntu VM.
It sits on this VM's second network, 10.99.0.0/24 (this VM is
10.99.0.1 there, on interface le-host), and its default route already
points at this VM, but it has no way out yet: from the peer,
ping -c 2 9.9.9.9 fails. Get a shell there with
sudo ip netns exec lepeer bash.
The lab installs and starts firewalld, allowing SSH. The interface
le-host isn't managed by NetworkManager, so set its zone with
firewall-cmd rather than nmcli. Keep a console open: a firewall mistake
can cut off SSH.
Tasks
- Put
le-hostin firewalld'sinternalzone, persistently. - Create a firewalld policy
int-to-pubthat accepts traffic from zoneinternalto zonepublic, and turn on masquerading in the zone of the main interface, both persistently. Checknet.ipv4.ip_forward. - From the peer,
ping -c 2 9.9.9.9now works. Watch the translation on this VM withtcpdump -ni any icmpwhile it runs.
Hints
firewall-cmd --permanent --zone=internal --change-interface=le-host,--get-active-zones.firewall-cmd --permanent --new-policy NAME, then--policy NAMEwith--add-ingress-zone,--add-egress-zoneand--set-target=ACCEPT(firewalld 2.4 takes one of these per command);--info-policy NAME.--zone=public --add-masquerade, with--permanenttoo;--reload.