如何在 Red Hat Linux (RHEL) 中使用 IPTables 重新導向連接埠?

如何在 Red Hat Linux (RHEL) 中使用 IPTables 重新導向連接埠?

我想將連接埠 80 轉發到 8080 /etc/syscongfig/iptables

-A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

但得到:

# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules: iptables-restore v1.4.7: 
          Line 8 seems to have a -t table  option.

有什麼問題?應該怎麼做呢?

答案1

檔案是否/etc/syscongfig/iptables具有正確的 iptables-restore 結構?

嘗試將此規則手動新增至防火牆

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

並與命令/etc/sysconfig/iptables的輸出進行比較iptables-save

答案2

這是你的iptables規則:

-A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

但我相信它應該是這樣的:

-A PREROUTING -t nat -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080

請注意-m tcp添加了。當-p tcp符合要檢查的規則或封包的協定時,-m tcp明確告訴 IPTables 符合 TCP 封包。這似乎令人困惑,但據我所知,-p tcp需要-m tcp在呼叫連接埠特定規則時進行配對。

如果其他人可以擴展此要求背後的基本原理/邏輯,請在評論中加入。

相關內容