![使用 iptables 进行端口转发时出错?](https://linux22.com/image/962668/%E4%BD%BF%E7%94%A8%20iptables%20%E8%BF%9B%E8%A1%8C%E7%AB%AF%E5%8F%A3%E8%BD%AC%E5%8F%91%E6%97%B6%E5%87%BA%E9%94%99%EF%BC%9F.png)
我有一个相当标准的 ubuntu 安装,并希望添加端口转发。
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#Redirect 1731 to 8443
-t nat -A PREROUTING -i eth0 -p tcp --dport 1731 -j REDIRECT --to-port 8443
#Allow 443 and 80
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
但是我一直收到错误:
iptables: Applying firewall rules: iptables-restore v1.4.7: Line 13 seems to have a -t table option.
我已确认该设备已启用 IP 转发:
cat /proc/sys/net/ipv4/ip_forward
1
我确信我遗漏了 iptables 格式中的一些简单内容。您觉得呢?
答案1
以 开头的行-t nat
不应该位于过滤表下方,如第一行所示。
将文件更改为以下内容:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#Allow 443 and 80
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
#Redirect 1731 to 8443
-A PREROUTING -i eth0 -p tcp --dport 1731 -j REDIRECT --to-port 8443
COMMIT