透過 iptables 設定 NAT

透過 iptables 設定 NAT

我想改變這一點:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
178.212.120.5   192.168.1.254   255.255.255.255 UGH   0      0        0 eth2.2
208.67.222.222  192.168.1.254   255.255.255.255 UGH   0      0        0 eth2.2
192.168.1.0     *               255.255.255.0   U     0      0        0 eth2.2
192.168.10.0    *               255.255.255.0   U     0      0        0 br0
239.0.0.0       *               255.0.0.0       U     0      0        0 br0
default         192.168.1.254   0.0.0.0         UG    0      0        0 eth2.2

進入這個:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
178.212.120.5   192.168.1.254   255.255.255.255 UGH   0      0        0 ra0
208.67.222.222  192.168.1.254   255.255.255.255 UGH   0      0        0 ra0
192.168.1.0     *               255.255.255.0   U     0      0        0 ra0
192.168.10.0    *               255.255.255.0   U     0      0        0 br0
239.0.0.0       *               255.0.0.0       U     0      0        0 br0
default         192.168.1.254   0.0.0.0         UG    0      0        0 ra0

並以以下方式配置 NAT:

  1. 公共 NAT 介面帶有ra0IP192.168.1.3
  2. NAT 內部子網路已192.168.10.0/24開啟br0

我遇到的問題是我知道如何使用 Linuxrouteifconfig命令,但我對iptables.

答案1

一個「粗略且準備好的」答案是使用route和ifconfig來設定ra介面和路由,然後發出iptables命令 -

/sbin/iptables -t nat -I POSTROUTING -o ra0 -j MASQUERADE

這將偽裝(所有)流量從 ra0 發出,但不從 br0 發出。但我注意到「ra0 的 NAT 介面實際上並不是真實世界的 IP 位址,因此要么您將執行雙重 nat,要么該 IP 位址不正確。

相關內容