My goal is to set two ethernet interfaces on two different ports and with two differents static IP on the same network. The matter is that one port will become reachable by the two IPs, the other won't. I proceed with the /etc/network/interfaces file and /etc/init.d/networking restart call. I also tried with ifupdown calls. Here is how I proceed:
I've just installed my Debian 3.16 OS without any network configuration.My device has two Ethernet ports.
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
Everything seems fine. I want to add a new ethernet interface to connect on my network, so I modify the /etc/network/interfaces file this way:
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
My device is now reachable on ethernet port let's say A with the IP 192.168.1.160, ifconfig is fine too. Then I add the new interface and modify /etc/network/interfaces this way:
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)
I expect to reach my device on port A with .160 and on port B with .161. But I actually reach my device on port A with both .160 and .161, and none on port B.
EDIT: If I plug the Ethernet cable on the physical port A, I want to be able to join (ping or ssh connexion) my device with IP 192.168.1.160. If I plug the Ethernet cable on the physical port B, I want to be able to join (ping or ssh connexion) my device with IP 192.168.1.161. (network is 192.168.1.0/24)
My questions are:
- What I am doing wrong? Are those file and calls aim to work together or are they non-compatible in their network management?
- What are the tools commonly used to configure a network interface on Debian 3.16 if not those one?
- Is there a link I've missed between network interfaces and the hardware?
Of course:
- I've spent lot of time looking for some answers and build my method with thoses answers, plus the network configuration for Debian documentation.
- I've tried to restart network interfaces with both /etc/init.d/networking restart and ifup/ifdown eth0
- Finally I've re-installed my Debian for that, so I also tried to reboot.
In your question terms are not clear, what you mean by
"I expect to reach my device on port A with .160 and on port B with .161. But I actually reach my device on port A with both .160 and .161, and none on port B."
If this will clear than might be we can provide you how exactly proceed.
Please have a look for policy-based routing in linux. May be below can help you: https://www.novell.com/support/kb/doc.php?id=7008874
http://blog.scottlowe.org/2013/05/29/a-quick-introduction-to-linux-policy-routing/
As you said you have tried with single gateway on active interface only, so that should worked. Problem here is with network, which is same for both interface. Can try with this example:
And test with ifconfig down eth0 and eth1 one by one
also can plug lan on both interface and try with ping or ssh.
Basically, I suspect this is about routing. Unless you are on the same LAN segment (i.e. broadcast domain) as the two IPs you mention, then your traffic needs to be routed.
The short version is that you have set both ports to have a default gateway. That is something you can do (but AFAIK requires you to specify a cost for one of your NICs), but this would still more than likely cause the same thing to happen
In your config, eth0 is configured first. I suspect this means it is the one announcing that it has a default gateway, which in turns means eth1's gateway is ignored. You can check this with
ip r
.More generally, in a routed network (again, if you are in the same broadcast domain, it is a different matter, because you are then going by physical address/MAC, not network address/IP), there is always a preferred path, and your traffic is simply using that preferred path.
In effect, all you are seeing is that your eth0 is providing access to eth0 and eth1's IP address, because it knows a route to both, and back to your IP.
So there is nothing wrong here - at least not that I can tell.
If you were doing all this for availability reasons, then you might consider bonding your NICs instead, and having a single IP, because that setup has less variables.