我们在Ubuntu Xenial中的网络路由配置方面遇到了问题。
我们有许多服务器同时使用Debian 8.4(Jessie)和Ubuntu 16.04.2(xenial)
和
一模一样
网络设置(或至少在我们看来)。
它们都有两个NIC连接到两个VLAN(如“A”和“B”),都可以访问
尽管其他VLAN表示,例如,来自VLAN“C”。
二者都
/etc/network/interfaces
文件的格式如下:
注:
为了更好的可读性,我伪造了名字和IP。
# VLAN A
auto eth0
iface eth0 inet static
address 192.168.111.xxx
netmask 255.255.255.0
broadcast 192.168.111.255
network 192.168.111.0
gateway 192.168.111.254
dns-nameservers 192.168.111.25 192.168.111.26
# VLAN B
auto eth1
iface eth1 inet static
address 192.168.222.xxx
netmask 255.255.255.0
broadcast 192.168.222.255
network 192.168.222.0
gateway 192.168.222.254 # <-- (Commented out in Ubuntu machine)
dns-nameservers 192.168.111.25 192.168.111.26
...说
xxx
Debian机器是100,Ubuntu机器是200,我
正在尝试从VLAN“C”中的192.168.1.10 ping到以下地址:
-
192.168.111.100:工作正常。
-
192.168.222.100:很好用。
-
192.168.111.200:工作正常。
-
192.168.222.200:
没有回答!!
“B”vlan主要用于备份和其他“后台”通信
避免vlan“A”中的饱和问题。
我知道,使用两条网络路径访问同一台机器并不常见
设置,我必须说,只能连接其中一个
如今,其他网络不是什么大问题。但我最讨厌的是
为什么?
我可以访问Debian机器,而不能访问Ubuntu机器?
另一方面,如果它在两个平台上都运行良好,我们也可以
考虑从NIC关闭一些服务(如ssh和后端接口)
“A”以提高安全性(我们的防火墙只允许从
IT人员vlan)。
当然
如前所述
接口
一小条
网关
行在Ubuntu机器中被注释掉了,但那是因为,网络
否则,初始化将在该计算机中失败。事实上,这就是我们
正在尝试解决。
但是
两台机器的路由表几乎相同
. 唯一的区别
我可以看到
联机
Ubuntu计算机中的标志:
myUser@debianMachine:~$ sudo ip route
default via 192.168.111.254 dev eth0
192.168.111.0/24 dev eth0 proto kernel scope link src 192.168.111.100
192.168.222.0/24 dev eth1 proto kernel scope link src 192.168.222.100
myUser@ubuntuMachine:~$ sudo ip route
default via 192.168.111.254 dev eth0 onlink
192.168.111.0/24 dev eth0 proto kernel scope link src 192.168.111.200
192.168.222.0/24 dev eth1 proto kernel scope link src 192.168.222.200
...但我可以通过以下命令将其删除:
myUser@ubuntuMachine:~$ sudo ip route replace default via 192.168.111.254 dev eth0
myUser@ubuntuMachine:~$ sudo ip route
default via 192.168.111.254 dev eth0
192.168.111.0/24 dev eth0 proto kernel scope link src 192.168.111.200
192.168.222.0/24 dev eth1 proto kernel scope link src 192.168.222.200
而且它没有解决问题。
之后,我还尝试取消注释
网关
“VLAN B”行
说,在
/etc/网络/接口
文件并尝试
重新启动网络,但实际情况如下:
myUser@ubuntuMachine:~$ sudo /etc/init.d/networking restart
[....] Restarting networking (via systemctl): networking.serviceJob for networking.service failed because the control process exited with error code. See "systemctl status networking.service" and "journalctl -xe" for details.
failed!
...以及
联机
旗帜又回来了。
请注意,再次注释该行并发布新的
/etc/init.d/networking restart
命令,直到
计算机已重新启动(即使是联网,尽管有VLAN B默认网关
问题,继续正常工作)。
以下是建议命令的输出:
myUser@ubuntuMachine:~$ sudo systemctl status networking.service
â networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Drop-In: /run/systemd/generator/networking.service.d
ââ50-insserv.conf-$network.conf
Active: failed (Result: exit-code) since jue 2017-12-21 14:55:29 CET; 42s ago
Docs: man:interfaces(5)
Process: 8552 ExecStop=/sbin/ifdown -a --read-environment --exclude=lo (code=exited, status=0/SUCCESS)
Process: 8940 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
Process: 8934 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-envi
Main PID: 8940 (code=exited, status=1/FAILURE)
dic 21 14:55:29 ubuntuMachine systemd[1]: Stopped Raise network interfaces.
dic 21 14:55:29 ubuntuMachine systemd[1]: Starting Raise network interfaces...
dic 21 14:55:29 ubuntuMachine ifup[8940]: RTNETLINK answers: File exists
dic 21 14:55:29 ubuntuMachine ifup[8940]: Failed to bring up eth1.
dic 21 14:55:29 ubuntuMachine systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILUR
dic 21 14:55:29 ubuntuMachine systemd[1]: Failed to start Raise network interfaces.
dic 21 14:55:29 ubuntuMachine systemd[1]: networking.service: Unit entered failed state.
dic 21 14:55:29 ubuntuMachine systemd[1]: networking.service: Failed with result 'exit-code'.
...以及
sudo journalctl -xe
:
dic 21 14:55:29 ubuntuMachine sudo[8922]: myUser : TTY=pts/0 ; PWD=/home/myUser ; USER=root ; COMMAND=/etc/init.d/networking restart
dic 21 14:55:29 ubuntuMachine sudo[8922]: pam_unix(sudo:session): session opened for user root by myUser(uid=0)
dic 21 14:55:29 ubuntuMachine systemd[1]: Stopped Raise network interfaces.
-- Subject: Unit networking.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit networking.service has finished shutting down.
dic 21 14:55:29 ubuntuMachine systemd[1]: Starting Raise network interfaces...
-- Subject: Unit networking.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit networking.service has begun starting up.
dic 21 14:55:29 ubuntuMachine ifup[8940]: RTNETLINK answers: File exists
dic 21 14:55:29 ubuntuMachine ifup[8940]: Failed to bring up eth1.
dic 21 14:55:29 ubuntuMachine systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
dic 21 14:55:29 ubuntuMachine systemd[1]: Failed to start Raise network interfaces.
-- Subject: Unit networking.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit networking.service has failed.
--
-- The result is failed.
dic 21 14:55:29 ubuntuMachine systemd[1]: networking.service: Unit entered failed state.
dic 21 14:55:29 ubuntuMachine systemd[1]: networking.service: Failed with result 'exit-code'.
dic 21 14:55:29 ubuntuMachine sudo[8922]: pam_unix(sudo:session): session closed for user root
我在google上搜索了很多相关信息,但都没有找到
完全回答我的问题:
-
一
explanation of "onlink" flag
在我看来,它似乎指向
排除了“onlink”标志负责
“反向布线错误”,意思是
«告诉内核
不必检查网关是否可以通过
当前计算机
所以(我发现)内核可能认为它可以(或者
应)将接入连接的答案从VLAN C路由到
默认网关而非思想
相同的NIC
连接已启动
.
-
但是
正如我所说
,删除“onlink”标志似乎没有改变
任何东西
-
这
unix StackExchange answer
似乎解决了问题(我没有
通过使用多个路由表和规则(告诉
使用哪个表)。但是
这不能解释
为什么选择Debian
机器运转良好(我检查过
/etc/iproute2/rt\U表格
文件,共
机器和
它们是相同的
也是:
myUser@bothMachines:~$ sudo cat /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
所以我的最后一个假设是,这可能只是实现上的差异
在内核版本和ubuntu版本之间
可以是
正确的行为
所以,在现代内核中,我需要使用两个
不同的路由表(但我不确定,也不知道为什么…)。
myUser@debianMachine:~$ sudo uname -a
Linux debianMachine 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) x86_64 GNU/Linux
myUser@ubuntuMachine:~$ sudo uname -a
Linux ubuntuMachine 4.4.0-87-generic #110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
因此,问题是:
我们是不是在Ubuntu机器上做错了什么(或者有一些bug)?或者,相反,这是正确的行为,我们被迫设置更复杂的路由模式(通过每个vlan路由或通过使用两个路由表使两个默认网关重新工作)?
编辑:
现在,我尝试添加静态路由来解决问题:
myUser@ubuntuMachine:~$ sudo ip route add 192.168.1.0/24 via 192.168.222.254 dev eth1
...但这冻结了我的ssh连接(以为NIC A),甚至我可以连接以为NIC B(192.168.111.200)
这两条规则似乎不可能同时执行:
myUser@ubuntuMachine:~$ sudo ip route add 192.168.1/24 via 102.168.111.254 dev eth0
myUser@ubuntuMachine:~$ sudo ip route add 192.168.1/24 via 192.168.222.254 dev eth1
RTNETLINK answers: File exists
编辑2:
我终于找到了
Linux Advanced Routing & Traffic Control HOWTO
这似乎比我在其
Chapter 4. Rules - routing policy database
我看到以下文字:
如果要使用此功能,请确保您的内核
使用“IP:高级路由器”和“IP:策略路由”编译
特征
...因此,我认为所有这些都指向我之前关于内核实现差异的假设是正确的,而这种差异具体地说就是正在编译的这两个特性。