Setting up a NAT gateway on Rocky Linux 9 (and Hetzner) » 22 November 2023
This is mostly a note to myself, because I suck at Linux networking.
The general idea is to have a virtual network (this time at Hetzner) with a reverse proxy VM that has a couple of other VMs that have no public IPs. Sometimes these worker VMs also need love Internet access, so let’s set up a NAT gateway.
-
Add a route to the vnet, where the destination is 0.0.0.0/0, and the gateway is the IP of the… well, the gateway.
-
On the server
echo 1 > /proc/sys/net/ipv4/ip_forward
, theniptables -t nat -A POSTROUTING -s '10.0.0.0/16' -o eth0 -j MASQUERADE
, of course replace any IP addresses as needed -
On the clients
ip route add default via 10.0.0.1
, then edit/etc/resolv.conf
and add nameservers, each in their own line, likenameserver 1.1.1.1
-
Update all machines, I don’t know why the original guide says this, but hey,
yum update -y && yum upgrade -y
Lastly, to make everything persistent, on the server, edit /etc/NetworkManager/dispatcher.d/ifup-local
and add:
Finally, chmod +x /etc/NetworkManager/dispatcher.d/ifup-local
On the client, first do yum remove hc-utils -y
, then edit /etc/NetworkManager/dispatcher.d/ifup-local
and add:
And again, chmod +x /etc/NetworkManager/dispatcher.d/ifup-local
Once it’s done, I don’t want to touch it ever again.