无法在第二个以太网端口上设置第二个网络接口 Debian 3.16

无法在第二个以太网端口上设置第二个网络接口 Debian 3.16

我的目标是在两个不同的端口上设置两个以太网接口,并在同一个网络上使用两个不同的静态 IP。问题是,一个端口将可以通过两个 IP 访问,而另一个则不能。我继续使用 /etc/network/interfaces 文件和 /etc/init.d/networking restart 调用。我还尝试使用 ifupdown 调用。以下是我进行的操作:

我刚刚安装了 Debian 3.16 操作系统,没有任何网络配置。我的设备有两个以太网端口。

ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:30:18:cd:49:77 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:30:18:cd:49:76 brd ff:ff:ff:ff:ff:ff
4: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether bc:30:7e:c0:e6:ba brd ff:ff:ff:ff:ff:ff

ifconfig
lo        Link encap:Boucle locale  
          inet adr:127.0.0.1  Masque:255.0.0.0
          adr inet6: ::1/128 Scope:Hôte
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:31 errors:0 dropped:0 overruns:0 frame:0
          TX packets:31 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:0 
          RX bytes:3172 (3.0 KiB)  TX bytes:3172 (3.0 KiB)

cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

一切似乎都很好。我想添加一个新的以太网接口来连接我的网络,所以我按如下方式修改 /etc/network/interfaces 文件:

cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.160
netmask 255.255.255.0
gateway 192.168.1.1

现在我的设备可以通过以太网端口 A 访问,IP 为 192.168.1.160,ifconfig 也可以。然后我添加新接口并按如下方式修改 /etc/network/interfaces:

cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.160
netmask 255.255.255.0
gateway 192.168.1.1

auto eth1
iface eth1 inet static
address 192.168.1.161
netmask 255.255.255.0
gateway 192.168.1.1


ifconfig
eth0      Link encap:Ethernet  HWaddr 00:30:18:cd:49:77  
          inet adr:192.168.1.160  Bcast:192.168.1.255  Masque:255.255.255.0
          adr inet6: fe80::230:18ff:fecd:4977/64 Scope:Lien
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6550 errors:0 dropped:8 overruns:0 frame:0
          TX packets:819 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:1000 
          RX bytes:584489 (570.7 KiB)  TX bytes:106896 (104.3 KiB)
          Interruption:18 Mémoire:d0700000-d0720000 

eth1      Link encap:Ethernet  HWaddr 00:30:18:cd:49:76  
          inet adr:192.168.1.161  Bcast:192.168.1.255  Masque:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:222 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:1000 
          RX bytes:20241 (19.7 KiB)  TX bytes:1500 (1.4 KiB)
          Interruption:19 Mémoire:d0600000-d0620000 

lo        Link encap:Boucle locale  
          inet adr:127.0.0.1  Masque:255.0.0.0
          adr inet6: ::1/128 Scope:Hôte
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:31 errors:0 dropped:0 overruns:0 frame:0
          TX packets:31 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 lg file transmission:0 
          RX bytes:3172 (3.0 KiB)  TX bytes:3172 (3.0 KiB)

我期望通过 .160 访问端口 A 上的设备,通过 .161 访问端口 B 上的设备。但实际上,我通过 .160 和 .161 都访问了端口 A 上的设备,而通过端口 B 上却访问不到任何设备。

编辑: 如果我将以太网电缆插入物理端口 A,我希望能够连接(ping 或 ssh 连接)IP 为 192.168.1.160 的设备。如果我将以太网电缆插入物理端口 B,我希望能够连接(ping 或 ssh 连接)IP 为 192.168.1.161 的设备。(网络为 192.168.1.0/24)

我的问题是:

  • 我做错了什么?这些文件和调用的目的是协同工作还是它们在网络管理上不兼容?
  • 如果不是这些,那么在 Debian 3.16 上配置网络接口通常使用哪些工具?
  • 我是否错过了网络接口和硬件之间的联系?

当然:

  1. 我花了很多时间寻找一些答案,并利用这些答案以及 Debian 的网络配置构建我的方法文档
  2. 我尝试使用 /etc/init.d/networking restart 和 ifup/ifdown eth0 重新启动网络接口
  3. 最后,我重新安装了我的 Debian,因此我也尝试重新启动。

答案1

在你的问题中术语不清楚,你的意思是什么
“我希望通过 .160 访问端口 A 上的设备,通过 .161 访问端口 B 上的设备。但实际上,我通过 .160 和 .161 都访问了端口 A 上的设备,而通过端口 B 上却什么都访问不到。”
如果这清楚了,那么我们就可以告诉您具体如何进行。

请查看 Linux 中的基于策略的路由。以下内容可能对您有帮助: https://www.novell.com/support/kb/doc.php?id=7008874
http://blog.scottlowe.org/2013/05/29/a-quick-introduction-to-linux-policy-routing/

正如您所说,您已尝试仅在活动接口上使用单个网关,因此应该可行。这里的问题在于网络,两个接口都存在相同的问题。可以尝试以下示例:

ifconfig eth0 192.168.1.161/24 up  
route add default gw 192.168.1.1 dev eth0  
ifconfig eth1 192.168.1.162/24  up  

并使用 ifconfig 逐个关闭 eth0 和 eth1 进行测试,
也可以在两个接口上插入 LAN,然后尝试使用 ping 或 ssh。

答案2

基本上,我怀疑这与路由有关。除非您与提到的两个 IP 位于同一个 LAN 段(即广播域),否则您的流量需要路由。

简而言之,您已将两个端口设置为具有默认网关。您可以这样做(但据我所知,需要您为其中一个 NIC 指定成本),但这仍然很可能会导致同样的事情发生

在您的配置中,eth0 是第一个配置的。我怀疑这意味着它宣布它有一个默认网关,这反过来意味着 eth1 的网关被忽略了。您可以使用 来检查这一点ip r

更一般地说,在路由网络中(同样,如果您在同一个广播域中,则是另一回事,因为您使用的是物理地址/MAC,而不是网络地址/IP),总是有一条首选路径,而您的流量只是使用该首选路径。

实际上,您所看到的只是您的 eth0 提供对 eth0 和 eth1 的 IP 地址的访问,因为它知道到这两个 IP 的路由,以及返回您 IP 的路由。

因此这里没有什么问题 — — 至少我看不出来。

如果您出于可用性原因而执行所有这些操作,那么您可以考虑绑定您的 NIC,并拥有单个 IP,因为该设置的变量较少。

相关内容