1

Case scenario; Raspbian Linux v9.1 connected to one network via RJ45:

luis@Fresoncio:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.25.248  netmask 255.255.255.0  broadcast 172.18.25.255
        inet6 fe80::5c59:95e9:c658:8ad2  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:92:fe:b3  txqueuelen 1000  (Ethernet)
        RX packets 24160  bytes 1673645 (1.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1968  bytes 196942 (192.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4  bytes 156 (156.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 156 (156.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Note the DHCP acquired IP: 172.18.25.248 .

Sometimes I need to connect to other networks, so I add several NIC devices, like in:

luis@Fresoncio:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.25.248  netmask 255.255.255.0  broadcast 172.18.25.255
        inet6 fe80::5c59:95e9:c658:8ad2  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:92:fe:b3  txqueuelen 1000  (Ethernet)
        RX packets 24160  bytes 1673645 (1.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1968  bytes 196942 (192.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.35.101  netmask 255.255.255.0  broadcast 192.168.35.255
        inet6 fe80::2064:deee:d534:1a83  prefixlen 64  scopeid 0x20<link>
        ether a0:ce:c8:09:f8:84  txqueuelen 1000  (Ethernet)
        RX packets 2378  bytes 177246 (173.0 KiB)
        RX errors 0  dropped 4  overruns 0  frame 0
        TX packets 54  bytes 9354 (9.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.33  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a170:6c36:802a:c19  prefixlen 64  scopeid 0x20<link>
        ether 3c:18:a0:07:63:8b  txqueuelen 1000  (Ethernet)
        RX packets 797  bytes 61728 (60.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 37  bytes 4845 (4.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

... etc.
Everything is all right until now.

The problem comes when I want to set (whether be it DHCP or static) the IP configuration of any NIC, for example, for the primary NIC (always eth0):

luis@Fresoncio:~$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

auto eth0
iface eth0 inet dhcp

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

After rebooting (or restarting the network) the eth0 adapter is set OK, but any other NIC seems to stop working, as they are not shown anymore:

luis@Fresoncio:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.25.248  netmask 255.255.255.0  broadcast 172.18.25.255
        inet6 fe80::5c59:95e9:c658:8ad2  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:92:fe:b3  txqueuelen 1000  (Ethernet)
        RX packets 24160  bytes 1673645 (1.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1968  bytes 196942 (192.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4  bytes 156 (156.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 156 (156.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Even when they are still recognized:

luis@Fresoncio:~$ ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.25.248  netmask 255.255.255.0  broadcast 172.18.25.255
        inet6 fe80::ba27:ebff:fe92:feb3  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:92:fe:b3  txqueuelen 1000  (Ethernet)
        RX packets 1430  bytes 109681 (107.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 194  bytes 33418 (32.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether a0:ce:c8:09:f8:84  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0e:c6:d4:10:b6  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth3: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 3c:18:a0:07:63:8b  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4  bytes 156 (156.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 156 (156.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Of course, I could go to /etc/network/interfaces again and set eth1, eth2... etc. But isn't there a more practical method?

This is: how can I set IP configuration for a specific NIC on /etc/network/interfaces without modifying the behavior of the others?

Further data:

  • Same results with desktop PC running Ubuntu v16.04.

EDIT 01:

In a plain Linux installation, this is the common /etc/network/interfaces I use to find:

luis@Fresoncio:~$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

Note that, whit this vanilla untouched /etc/network/interfaces file, all the NICs do start correctly (DHCP in my case) and get configured.

Manually configuring eth1, eth2... etc, could be (for some people) indeed considered a way to solve the issue, but it is not the way the question asks about. The fact is: it seems that any NIC you plug (eth9,wlan3,enp2s0... etc) is automatically started and configured (as DHCP) in a untouched /etc/network/interfaces file, and I want to keep this behavior.

1

The ifconfig -a is showing you all the devices that have been recognized and have appropriate drivers.

Plain ifconfig only shows devices that are up and configured.

Your /etc/network/interfaces file is only configuring the lo adapter and the eth0 adapter. You aren't configuring the other devices (eth1, etc) at boot time, so while they are there, nothing has brought them online and activated them. (unless you've done something in a file under /etc/network/interfaces.d ?)

Assuming there is nothing in /etc/network/interfaces.d you can set /etc/network/interfaces up like so - eth0 will still do DHCP and provide the default gateway, the other devices will be on their subnets with no gateway associated.

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
ifact eth1 inet static
   address 192.168.35.101
   netmask 255.255.255.0

auto eth2
ifact eth2 inet static
   address 192.168.1.33
   netmask 255.255.255.0

Note that you can do the same thing with only 1 NIC and use virtual interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth0:1
ifact eth0:1 inet static
   address 192.168.35.101
   netmask 255.255.255.0

auto eth0:2
ifact eth0:2 inet static
   address 192.168.1.33
   netmask 255.255.255.0
  • As referred, the original question asks about a more practical (this is: different) method than the (obvious one) "go to /etc/network/interfaces again and set eth1, eth2... etc" option. – Sopalajo de Arrierez Dec 22 '17 at 22:15
  • In a common untouched vanilla Linux, the /etc/network/interfaces file is only configuring the lo adapter, but the other existing NICs (like eth0 or enp0s7) do correctly get started and DHCP configured. Added this info to original post. – Sopalajo de Arrierez Dec 22 '17 at 22:34
  • @SopalajodeArrierez - that really depends on the distro itself. the interfaces file is a Debian thing, so it is in Ubuntu, Mint, etc. However most of those, and even Debian when isntalled as a GUI desktop, use NetworkManager (of some type) so as to handle wired and wireless connections. I keep it (or wicd) on my laptop but remove it on desktops. Servers it is never isntalled and everything is in the interfaces file. – ivanivan Dec 23 '17 at 1:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.