Networking Can';t通过第二个NIC建立连接(两个跃点)

Networking Can';t通过第二个NIC建立连接(两个跃点),networking,routing,ip,ubuntu-server,iproute,Networking,Routing,Ip,Ubuntu Server,Iproute,我们在Ubuntu Xenial中的网络路由配置方面遇到了问题 我们有许多服务器同时使用Debian8.4(Jessie)和Ubuntu 16.04.2(xenial) 以及完全相同的网络设置(或者至少在我们看来) 它们都有两个NIC连接到两个VLAN(如“A”和“B”),这两个VLAN都是可访问的 尽管其他VLAN表示,例如,来自VLAN“C” 两个/etc/network/interfaces文件的格式如下: 注意:为了更好的可读性,我伪造了姓名和IP地址 …但我可以通过以下命令将其删除:

我们在Ubuntu Xenial中的网络路由配置方面遇到了问题

我们有许多服务器同时使用Debian8.4(Jessie)和Ubuntu 16.04.2(xenial) 以及完全相同的网络设置(或者至少在我们看来)

它们都有两个NIC连接到两个VLAN(如“A”和“B”),这两个VLAN都是可访问的 尽管其他VLAN表示,例如,来自VLAN“C”

两个
/etc/network/interfaces
文件的格式如下:

注意:为了更好的可读性,我伪造了姓名和IP地址

…但我可以通过以下命令将其删除:

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/network/interfaces文件中被注释掉,并尝试 重新启动网络,但实际情况如下:

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!
…然后,onlink标志再次出现

请注意,再次注释该行并发布新的
/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
我在谷歌上搜索了很多相关信息,但没有找到 充分回答我的问题:

  • 在我看来,这是一个指向 排除了“onlink”标志可能导致 “错误的反向路由”,意思是«告诉内核 不必检查网关是否可由 当前机器»所以(我发现)内核可能认为它可以(或者 应)将输入连接的答案从VLAN C路由到 默认网关,而不是来自 连接已启动

    • 但是,正如我所说的,删除“onlink”标志似乎没有改变 什么都行
  • 这似乎解决了问题(我没有 通过使用多个路由表和规则(告诉 内核(使用哪个表)。但是它不能解释为什么Debian 机器运转良好(我检查了文件的/etc/iproute2/rt_表 两台机器和它们也是相同的

所以我的最后一个假设是,这可能只是实现上的差异 在内核版本和ubuntu版本之间,有了ubuntu版本是最近的事了 可能是正确的行为因此,在现代内核中,我需要使用两个 不同的路由表(但我不确定,也不知道为什么…)

因此,问题是:

我们是不是在Ubuntu机器上做错了什么(或者有一些错误)?或者,相反,这是正确的行为,我们被迫设置更复杂的路由模式(通过每个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:

我终于找到了,它似乎比我找到的所有其他文档都更准确,特别是在其我看到的以下文本中:

如果您想使用此功能,请确保您的内核 用“IP:高级路由器”和“IP:策略路由”编译 特征


…因此,我认为我之前关于内核实现差异的假设是正确的,而这一差异具体地说就是正在编译的这两个特性。

不是权威性的答案,而是我的第一次工作尝试(应用我所理解的):

更新:
from
dev
不需要
ip-route
命令中的参数(如果没有这些参数,它工作得很好)

…在执行第一个命令后,我还无法连接,但在发出第二个命令后,是的

我在以下文本中找到了这一逻辑:

Linux-2.x可以将路由打包到多个路由表中,这些路由表由1到255之间的数字或文件/etc/iproute2/rt_表中的名称标识。默认情况下,所有正常路由都插入主表(ID 254),内核在计算路由时仅使用此表

实际上,另一个表始终存在,它是不可见的,但更重要。它是本地表(ID 255)。此表由本地和广播地址的路由组成。内核自动维护此表,管理员通常不需要修改或查看它

事实上,我最终使用了另一个路由表,由它的id(253)标识,而不是我现在理解的它只是一个别名(在/etc/iproute2/rt_tables文件中定义)

…再次检查该文件,我现在看到已经为该路由表定义了一个别名(“默认值”)(在“主”别名旁边,正如我之前粘贴的文本片段所说,它实际上是254

我还不知道这个命名背后的逻辑是什么(我指的是253路由表的“默认值”),以及出于任何原因,是否最好像(问题中已经提到)那样使用较低的路由表(1、2、3…)

但是,为了简单起见,如果我们不打算构建复杂的路由策略,只想解决这个连接问题,我想使用类似(尚未测试)的东西可能是一个很好的解决方案:

我仍然需要测试并检查是否需要通过网关行中的192.168.222.254添加一个
,或者它是否根本不起作用,需要使用另一个post up命令来添加它myUser@bothMachines:~$ sudo cat /etc/iproute2/rt_tables
#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
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
myUser@ubuntuMachine:~$ sudo ip route add 192.168.1.0/24 via 192.168.222.254 dev eth1
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
sudo ip route add 192.168.1.0/24 via 192.168.222.254 from 192.168.222.200 dev eth1 table 253 
sudo ip rule add from 192.168.222.200 table 253
gateway 192.168.222.254 table 253
post-up ip rule add from 192.168.222.200 table 253
sudo ip route add default from 192.168.222.200 via 192.168.222.254 table 253
sudo ip rule add from 192.168.222.200 table 253
gateway 192.168.222.254 table 1
post-up ip rule add from 192.169.222.200 table 1
pre-down ip rule del from 192.168.222.200 table 1
post-up ip route add 192.188.222.0/24 dev eth1 src 192.168.222.200 table 1
0:      from all lookup local 
32765:  from 192.168.222.200 lookup 1 
32766:  from all lookup main 
32767:  from all lookup default