因此,我有一台 Ubuntu 机器,其接口 eth1 上有多个 VLAN,每个 VLAN 都有相同的 IP 地址 (172.16.0.2)。我需要能够同时远程登录到机架上的设备,这些设备的 IP 地址也相同 (172.16.0.1)。我能想到的唯一方法是通过 IPtables 将流量转发到特定接口的特定目标端口。
例如我希望能够运行“telnet 172.16.0.1 12001”并将这个出站接口 eth1.101 定向到 172.16.0.1:23 或运行“telnet 172.16.0.1 12002”并将这个出站接口 eth1.102 定向到 172.16.0.1:23。
我尝试了好几次 iptables 设置,但都没有成功。有没有 iptables 专家可以帮我设置?
eth0 Link encap:Ethernet HWaddr c8:60:00:85:22:be
inet addr:10.0.152.86 Bcast:10.0.152.255 Mask:255.255.255.0
inet6 addr: fe80::ca60:ff:fe85:22be/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:399596 errors:0 dropped:0 overruns:0 frame:0
TX packets:416603 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:55610834 (55.6 MB) TX bytes:562660002 (562.6 MB)
eth1 Link encap:Ethernet HWaddr 68:05:ca:16:f6:72
inet addr:172.16.0.2 Bcast:172.16.0.255 Mask:255.255.255.0
inet6 addr: fe80::6a05:caff:fe16:f672/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:95 errors:0 dropped:0 overruns:0 frame:0
TX packets:55215 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8580 (8.5 KB) TX bytes:11943374 (11.9 MB)
Interrupt:16 Memory:febe0000-fec00000
eth1.101 Link encap:Ethernet HWaddr 68:05:ca:16:f6:72
inet addr:171.16.0.2 Bcast:171.16.0.255 Mask:255.255.255.0
inet6 addr: fe80::6a05:caff:fe16:f672/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:47 errors:0 dropped:0 overruns:0 frame:0
TX packets:145 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3222 (3.2 KB) TX bytes:24388 (24.3 KB)
eth1.102 Link encap:Ethernet HWaddr 68:05:ca:16:f6:72
inet addr:171.16.0.2 Bcast:171.16.0.255 Mask:255.255.255.0
inet6 addr: fe80::6a05:caff:fe16:f672/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:48 errors:0 dropped:0 overruns:0 frame:0
TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3268 (3.2 KB) TX bytes:11718 (11.7 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:59 errors:0 dropped:0 overruns:0 frame:0
TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5010 (5.0 KB) TX bytes:5010 (5.0 KB)
user@machine ~ $ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.152.1 0.0.0.0 UG 0 0 0 eth0
10.0.152.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
171.16.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1.101
171.16.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1.102
172.16.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1