# Configuração de Rede via Netplan ### 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`` <br> ### Identificando a NIC Ethernet ``ifconfig -a`` <br> ### 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`` <br> ### Verificando existência do arquivo .yaml ``ls -lha /etc/netplan/`` <br> ### 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`` <br> ### 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]`` <br> ### Configuração COMPLETA sem (IP, Máscara, Gateway e DNS) ### Exemplo 1º: ``network:`` &nbsp;&nbsp;&nbsp;&nbsp;``version: 2`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;``renderer: networkd`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;``ethernets:`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``DEVICE_NAME:`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``dhcp4: yes/no`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``addresses: [IP_ADDRESS/NETMASK]`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;``gateway4: GATEWAY`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;``nameservers:`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``addresses: [NAMESERVER_1, NAMESERVER_2]`` <br> ### Configuração COMPLETA com (IP, Máscara, Gateway e DNS) ### Exemplo 2º: ``network:`` &nbsp;&nbsp;&nbsp;&nbsp;``Version: 2`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;``Renderer: NetworkManager/ networkd`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;``ethernets:`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``enp2s0:`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``dhcp4: no`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``addresses: [192.168.2.100/24]`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;``gateway4: 192.168.2.1`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;``nameservers:`` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ``addresses: [208.67.222.222, 208.67.220.220]`` <br> ### Aplicando configurações: ``sudo netplan try && sudo netplan apply`` <br> ### Verificando erros: ``sudo netplan -d apply`` <br> ### Reiniciando serviços de rede: ``sudo systemctl restart network-manager`` <br> ### 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 `` <br> ### 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 `` <br> ``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`` <br> ### Configuração de rede OK :wq ### Fonte original: https://vitux.com/how-to-configure-networking-with-netplan-on-ubuntu/ ### Autor: Fernando Henrique Santorsula E-mail: f208918@dac.unicamp.br **FEEC/UNICAMP - Campinas/SP/BR** https://www.fee.unicamp.br/