设置

设置

这个问题与我在 ServerFault 和其他地方寻求答案时咨询过的许多其他问题类似,但我陷入了困境,因为据我所知,我已经正确设置了它,但我并没有高兴地让它工作。

我已经使用 VirtualBox 中的多台机器建立了一个模拟环境,一台代表服务器(用作路由器),另一台模拟两个 ADSL 调制解调器(只是充当 NAT 路由器,在 LAN 端有两个端口,在 WAN 端有一个端口连接到互联网)。

服务器(SRV)将两个端口(ETH2 和 ETH3)连接到两个独立的 Vbox 虚拟网络,通过 ADSL 机器(分别连接到其 ETH2/3 端口)。

                  +----------+
                  |   SRV    |
                  +----------+
 ETH2 (192.168.1.10) |     | ETH3 (192.168.2.11)
                     |     |
                     |     |
  ETH2 (192.168.1.1) |     | ETH3 (192.168.2.1)
                  +----------+
                  |   ADSL   |
                  +----------+

ADSL端口为ETH2(192.168.1.1)和ETH3(192.168.2.1)。

SRV 端口是 ETH2(192.168.1.10)和 ETH3(192.168.2.11)。

SRViptables没有做任何有趣的事情,除了看到下面关于main测试期间对默认路由进行调整的评论。


设置

ip route show

default via 192.168.1.1 dev eth2
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
192.168.1.0/24 dev eth2 proto kernel scope link src 192.168.1.10
192.168.2.0/24 dev eth3 proto kernel scope link src 192.168.2.11
192.168.10.0/24 dev eth1 proto kernel scope link src 192.168.10.1
192.168.13.0/24 dev admin.tinc proto kernel scope link src 192.168.13.1

设置两张桌子adsl1ads2

ip route show table adsl1

default via 192.168.1.1 dev eth2
192.168.1.0/24 dev eth2 scope link src 192.168.1.10

ip route show table adsl2

default via 192.168.2.1 dev eth3
192.168.2.0/24 dev eth3 scope link src 192.168.2.11

ip rule

0:      from all lookup local
32762:  from all to 192.168.1.0/24 lookup adsl1
32763:  from all to 192.168.2.0/24 lookup adsl2
32764:  from 192.168.2.0/24 lookup adsl2
32765:  from 192.168.1.0/24 lookup adsl1
32766:  from all lookup main
32767:  from all lookup default

演示问题

如果我通过 ETH2 进行 ping 操作,则没有问题。

ping -I eth2 -c 1 google.com

PING google.com (216.58.214.14) from 192.168.1.10 eth2: 56(84) bytes of 
data.
64 bytes from lhr26s05-in-f14.1e100.net (216.58.214.14): icmp_seq=1 ttl=61 
time=20.2 ms

--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 20.288/20.288/20.288/0.000 ms

如果我通过 ETH3 进行 ping 操作,ETH3 上根本没有流量。

PING google.com (216.58.213.110) from 192.168.2.11 eth3: 56(84) bytes of 
data.

--- google.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

如果我更改main表默认网关......

ip route replace default via 192.168.2.1 dev eth3

相反的情况发生(ETH3 工作,ETH2 失败)。在我看来,这表明路由表adsl1和路由adsl2表是错误的,或者根本没有被参考(规则是错误的)。但我不知道为什么?


更新 1

sysctl -w net.ipv4.conf.all.rp_filter=0

sysctl -w net.ipv4.conf.eth2.rp_filter=0

sysctl -w net.ipv4.conf.eth2.rp_filter=0

重复ping -I eth3 google.com...

tcpdump -i eth3

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth3, link-type EN10MB (Ethernet), capture size 262144 bytes
20:26:32.207178 ARP, Request who-has lhr35s11-in-f14.1e100.net tell 192.168.2.11, length 28
20:26:33.221587 ARP, Request who-has lhr35s11-in-f14.1e100.net tell 192.168.2.11, length 28

更新 1 的附加信息

当 ETH3 被设置为默认路由时main(没有其他变化),情况tcpdump如下:

tcpdump: listening on eth3, link-type EN10MB (Ethernet), capture size 262144 bytes
21:41:51.865488 IP (tos 0x0, ttl 64, id 31173, offset 0, flags [DF], proto ICMP (1), length 84)
    192.168.2.11 > google-public-dns-a.google.com: ICMP echo request, id 2962, seq 1, length 64
21:41:51.866542 IP (tos 0x0, ttl 64, id 18679, offset 0, flags [DF], proto UDP (17), length 71)
    192.168.2.11.36067 > one.one.one.one.domain: [bad udp cksum 0xc4f9 -> 0xb220!] 31965+ PTR? 11.2.168.192.in-addr.arpa. (43)
21:41:51.885947 IP (tos 0x0, ttl 61, id 4776, offset 0, flags [DF], proto ICMP (1), length 84)
    google-public-dns-a.google.com > 192.168.2.11: ICMP echo reply, id 2962, seq 1, length 64

附加信息

ip route get 8.8.8.8 oif eth3

8.8.8.8 dev eth3 src 192.168.2.11
    cache  users 1

ARP因此,肯定是路由出现了问题(而不是其他地方出现了问题)。这也解释了!的奇异存在。

好的!

我似乎认为当流量被导向接口 ETH3 时,它并没有192.168.2.11像我预期的那样被分配一个“发件人”地址,至少在路由策略数据库决策时没有及时分配。

我手动添加了一个简单的规则:

ip rule add to 8.8.8.8 lookup adsl2

然后

ip route get 8.8.8.8 oif eth3

8.8.8.8 via 192.168.2.1 dev eth3 table adsl2 src 192.168.2.11
    cache

显然表adsl2正在被使用并且正确设置via 192.168.2.1。好极了!

如果我把这条规则替换成更具体的规则

ip rule add to 8.8.8.8 from 192.168.2.11 lookup adsl2

我明白了

ip route get 8.8.8.8 oif eth3

8.8.8.8 dev eth3 src 192.168.2.11
    cache

回到via未设置的状态,结论:adsl2表未被使用。进一步的结论:from无效,因此接口eth3未设置源地址,192.168.2.11尽管ip a显示

5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:e5:7e:eb brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.11/24 brd 192.168.2.255 scope global eth3
    valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fee5:7eeb/64 scope link
       valid_lft forever preferred_lft forever

我哪里搞砸了?

相关内容