Consultar configurações das interfaces de rede
🎯
ROTEIRO: O objetivo é descobrir quais são as configurações de rede já definidas para cada sistema.
Lembre-se: no Ubuntu é com o Netplan e no AlmaLinux é com o NetworkManager!
Aqui o jeito é olhar o conteúdo do aquivo .yaml com as configurações de rede:
ubuntu@ubuntu-cloud:/etc/netplan$ sudo cat /etc/netplan/50-cloud-init.yaml
network:
version: 2
ethernets:
ens3:
match:
macaddress: "0c:7e:8f:15:00:00"
dhcp4: true
dhcp6: true
set-name: "ens3"
ubuntu@ubuntu-cloud:/etc/netplan$
Pode usar também o comando sudo networkctl status:
ubuntu@ubuntu-cloud:~$ sudo networkctl status
[sudo] password for ubuntu:
● Interfaces: 2, 1
State: routable
Online state: online
Address: 10.27.255.95 on ens3
fe80::e7e:8fff:fe15:0 on ens3
Gateway: 10.27.0.20 on ens3
DNS: 208.67.222.222
208.67.220.220
Jul 27 23:13:23 ubuntu-cloud systemd-networkd[599]: lo: Gained carrier
Jul 27 23:13:23 ubuntu-cloud systemd-networkd[599]: Enumeration completed
Jul 27 23:13:23 ubuntu-cloud systemd[1]: Started systemd-networkd.service - Net>
Jul 27 23:13:23 ubuntu-cloud systemd-networkd[599]: ens3: Configuring with /run>
Jul 27 23:13:23 ubuntu-cloud systemd-networkd[599]: ens3: Link UP
Jul 27 23:13:23 ubuntu-cloud systemd-networkd[599]: ens3: Gained carrier
Jul 27 23:13:23 ubuntu-cloud systemd-networkd[599]: ens3: DHCPv4 address 10.27.>
Jul 27 23:13:23 ubuntu-cloud systemd[1]: Starting systemd-networkd-wait-online.>
Jul 27 23:13:25 ubuntu-cloud systemd-networkd[599]: ens3: Gained IPv6LL
Jul 27 23:13:25 ubuntu-cloud systemd[1]: Finished systemd-networkd-wait-online.>
ubuntu@ubuntu-cloud:~$
nmcli connection show
[almalinux@almalinux /]$ nmcli connection show NAME UUID TYPE DEVICE System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 ethernet eth0 [almalinux@almalinux /]$
ou:
nmcli device show
[almalinux@almalinux ~]$ nmcli device show GENERAL.DEVICE: eth0 GENERAL.TYPE: ethernet GENERAL.HWADDR: 0C:01:72:49:00:00 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: System eth0 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 10.27.255.94/16 IP4.GATEWAY: 10.27.0.20 IP4.ROUTE[1]: dst = 10.27.0.0/16, nh = 0.0.0.0, mt = 100 IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 10.27.0.20, mt = 100 IP4.DNS[1]: 208.67.222.222 IP4.DNS[2]: 208.67.220.220 IP4.DOMAIN[1]: ifma.edu IP6.ADDRESS[1]: fe80::e01:72ff:fe49:0/64 IP6.GATEWAY: -- IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 256 GENERAL.DEVICE: lo GENERAL.TYPE: loopback GENERAL.HWADDR: 00:00:00:00:00:00 GENERAL.MTU: 65536 GENERAL.STATE: 10 (unmanaged) GENERAL.CONNECTION: -- GENERAL.CON-PATH: -- IP4.ADDRESS[1]: 127.0.0.1/8 IP4.GATEWAY: -- IP6.ADDRESS[1]: ::1/128 IP6.GATEWAY: -- IP6.ROUTE[1]: dst = ::1/128, nh = ::, mt = 256 [almalinux@almalinux ~]$
💡
No AlmaLinux, as configurações de rede são geralmente gerenciadas pelo NetworkManager ou pelos arquivos do diretório
/etc/sysconfig/network-scripts/.
É possível consultar diretamente as informações de uma determinada interface:
[almalinux@almalinux ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 # Created by cloud-init on instance boot automatically, do not edit. # BOOTPROTO=dhcp DEVICE=eth0 HWADDR=0c:01:72:49:00:00 ONBOOT=yes TYPE=Ethernet USERCTL=no [almalinux@almalinux ~]$
RESUMO
| Distro | Gerenciador | Comando | Finalidade |
|---|---|---|---|
| Ubuntu | Netplan | sudo cat /etc/netplan/50-cloud-init.yaml |
Exibe as configurações de rede definidas no arquivo .yaml. |
| Ubuntu | systemd-networkd | sudo networkctl status |
Mostra o status da rede e as configurações aplicadas (IP, gateway, DNS). |
| AlmaLinux | NetworkManager | nmcli connection show |
Lista as conexões definidas e associadas às interfaces. |
| AlmaLinux | NetworkManager | nmcli device show |
Mostra as configurações completas (IP, gateway, DNS) de cada dispositivo. |
| AlmaLinux | Arquivo direto | cat /etc/sysconfig/network-scripts/ifcfg-eth0 |
Exibe a configuração da interface eth0 definida no arquivo ifcfg-eth0. |
