我有一个 Ubuntu 10.04 LTS 服务器,它有两个以太网端口eth0和eth1.
eth0通过网络 192.168.3.0/24 连接到 ISP1,服务器静态地址为 192.168.3。5
eth1通过网络 192.168.5.0/24 连接到 ISP2,服务器静态地址为 192.168.5.10
连接后eth1,没有互联网连接eth0。内部网络可以访问,例如从192.168.3.0/24网络中的其他计算机可以ssh、ping。
当eth1禁用或断开连接时,eth0工作正常。
如何确保两个以太网端口都能连接到互联网?
netstat 配置 eth1 已禁用
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.3.1 0.0.0.0 UG 0 0 0 eth0
Run Code Online (Sandbox Code Playgroud)
Netstat 配置 eth1 已启用
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.5.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
0.0.0.0 192.168.5.254 0.0.0.0 UG 0 0 0 eth1
0.0.0.0 192.168.3.1 0.0.0.0 UG 0 0 0 eth0
Run Code Online (Sandbox Code Playgroud)
编辑
我还检查了/etc/resolv.conf
在那里,我手动添加了两个网关的名称服务器。
IP地址显示
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 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 UNKNOWN qlen 1000
link/ether 11:bb:3e:15:3e:0e brd ff:ff:ff:ff:ff:ff
inet 192.168.3.100/24 brd 192.168.3.255 scope global eth0
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 100
link/ether aa:2a:ae:5f:59:e8 brd ff:ff:ff:ff:ff:ff
inet 192.168.5.100/24 brd 192.168.5.255 scope global eth1
valid_lft forever preferred_lft forever
Run Code Online (Sandbox Code Playgroud)
我根据从此处获取的基本实现(拆分访问)制作了一个可能的运行示例。
创建两个额外的路由表,例如 T1 和 T2。
ip route add 192.168.3.0/24 dev eth0 src 192.168.3.5 table T1
ip route add default via 192.168.3.0/24 table T1
ip route add 192.168.5.0/24 dev eth1 src 192.168.5.10 table T2
ip route add default via 192.168.5.0/24 table T2
Run Code Online (Sandbox Code Playgroud)
设置主路由表:
ip route add 192.168.3.0/24 dev eth0 src 192.168.3.5
ip route add 192.168.5.0/24 dev eth1 src 192.168.5.10
Run Code Online (Sandbox Code Playgroud)
添加您对默认路线的偏好:
ip route add default via 192.168.3.5
Run Code Online (Sandbox Code Playgroud)
设置路由规则,选择使用哪个路由表进行路由。
ip rule add from 192.168.3.5 table T1
ip rule add from 192.168.5.10 table T2
Run Code Online (Sandbox Code Playgroud)
更多信息请点击这里。