cenário de caso; Linux Raspbian v9.1 conectado a uma rede 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
Observe o IP adquirido pelo DHCP: 172.18.25.248.
Às vezes, preciso conectar-me a outras redes, por isso, adiciono vários dispositivos NIC , como em:
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.
Tudo está bem até agora.
O problema vem quando eu quero definir (seja ele DHCP ou estático) a configuração IP de qualquer NIC, por exemplo, para o NIC principal (sempre 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
Após reinicializar (ou reiniciar a rede), o adaptador eth0
está definido como OK, mas qualquer outra NIC parece deixar de funcionar, pois não são mais mostradas:
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
Mesmo quando eles ainda são reconhecidos :
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
Claro, eu poderia ir para /etc/network/interfaces
novamente e definir eth1
, eth2
... etc. Mas não existe um método mais prático ?
Isto é: como posso definir a configuração de IP para um NIC específico em /etc/network/interfaces
sem modificar o comportamento dos outros?
Mais dados :
- Mesmos resultados com o PC de mesa executando o Ubuntu v16.04.
EDIT 01 :
Em uma instalação simples do Linux, esse é o% comum/etc/network/interfaces
que eu uso para encontrar:
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
Observe que, com esse arquivo /etc/network/interfaces
inalterado, todas as NICs são iniciadas corretamente (DHCP no meu caso) e configuradas.
A configuração manual de eth1
, eth2
... etc, pode ser (para algumas pessoas) de fato considerada uma maneira de resolver o problema, mas não é a maneira como a pergunta é feita. O fato é: parece que qualquer NIC que você conecta ( eth9
, wlan3
, enp2s0
... etc) é automaticamente iniciado e configurado (como DHCP) em um arquivo /etc/network/interfaces
intocado, e eu quero continuar esse comportamento.