OS: Linux Xubuntu & Ubuntu (18.04LTS)
Objetivo:
Configurar rede em modo texto utilizando o software NIC (Network Interface Card) “Ethernet”
Instalando o pacote Net-tools (ifconfig)
apt update && apt upgrade && apt install net-tools -y
Identificando a NIC Ethernet
ifconfig -a
Retorno do comando anterior:
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet netmask broadcast
inet6 fe80::1e39:47ff:fe0b:855e prefixlen 64 scopeid 0x20
inet6 fdc0:6985:cf43:0:1e39:47ff:fe0b:855e prefixlen 64 scopeid 0x0
ether 1c:39:47:0b:85:5e txqueuelen 1000 (Ethernet)
RX packets 1083 bytes 87247 (87.2 KB)
RX errors 0 dropped 22 overruns 0 frame 0
TX packets 205 bytes 30745 (30.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Verificando existência do arquivo .yaml
ls -lha /etc/netplan/
Resultado do comando anterior:
total 20K
drwxr-xr-x 2 root root 4,0K mai 4 22:11
drwxr-xr-x 146 root root 12K mai 4 21:54
-rw-r--r-- 1 root root 189 mai 4 22:11
01-network-manager-all.yaml
Configuração SEM gateway e DNS
#--Configuration Network Netplan
#--Linux Ubuntu 18.04LTS
network:
version: 2
renderer: networkd
ethernets:
enp2s0:
dhcp4: no
addresses: [192.168.2.100/24]
Configuração COMPLETA sem (IP, Máscara, Gateway e DNS)
Exemplo 1º:
network:
version: 2
renderer: networkd
ethernets:
DEVICE_NAME:
dhcp4: yes/no
addresses: [IP_ADDRESS/NETMASK]
gateway4: GATEWAY
nameservers:
addresses: [NAMESERVER_1, NAMESERVER_2]
Configuração COMPLETA com (IP, Máscara, Gateway e DNS)
Exemplo 2º:
network:
Version: 2
Renderer: NetworkManager/ networkd
ethernets:
enp2s0:
dhcp4: no
addresses: [192.168.2.100/24]
gateway4: 192.168.2.1
nameservers:
addresses: [208.67.222.222, 208.67.220.220]
Aplicando configurações:
sudo netplan try && sudo netplan apply
Verificando erros:
sudo netplan -d apply
Reiniciando serviços de rede:
sudo systemctl restart network-manager
Verificando resultados:
sudo ifconfig -a enp2s0
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.2.100 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::1e39:47ff:fe0b:855e prefixlen 64 scopeid 0x20<link> inet6 fdc0:6985:cf43:0:1e39:47ff:fe0b:855e prefixlen 64 scopeid 0x0<global> ether 1c:39:47:0b:85:5e txqueuelen 1000 (Ethernet) RX packets 1904 bytes 150730 (150.7 KB) RX errors 0 dropped 22 overruns 0 frame 0 TX packets 262 bytes 40821 (40.8 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Testes de conectividade:
santorsula@inspirion:$ ping -c 3 192.168.2.1
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from 192.168.2.1: icmp_seq=2 ttl=64 time=0.049 ms
64 bytes from 192.168.2.1: icmp_seq=3 ttl=64 time=0.051 ms
santorsula@inspirion:$ ping -c 3 208.67.222.222
64 bytes from 208.67.222.222: icmp_seq=1 ttl=54 time=17.0 ms
64 bytes from 208.67.222.222: icmp_seq=2 ttl=54 time=15.4 ms
64 bytes from 208.67.222.222: icmp_seq=3 ttl=54 time=20.3 ms
Fonte original: https://vitux.com/how-to-configure-networking-with-netplan-on-ubuntu/