Host:3022 -> VM:22
such that ssh -p 3022 localhost works fine. Now I want to add another port forwarding using iptables to achieve:
Host:22 -> (forward) Host:3022 -> VM:22
such that
Code: Select all
$ ssh locahostCode: Select all
$ ssh hostThis is my current approach
Code: Select all
# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere anywhere tcp dpt:ssh to:127.0.0.1:3022
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destinationCode: Select all
# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere localhost tcp dpt:3022 state NEW,RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)
target prot opt source destinationCode: Select all
$ ssh -p 3022 localhostCode: Select all
$ ssh localhostCode: Select all
ssh: connect to host localhost port 22: Connection refusedCode: Select all
net.ipv4.ip_forward = 1These are the commands, that I used to install the iptable rules:
Code: Select all
iptables -t nat -A PREROUTING -p tcp -i eno1 --dport 22 -j DNAT --to-destination 127.0.0.1:3022
iptables -A FORWARD -p tcp -d 127.0.0.1 --dport 3022 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPTWhat is it, that I am missing?
EDIT:
Code: Select all
# netstat -lntu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3022 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:222 0.0.0.0:* LISTEN
tcp6 0 0 :::222 :::* LISTEN
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:7001 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp6 0 0 :::5353 :::* 
