Iptables

iptables DNAT 更改未顯示在 Wireshark 中

  • June 16, 2021

我想將介面上的所有傳入流量重新路由ens4f0到 IP 地址 192.168.50.10,但 Wireshark 顯示傳入數據包的目標 IP 地址未更改。這是預期的行為嗎?我以為 PREROUTING 先於其他任何東西進入?

我的iptables命令是:

# iptables -t nat -A PREROUTING -i ens4f0 -j DNAT --to 192.168.50.10
# iptables -t nat -vL
Chain PREROUTING (policy ACCEPT 24618 packets, 1923K bytes)
pkts bytes target     prot opt in     out     source               destination         
   0     0 DNAT       all  --  ens4f0 any     anywhere             anywhere             to:192.168.50.8
   0     0 DNAT       all  --  ens4f0 any     anywhere             anywhere             to:192.168.50.10
   0     0 DNAT       all  --  ens4f0 any     anywhere             anywhere             to:192.168.50.10

我知道傳入的數據包來自 192.168.50.8,所以我也嘗試過:

# iptables -t nat -A PREROUTING -i ens4f0 -j DNAT -s 192.168.50.8/32 --to 192.168.50.10
# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
DNAT       all  --  anywhere             anywhere             to:192.168.50.8
DNAT       all  --  anywhere             anywhere             to:192.168.50.10
DNAT       all  --  anywhere             anywhere             to:192.168.50.10
DNAT       all  --  192.168.50.8         anywhere             to:192.168.50.10

Wireshark在防火牆處理之前擷取傳入的數據包(以及在防火牆處理之後的出站數據包),因此您無法在此數據包擷取中看到防火牆對入站數據包所做的更改。嘗試在出介面上擷取以查看修改後的數據包。

引用自:https://serverfault.com/questions/1066924