同一子网上的多个 NIC

同一子网上的多个 NIC

尽管有几篇文章讨论这个问题,但我需要一些建议,因为我仍然面临这个问题。

我在虚拟机上有 3 个接口(6.6 分)

[root@localhost network-scripts]# ip addr list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN_                                                                                                                                                                                                                                                   
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host_
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:bf:6e:7b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.140/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::20c:29ff:febf:6e7b/64 scope link_
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:bf:6e:85 brd ff:ff:ff:ff:ff:ff
    inet 172.16.64.7/24 brd 172.16.64.255 scope global eth1
    inet6 fe80::20c:29ff:febf:6e85/64 scope link_
       valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:bf:6e:8f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.151/24 brd 192.168.1.255 scope global eth2
    inet6 fe80::20c:29ff:febf:6e8f/64 scope link_
       valid_lft forever preferred_lft forever

eth1 用于管理线路。我想将 192.168.1.140 和 192.168.1.150 分别分配给 eth0 和 eth2。由于 eth0 和 eth2 都属于同一个子网,因此我配置了基于策略的路由。

[root@localhost /]# cat /etc/sysconfig/network-scripts/route-eth0
192.168.1.0/24 dev eth0 src 192.168.1.140 table eth0
default via 192.168.1.1 dev eth0 table eth0                                                                                                                                                                                                                                                                            


[root@localhost /]# cat /etc/sysconfig/network-scripts/route-eth2
192.168.1.0/24 dev eth2 src 192.168.1.151 table eth2
default via 192.168.1.1 dev eth2 table eth2


[root@localhost /]# cat /etc/sysconfig/network-scripts/rule-eth0
from 192.168.1.140 table eth0 priority 1000


[root@localhost /]# cat /etc/sysconfig/network-scripts/rule-eth2
from 192.168.1.151 table eth2 priority 1001

然后我在 /etc/sysctl.conf 中设置以下参数

net.ipv4.conf.all.arp_filter = 1
net.ipv4.conf.default.rp_filter = 0

重新启动虚拟机以使内核参数和网络配置的更改生效。路由表中的结果如下。

[root@localhost /]# ip rule show
0:      from all lookup local
1000:   from 192.168.1.140 lookup eth0
1001:   from 192.168.1.151 lookup eth2
32766:  from all lookup main
32767:  from all lookup default

[root@localhost /]# ip route show table eth0                                                                                                                                                                                                                                                                           
192.168.1.0/24 dev eth0  scope link  src 192.168.1.140
default via 192.168.1.1 dev eth0

[root@localhost /]# ip route show table eth2
192.168.1.0/24 dev eth2  scope link  src 192.168.1.151
default via 192.168.1.1 dev eth2

配置看上去不错,但是不知为何却无法 ping 通互联网。

[root@localhost /]# ping -c 1 -I eth0 8.8.8.8_
PING 8.8.8.8 (8.8.8.8) from 192.168.1.140 eth0: 56(84) bytes of data.
From 192.168.1.140 icmp_seq=1 Destination Host Unreachable

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 3001ms

[root@localhost /]# ping -c 1 -I eth2 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.1.151 eth2: 56(84) bytes of data.
From 192.168.1.151 icmp_seq=1 Destination Host Unreachable

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 3003ms

有任何想法吗?

相关内容