我正在尝试将第二个 ISP 连接连接到我的服务器以供我们的 SIP 电话使用。
eth0
已开启默认 25Mb 服务192.168.1.x,我已经配置了
eth1
新的 6Mb 服务10.10.1.x
两个路由器都配置了 pppoe 和唯一的静态 IP,我有单独的交换机,以及一个带有两个以太网端口的 Ubuntu 14Lts 服务器。单独连接任何一个都可以正常工作,但同时连接两个路由器时,我只能ping -I eth[0|1] 8.8.8.8 -c 3
在一个接口上 ping 通每个路由器,但都没有问题。
如果有人可以帮助我启动并运行 Nic 并默认主要流量通过eth0
以及仅 Asterisk/Sip 流量通过,eth1
那将节省我的时间。
一些信息输出:
# cat /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.100
gateway 192.168.1.1
netmask 255.255.255.0
auto eth1
iface eth1 inet static
address 10.10.1.101
#gateway 10.10.1.1
netmask 255.255.255.0
$ sudo route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default home.Home 0.0.0.0 UG 0 0 0 eth1
10.10.1.0 * 255.255.255.0 U 1 0 0 eth1
link-local * 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
$ sudo ifdown eth0 && sudo ifup eth0
RTNETLINK answers: No such process
RTNETLINK answers: File exists
Failed to bring up eth0.
$ sudo ifdown eth1 && sudo ifup eth1
ifdown: interface eth1 not configured
RTNETLINK answers: File exists
Failed to bring up eth1.
$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:25:90:11:c8:44
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::225:90ff:fe11:c844/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2316517 errors:0 dropped:0 overruns:0 frame:0
TX packets:3877952 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1881181270 (1.8 GB) TX bytes:5573716194 (5.5 GB)
Interrupt:16 Memory:faee0000-faf00000
eth1 Link encap:Ethernet HWaddr 00:25:90:11:c8:45
inet addr:10.10.1.101 Bcast:10.10.1.255 Mask:255.255.255.0
inet6 addr: fe80::225:90ff:fe11:c845/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:214622 errors:0 dropped:0 overruns:0 frame:0
TX packets:9763 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13988405 (13.9 MB) TX bytes:890576 (890.5 KB)
Interrupt:16 Memory:fafe0000-fb000000
======================编辑1:===========================
感谢 Peter Zhabin 提供的 iproute2 说明
apt-get install iproute2
echo "1 link2" >> /etc/iproute2/rt_tables
ip route add 10.10.1.0/24 dev eth1 src 10.10.1.101 table link2
ip route add default via 10.10.1.1 dev eth1 table link2
ip rule add from 10.10.1.101/32 table link2
ip rule add to 10.10.1.101/32 table link2
第一次尝试时有点奇怪,sudo echo "1 link2" >> /etc/iproute2/rt_tables
它响应-bash:/etc/iproute2/rt_tables:权限被拒绝,但我切换到Root以避免需要sudo,并且没有进一步的抱怨。
======================编辑2:===========================
# ping -I 10.10.1.101 8.8.8.8 -c 3
PING 8.8.8.8 (8.8.8.8) from 10.10.1.101 : 56(84) bytes of data.
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2014ms
======================编辑3:===========================
# ip rule show
0: from all lookup local
32764: from all to 10.10.1.101 lookup link2
32765: from 10.10.1.101 lookup link2
32766: from all lookup main
32767: from all lookup default
# ip route show
default via 192.168.1.1 dev eth0
10.10.1.0/24 dev eth1 proto kernel scope link src 10.10.1.101
169.254.0.0/16 dev eth1 scope link metric 1000
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
# ip route show table link2
default via 10.10.1.1 dev eth1
10.10.1.0/24 dev eth1 scope link src 10.10.1.101
显示 link2 表有点奇怪,有点不尽如人意。我不明白为什么它并不总是打印出来。好消息是通过 IP 进行 Ping 操作,尽管 eth1 不行。为了完成,我还包含了完整的 show tables
# ip route show table all
default via 10.10.1.1 dev eth1 table link2
10.10.1.0/24 dev eth1 table link2 scope link src 10.10.1.101
default via 192.168.1.1 dev eth0
10.10.1.0/24 dev eth1 proto kernel scope link src 10.10.1.101
169.254.0.0/16 dev eth1 scope link metric 1000
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
broadcast 10.10.1.0 dev eth1 table local proto kernel scope link src 10.10.1.101
local 10.10.1.101 dev eth1 table local proto kernel scope host src 10.10.1.101
broadcast 10.10.1.255 dev eth1 table local proto kernel scope link src 10.10.1.101
broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1
broadcast 192.168.1.0 dev eth0 table local proto kernel scope link src 192.168.1.100
local 192.168.1.100 dev eth0 table local proto kernel scope host src 192.168.1.100
broadcast 192.168.1.255 dev eth0 table local proto kernel scope link src 192.168.1.100
broadcast 192.168.122.0 dev virbr0 table local proto kernel scope link src 192.168.122.1
local 192.168.122.1 dev virbr0 table local proto kernel scope host src 192.168.122.1
broadcast 192.168.122.255 dev virbr0 table local proto kernel scope link src 192.168.122.1
fe80::/64 dev eth0 proto kernel metric 256
fe80::/64 dev eth1 proto kernel metric 256
unreachable default dev lo table unspec proto kernel metric 4294967295 error -101
local ::1 dev lo table local proto none metric 0
local fe80::225:90ff:fe11:c844 dev lo table local proto none metric 0
local fe80::225:90ff:fe11:c845 dev lo table local proto none metric 0
ff00::/8 dev eth0 table local metric 256
ff00::/8 dev eth1 table local metric 256
unreachable default dev lo table unspec proto kernel metric 4294967295 error -101
# ping -I eth1 8.8.8.8 -c 3
PING 8.8.8.8 (8.8.8.8) from 10.10.1.101 eth1: 56(84) bytes of data.
From 10.10.1.101 icmp_seq=1 Destination Host Unreachable
From 10.10.1.101 icmp_seq=2 Destination Host Unreachable
From 10.10.1.101 icmp_seq=3 Destination Host Unreachable
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2015ms
pipe 3
# ping -I 10.10.1.101 8.8.8.8 -c 3
PING 8.8.8.8 (8.8.8.8) from 10.10.1.101 : 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=60 time=29.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=60 time=29.3 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=60 time=28.8 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 28.804/29.192/29.433/0.310 ms
答案1
首先,您必须正确设置通过这些网关传入的数据包的返回路径。这意味着如果有数据包通过 eth1 传入,响应也应通过 eth1 传出,而不是通过默认路由。
为了使其工作,您需要 iproute2,这将允许您拥有多个路由表和多个网关。首先,您应该只拥有一在网络/接口下设置的网关地址,假设它是 192.168.1.100 网络,并且您希望来自 10.10.1.101 的流量通过 10.10.1.1 路由器通过 eth1 出去。
然后剩下的将会像这样(根据需要添加 sudo):
apt-get install iproute2
echo "1 link2" >> /etc/iproute2/rt_tables
ip route add 10.10.1.0/24 dev eth1 src 10.10.1.101 table link2
ip route add default via 10.10.1.1 dev eth1 table link2
ip rule add from 10.10.1.101/32 table link2
ip rule add to 10.10.1.101/32 table link2
这将使你的返回流量运行到正确的路由器,并且你还可以毫无问题地 ping -I 两个接口。以上确实创建了第二个路由表 (link2),为其设置了默认路由和范围,并添加了两个规则来处理入站和出站流量。
如果您的手机从外部连接到此服务器,那就足够了。如果它们在内部某处,请评论有关您的内部网络设置的更多详细信息。