Interview Prep/Linux/Networking, SSH and remote access

You need to forward port 80 on a Linux host to a container or VM on 10.0.3.5:8080. How?

AdvancedScenarioNetworking, SSH and remote access
Answer

Situation read → DNAT plus forwarding.

What I'd do →

sudo sysctl -w net.ipv4.ip_forward=1
sudo nft add table ip nat
sudo nft add chain ip nat prerouting '{ type nat hook prerouting priority -100; }'
sudo nft add rule ip nat prerouting iifname "eth0" tcp dport 80 dnat to 10.0.3.5:8080
sudo nft add chain ip nat postrouting '{ type nat hook postrouting priority 100; }'
sudo nft add rule ip nat postrouting ip daddr 10.0.3.5 masquerade

Persist in /etc/nftables.conf and make ip_forward permanent in /etc/sysctl.d/.

Why → DNAT rewrites the destination; masquerade makes return traffic come back through this host.

Interview tip → Mention that locally generated traffic hits the output hook, not prerouting, so testing from the same host needs an extra rule.

All Linux questions Roadmap: Linux

More on Networking, SSH and remote access