I'm running Ubuntu 20.04. It works well by forwarding http requests directed at port 8080 of the local machine to another machine's port 80.
But when I set iptables rules to forward smb requests directed at a local machine to another machine running a smb server, it failed. There are only hits in PREROUTING, but no in POSTROUTING.
The iptables commands are the following:
sudo iptables -t nat -A PREROUTING -p tcp --match multiport --dports 445,137,138,139 -j DNAT --to-destination 192.168.10.162
sudo iptables -t nat -A POSTROUTING -d 192.168.10.162 -j MASQUERADE
After running $sudo iptables -t nat -L -v, it shows the following:
Chain PREROUTING (policy ACCEPT 3981 packets, 847K bytes)
pkts bytes target prot opt in out source destination
60 3156 DNAT tcp -- any any anywhere anywhere multiport dports netbios-ns,netbios-dgm,netbios-ssn,microsoft-ds to:192.168.10.162
Chain INPUT (policy ACCEPT 604 packets, 86773 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 57 packets, 4781 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 57 packets, 4781 bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- any any anywhere 192.168.10.162
The Ubuntu 20.04 connects to a switch which connects to another switch to which the other Linux machine connects to. I use a Win10 PC connected to the same switch as Ubuntu 20.04 does to visit Ubuntu 20.04.