我正在使用NAT模式进行访客网络。我需要从客人外面访问我的机器。我已经设置了iptables来将主机上的特定端口转发到guest虚拟机上的端口22,但这似乎不起作用。
我添加了这条规则:
# Port Forwardings
-A PREROUTING -i eth0 -p tcp --dport 9867 -j DNAT --to-destination 192.168.122.136:22
# Forward traffic through eth0 - Change to match you out-interface
-A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE
当我ssh 192.168.122.136
来自主机时,它可以正常运行,但是当我尝试ssh 192.168.122.136 -p 9867
时,它会显示ssh: connect to host 192.168.122.1 port 9867: Connection refused
我已在/etc/ufw/sysctl.conf
使用iptables -t nat -L
表示该规则已在iptable
DNAT tcp -- anywhere anywhere tcp dpt:9867 to:192.168.122.136:22
答案 0 :(得分:0)
找到我的答案here。基本上我把上面改为
# connections from outside
iptables -t nat -A PREROUTING -p tcp --dport 9867 -j DNAT --to 192.168.122.136:22
# for local connection
iptables -t nat -A OUTPUT -p tcp --dport 9867 -j DNAT --to 192.168.122.136:22
# Masquerade local subnet
iptables -t nat -A POSTROUTING -s 192.168.122.0/24 -j MASQUERADE
iptables -A FORWARD -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i virbr0 -o eth0 -j ACCEPT
iptables -A FORWARD -i virbr0 -o lo -j ACCEPT