Examples and links on how to do port forwarding on
- Linux using
iptables
- MacOS with
pfctl
(control the packet filter (PF) and NAT device) - with
ssh
Additional topic/link:
sudo iptables -A FORWARD -i wlan0 -o eth0 -p tcp --syn --dport 3389 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -p tcp --syn --dport 3389 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o wlan0 -p tcp --syn --dport 3389 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#sudo iptables -P FORWARD DROP
sudo iptables -t nat -A PREROUTING -p tcp -i wlan0 --dport 3389 -j DNAT --to-destination 192.168.1.10:3389
sudo iptables -t nat -A POSTROUTING -p tcp -o eth0 --dport 3389 -d 192.168.1.10
sudo iptables -t nat -I PREROUTING -p tcp -i wlan0 --dport 33389 -j DNAT --to-destination 192.168.1.10:33389
sudo iptables -t nat -I POSTROUTING -p tcp -o eth0 --dport 33389 -d 192.168.1.10 -j SNAT --to-source 192.168.2.77
echo "
rdr pass inet proto tcp from any to any port 33389 -> 192.168.152.130 port 3389
rdr pass inet proto udp from any to any port 33389 -> 192.168.152.130 port 3389
" | sudo pfctl -ef -
echo "
rdr pass inet proto tcp from any to any port 33389 -> 127.0.0.1 port 3389
rdr pass inet proto udp from any to any port 33389 -> 127.0.0.1 port 3389
" | sudo pfctl -ef -
# sudo pfctl -F all -f /etc/pf.conf
# sudo pfctl -s nat
ssh -L 0.0.0.0:3389:192.168.152.130:3389 [email protected]
ssh -L 0.0.0.0:3389:192.168.1.10:3389 [email protected]
ssh -L 0.0.0.0:3389:127.0.0.1:3389 [email protected]