我有我的SSH服务器侦听端口555.我需要允许一个IP连接到端口22,然后让IPTablesredirect到555(这是因为连接到端口22的软件只能连接到端口22) 。
我目前的IPTables规则如下:
Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT udp -- anywhere anywhere udp dpt:domain ACCEPT tcp -- anywhere anywhere tcp dpt:domain ACCEPT udp -- anywhere anywhere udp dpt:bootps ACCEPT tcp -- anywhere anywhere tcp dpt:bootps ACCEPT udp -- anywhere anywhere udp dpt:domain ACCEPT tcp -- anywhere anywhere tcp dpt:domain ACCEPT udp -- anywhere anywhere udp dpt:bootps ACCEPT tcp -- anywhere anywhere tcp dpt:bootps ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere tcp dpt:ms-wbt-server ACCEPT tcp -- anywhere anywhere state NEW tcp multiport dports 5901:5903,6001:6003 DROP tcp -- anywhere anywhere tcp dpt:telnet DROP tcp -- anywhere anywhere tcp dpt:telnet DROP tcp -- anywhere anywhere tcp dpt:sunrpc DROP tcp -- anywhere anywhere tcp dpt:ircu-2 DROP tcp -- anywhere anywhere tcp dpt:ircu-3 DROP tcp -- anywhere anywhere tcp dpt:ircu-4 DROP tcp -- anywhere anywhere tcp dpt:ircu-5 DROP tcp -- anywhere anywhere tcp dpt:telnet DROP tcp -- anywhere anywhere tcp dpt:ms-wbt-server DROP tcp -- anywhere anywhere tcp dpt:5666 DROP tcp -- anywhere anywhere tcp dpt:5903 Chain FORWARD (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere 192.168.100.0/24 ACCEPT all -- 192.168.100.0/24 anywhere ACCEPT all -- anywhere anywhere REJECT all -- anywhere anywhere reject-with icmp-port-unreachable REJECT all -- anywhere anywhere reject-with icmp-port-unreachable ACCEPT all -- anywhere 192.168.122.0/24 state RELATED,ESTABLISHED ACCEPT all -- 192.168.122.0/24 anywhere ACCEPT all -- anywhere anywhere REJECT all -- anywhere anywhere reject-with icmp-port-unreachable REJECT all -- anywhere anywhere reject-with icmp-port-unreachable TCPMSS tcp -- 172.16.36.0/24 anywhere tcp flags:FIN,SYN,RST,ACK/SYN TCPMSS set 1356 Chain OUTPUT (policy ACCEPT) target prot opt source destination
我是否正确地说,下列规则将做我想要的? (假设192.168.8.8是我想要连接到22的IP)。
iptables -A INPUT -s 192.168.8.8 -p tcp -m tcp --dport 22 -j ACCEPT iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 22 -j REDIRECT --to-port 678
任何帮助表示赞赏。 谢谢!
如果你想让它redirect到555端口,你应该使用
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 22 -j REDIRECT --to-port 555
代替
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 22 -j REDIRECT --to-port 678
除此之外,你的规则是正确的。
此外,使用当前的configuration,您将不需要INPUT规则,因为您目前不阻止连接到端口22(您的INPUT策略设置为ACCEPT )。