Ferramentas do usuário

Ferramentas do site


infra-estrutura:linux:entendendo_nomes_dispositivos_rede_previsivel_enp0s1

Entendendo os nomes de dispositivos de redes previsiveis

Após atualizar alguns servidores notei que o nome das interfaces mudaram do velho padrão UNIX/Linux eth0 para nomes nadas convencionais.

freewaynet@megatron:~$ ifconfig 
ens160    Link encap:Ethernet  HWaddr 00:0c:29:50:b6:8b  
          inet addr:172.16.30.26  Bcast:172.16.30.255  Mask:255.255.255.0
          inet6 addr: fde5:9eef:b183:0:20c:29ff:fe50:b68b/64 Scope:Global
          inet6 addr: fe80::20c:29ff:fe50:b68b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4172941 errors:0 dropped:20 overruns:0 frame:0
          TX packets:4826426 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:359769672 (359.7 MB)  TX bytes:563971622 (563.9 MB)

ao visualizar estes nomes fiquei me perguntando. Porque? =) e se não bastasse existem nomes mais estruncho, tais como enp0s1f1 :-?

Diante desse cenário fui atrás porque essa mudança, e o que significa esse nome maluco. Bom após dar uma rápida lida no seguinte link https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/. Eu entendi que os nomes malucos vem do código systemd, alias, esqueci de mencionar os nomes previsiveis vem das distribuições que utilizam o systemd. Enfim após algumas análises e buscas na internet, encontrei no github o código que implementa toda a nomemclatura e vejam só o programador comentou tão bem que nem precisei entender o código. =)

https://github.com/systemd/systemd/blob/master/src/udev/udev-builtin-net_id.c

abstraindo

/*
 * Predictable network interface device names based on:
 *  - firmware/bios-provided index numbers for on-board devices
 *  - firmware-provided pci-express hotplug slot index number
 *  - physical/geographical location of the hardware
 *  - the interface's MAC address
 *
 * http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames
 *
 * Two character prefixes based on the type of interface:
 *   en — Ethernet
 *   sl — serial line IP (slip)
 *   wl — wlan
 *   ww — wwan
 *
 * Type of names:
 *   b<number>                             — BCMA bus core number
 *   c<bus_id>                             — bus id of a grouped CCW or CCW device,
 *                                           with all leading zeros stripped [s390]
 *   o<index>[n<phys_port_name>|d<dev_port>]
 *                                         — on-board device index number
 *   s<slot>[f<function>][n<phys_port_name>|d<dev_port>]
 *                                         — hotplug slot index number
 *   x<MAC>                                — MAC address
 *   [P<domain>]p<bus>s<slot>[f<function>][n<phys_port_name>|d<dev_port>]
 *                                         — PCI geographical location
 *   [P<domain>]p<bus>s<slot>[f<function>][u<port>][..][c<config>][i<interface>]
 *                                         — USB port number chain
 *   v<slot>                               - VIO slot number (IBM PowerVM)
 *   a<vendor><model>i<instance>           — Platform bus ACPI instance id
 *
 * All multi-function PCI devices will carry the [f<function>] number in the
 * device name, including the function 0 device.
 *
 * SR-IOV virtual devices are named based on the name of the parent interface,
 * with a suffix of "v<N>", where <N> is the virtual device number.
 *
 * When using PCI geography, The PCI domain is only prepended when it is not 0.
 *
 * For USB devices the full chain of port numbers of hubs is composed. If the
 * name gets longer than the maximum number of 15 characters, the name is not
 * exported.
 * The usual USB configuration == 1 and interface == 0 values are suppressed.
 *
....

Resumindo. Os nomes são baseados:

  • O firmware/bios prove indices para dispositivos on-board
  • O firmware dos barramentos pci-express fornece o indice do slot
  • A localização fisica/geografica dohardware
  • O endereço MAC da intefaces

Seguindo mais a baixo temos exemplos para entender isso.

Uma placa PCI com 2 portas ethernet

  • enp2s0f0
  • enp2s0f1
 * PCI Ethernet multi-function card with 2 ports:
 *   /sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/enp2s0f0
 *   ID_NET_NAME_MAC=enx78e7d1ea46da
 *   ID_NET_NAME_PATH=enp2s0f0
 *   /sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.1/net/enp2s0f1
 *   ID_NET_NAME_MAC=enx78e7d1ea46dc
 *   ID_NET_NAME_PATH=enp2s0f1
<code>
 
O caminho **/sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/enp2s0f0** é o caminho baseado no barramento PCI.
 
Um exemplo da minha máquina
 
<code bash>
freewaynet@megatron:~$ lspci | grep -i Ethernet
03:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
0b:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
13:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
freewaynet@megatron:~$ 

Vamos visualizar o caminho(PATH) destas placas.

freewaynet@megatron:~$ lspci | grep -i Ethernet
03:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
0b:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
13:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
freewaynet@megatron:~$ udevadm info -e | grep  ^P.*0000:03:00.0*
P: /devices/pci0000:00/0000:00:15.0/0000:03:00.0
P: /devices/pci0000:00/0000:00:15.0/0000:03:00.0/net/ens160
freewaynet@megatron:~$ udevadm info -e | grep  ^P.*0000:0b:00.0*
P: /devices/pci0000:00/0000:00:16.0/0000:0b:00.0
P: /devices/pci0000:00/0000:00:16.0/0000:0b:00.0/net/ens192
freewaynet@megatron:~$ udevadm info -e | grep  ^P.*0000:13:00.0*
P: /devices/pci0000:00/0000:00:17.0/0000:13:00.0
P: /devices/pci0000:00/0000:00:17.0/0000:13:00.0/net/ens224
freewaynet@megatron:~$ ifconfig 
ens160    Link encap:Ethernet  HWaddr 00:0c:29:50:b6:8b  
          inet addr:172.16.30.26  Bcast:172.16.30.255  Mask:255.255.255.0
          inet6 addr: fde5:9eef:b183:0:20c:29ff:fe50:b68b/64 Scope:Global
          inet6 addr: fe80::20c:29ff:fe50:b68b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4315926 errors:0 dropped:20 overruns:0 frame:0
          TX packets:4991923 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:372119971 (372.1 MB)  TX bytes:582529088 (582.5 MB)
 
ens192    Link encap:Ethernet  HWaddr 00:0c:29:50:b6:95  
          inet addr:192.168.1.8  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: 2804:ff0:3:0:20c:29ff:fe50:b695/64 Scope:Global
          inet6 addr: fe80::20c:29ff:fe50:b695/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3260293 errors:0 dropped:221 overruns:0 frame:0
          TX packets:3334017 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1182672911 (1.1 GB)  TX bytes:278719183 (278.7 MB)
 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:564953 errors:0 dropped:0 overruns:0 frame:0
          TX packets:564953 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:36594036 (36.5 MB)  TX bytes:36594036 (36.5 MB)
 
freewaynet@megatron:~$

Att.