我的目标是在两个不同的端口上设置两个以太网接口,并在同一个networking上使用两个不同的静态IP。 问题是一个端口可以被两个IP访问,另一个不会。 我继续进行/ etc / network / interfaces文件和/etc/init.d/networking重新启动调用。 我也试着用ifupdown调用。 这是我如何继续:
我刚刚安装了我的Debian 3.16操作系统,没有任何networkingconfiguration。我的设备有两个以太网端口。
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
一切似乎都很好。 我想添加一个新的以太网接口在我的networking上连接,所以我修改/ 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
我的设备现在可以在以太网端口上通过,假设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和端口B用.161到达我的设备。 但是实际上,我使用.160和.161两个端口到达端口A,而在端口B上则没有。
编辑:如果我插入以太网电缆的物理端口A,我想能够join(ping或SSH连接)我的设备IP为192.168.1.160。 如果我将以太网电缆插在物理端口B上,我希望能够join(ping或者ssh连接)我的设备IP 192.168.1.161。 (networking是192.168.1.0/24)
我的问题是:
当然:
在你的问题条件不明确,你的意思是
“我希望使用.160到达端口A的设备,使用.161的端口到达我的设备。但实际上,我使用.160和.161两个端口到达了端口A的设备,
如果这可能会清楚,我们可以为您提供如何进行。
请在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/
正如你所说的,你已经尝试过使用单个网关在主动界面上,所以应该工作。 这里的问题是networking,这两个接口是相同的。 可以试试这个例子:
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逐个testingeth0和eth1
也可以在两个接口上插入lan,并尝试使用ping或ssh。
基本上,我怀疑这是关于路由。 除非您与您提到的两个IP位于同一LAN段(即广播域),否则您的stream量需要路由。
简短的版本是你已经设置了两个端口有一个默认网关。 这是你可以做的事情(但是AFAIK要求你为你的一个NIC指定一个成本),但是这样做可能会导致同样的事情发生
在你的configuration中,eth0首先被configuration。 我怀疑这意味着它是宣布它有一个默认网关,这反过来意味着eth1的网关被忽略。 你可以用ip r来检查。
更一般地说,在一个路由networking中(同样,如果你处于同一个广播域,则是另外一回事,因为你正在通过物理地址/ MAC而不是networking地址/ IP),总是有一个首选path,而您的stream量只是使用该首选path。
实际上,您所看到的只是您的eth0提供对eth0和eth1的IP地址的访问权限,因为它知道两者的路由,并返回到您的IP。
所以这里没有错 – 至less不是我能说的。
如果您为了可用性原因正在做这些事情,那么您可以考虑绑定您的NIC,并使用单个IP,因为该设置的variables较less。