Interview Prep/Linux/Networking, SSH and remote access

Your app servers need to reach the internet for updates but must not be reachable from it. How do you set it up on a Linux gateway?

IntermediateScenarioNetworking, SSH and remote access
Answer

Situation read → A NAT gateway with forwarding and masquerade.

What I'd do →

echo 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/90-forward.conf && sudo sysctl --system
sudo nft add table ip nat
sudo nft add chain ip nat postrouting '{ type nat hook postrouting priority 100; }'
sudo nft add rule ip nat postrouting oifname "eth0" ip saddr 10.0.2.0/24 masquerade

Add forward rules that allow 10.0.2.0/24 -> eth0 and only established/related traffic back. Save with nft list ruleset > /etc/nftables.conf.

Why → Outbound connections are translated; unsolicited inbound has no NAT mapping and is dropped.

Interview tip → In AWS, say you'd use a managed NAT Gateway rather than run this yourself.

All Linux questions Roadmap: Linux

More on Networking, SSH and remote access