Configurando a rede ethernet no ubuntu usando netplan

Nesse artigo vou falar como você pode configurar a rede ethernet cabeada em seu ubuntu.

Existem duas maneiras de se configurar o netplan , usando o Network Manager e o Systemd.

Vamos inicialmente configurar usando Network Manager .

Vamos identificar o nome das nossa placa de rede.

julio@julio-PC:~$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:ab:47:90 brd ff:ff:ff:ff:ff:ff
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:03:22:e9 brd ff:ff:ff:ff:ff:ff

No meu caso :

enp0s3 :
ip 10.0.2.15/24
Gateway 10.0.2.2
dns 10.0.2.3

 

enp0s8
ip 192.168.101.162/24
gateway 192.168.101.1
dns 192.168.101.1

Vamos listar qual o nome do arquivo do netplan de nosso sistema.

julio@julio-PC:~$ ls -latr /etc/netplan
total 20
-rw-r--r--   1 root root   104 fev  9  2019 01-network-manager-all.yaml
drwxr-xr-x   2 root root  4096 fev  9  2019 .
drwxr-xr-x 132 root root 12288 mai 11 11:49 ..

Inicialmente a interface como DHCP.

sudo vi /etc/netplan/01-network-manager-all.yaml

Lembrando da indentação do texto pois caso não esteja dessa forma ele vai dar erro.

network:
    version: 2
    renderer: NetworkManager
    ethernets:
        enp0s3:
            dhcp4: true

        enp0s8:
            dhcp4: true

Vamos aplicar:

sudo netplan --debug apply
julio@julio-PC:~$ sudo netplan --debug  apply 
** (generate:2620): DEBUG: 12:27:58.108: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:2620): DEBUG: 12:27:58.109: starting new processing pass
** (generate:2620): DEBUG: 12:27:58.109: enp0s8: setting default backend to 2
** (generate:2620): DEBUG: 12:27:58.109: enp0s3: setting default backend to 2
** (generate:2620): DEBUG: 12:27:58.109: Generating output files..
** (generate:2620): DEBUG: 12:27:58.109: networkd: definition enp0s8 is not for us (backend 2)
** (generate:2620): DEBUG: 12:27:58.110: networkd: definition enp0s3 is not for us (backend 2)
DEBUG:no netplan generated networkd configuration exists
DEBUG:netplan generated NM configuration exists, restarting NM
DEBUG:enp0s3 not found in {}
DEBUG:enp0s8 not found in {'enp0s3': {'dhcp4': True}}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    enp0s3:
      dhcp4: true
    enp0s8:
      dhcp4: true
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:device enp0s3 operstate is up, not changing
DEBUG:device enp0s8 operstate is up, not changing
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for enp0s3
DEBUG:netplan triggering .link rules for enp0s8

Vamos verificar os nomes criados.

julio@julio-PC:~$ nmcli connection show 
NAME            UUID                                  TYPE      DEVICE 
netplan-enp0s3  0cd33900-1641-328d-802b-91673510829b  ethernet  enp0s3 
netplan-enp0s8  7ba7a298-c741-366c-a1ac-84ad05b0a814  ethernet  enp0s8

Verificando a configuração:

ulio@julio-PC:~$ nmcli connection show  netplan-enp0s3
connection.id:                          netplan-enp0s3
connection.uuid:                        0cd33900-1641-328d-802b-91673510829b
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              enp0s3
connection.autoconnect:                 sim
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.auth-retries:                -1
connection.timestamp:                   1589217779
connection.read-only:                   não
GENERAL.UUID:                           0cd33900-1641-328d-802b-91673510829b
GENERAL.DEVICES:                        enp0s3
GENERAL.STATE:                          ativado
GENERAL.DEFAULT:                        sim
GENERAL.DEFAULT6:                       não
GENERAL.SPEC-OBJECT:                    --
GENERAL.VPN:                            não
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveConnection/1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings/2
GENERAL.ZONE:                           --
GENERAL.MASTER-PATH:                    --
IP4.ADDRESS[1]:                         10.0.2.15/24
IP4.GATEWAY:                            10.0.2.2
IP4.ROUTE[1]:                           dst = 0.0.0.0/0, nh = 10.0.2.2, mt = 100
IP4.ROUTE[2]:                           dst = 10.0.2.0/24, nh = 0.0.0.0, mt = 100
IP4.ROUTE[3]:                           dst = 169.254.0.0/16, nh = 0.0.0.0, mt = 1000
IP4.DNS[1]:                             10.0.2.3
DHCP4.OPTION[1]:                        requested_host_name = 1
DHCP4.OPTION[2]:                        requested_domain_search = 1
DHCP4.OPTION[3]:                        dhcp_message_type = 5
DHCP4.OPTION[4]:                        requested_time_offset = 1
DHCP4.OPTION[5]:                        requested_domain_name = 1
DHCP4.OPTION[6]:                        requested_rfc3442_classless_static_routes = 1
DHCP4.OPTION[7]:                        requested_broadcast_address = 1
DHCP4.OPTION[8]:                        requested_wpad = 1
DHCP4.OPTION[9]:                        requested_netbios_scope = 1
DHCP4.OPTION[10]:                       next_server = 10.0.2.4
DHCP4.OPTION[11]:                       broadcast_address = 10.0.2.255
DHCP4.OPTION[12]:                       requested_interface_mtu = 1
DHCP4.OPTION[13]:                       requested_subnet_mask = 1
DHCP4.OPTION[14]:                       dhcp_lease_time = 86400
DHCP4.OPTION[15]:                       routers = 10.0.2.2
DHCP4.OPTION[16]:                       ip_address = 10.0.2.15
DHCP4.OPTION[17]:                       requested_static_routes = 1
DHCP4.OPTION[18]:                       expiry = 1589297279
DHCP4.OPTION[19]:                       filename = Kubuntu-18.pxe
DHCP4.OPTION[20]:                       requested_domain_name_servers = 1
DHCP4.OPTION[21]:                       domain_name_servers = 10.0.2.3
DHCP4.OPTION[22]:                       requested_ntp_servers = 1
DHCP4.OPTION[23]:                       requested_netbios_name_servers = 1
DHCP4.OPTION[24]:                       requested_ms_classless_static_routes = 1
DHCP4.OPTION[25]:                       requested_routers = 1
DHCP4.OPTION[26]:                       subnet_mask = 255.255.255.0
DHCP4.OPTION[27]:                       network_number = 10.0.2.0
DHCP4.OPTION[28]:                       dhcp_server_identifier = 10.0.2.2
IP6.ADDRESS[1]:                         fe80::a00:27ff:feab:4790/64

A configuração com ip fixo, network manager:

sudo vi /etc/netplan/01-network-manager-all.yaml

 

network:
    version: 2
    renderer: NetworkManager
    ethernets:
        enp0s3:
            dhcp4: no
            addresses: [10.0.2.15/24]
            gateway4: 10.0.2.2
            nameservers:
                addresses: [10.0.2.3,8.8.8.8]
                search: [it-howto.org]

        enp0s8:
            dhcp4: no
            addresses: [192.168.101.106/24]
            gateway4: 192.168.101.1
            nameservers:
                addresses: [192.168.101.1,8.8.8.8]

Aplicando a configuração:

julio@julio-PC:~$ sudo netplan --debug  apply 
** (generate:2991): DEBUG: 14:33:18.475: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:2991): DEBUG: 14:33:18.475: starting new processing pass
** (generate:2991): DEBUG: 14:33:18.476: enp0s8: setting default backend to 2
** (generate:2991): DEBUG: 14:33:18.476: enp0s3: setting default backend to 2
** (generate:2991): DEBUG: 14:33:18.476: Generating output files..
** (generate:2991): DEBUG: 14:33:18.477: networkd: definition enp0s8 is not for us (backend 2)
** (generate:2991): DEBUG: 14:33:18.477: networkd: definition enp0s3 is not for us (backend 2)
DEBUG:no netplan generated networkd configuration exists
DEBUG:netplan generated NM configuration exists, restarting NM
DEBUG:enp0s3 not found in {}
DEBUG:enp0s8 not found in {'enp0s3': {'dhcp4': False, 'addresses': ['10.0.2.15/24'], 'gateway4': '10.0.2.2', 'nameservers': {'addresses': ['10.0.2.3', '8.8.8.8'], 'search': ['it-howto.org']}}}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    enp0s3:
      addresses:
      - 10.0.2.15/24
      dhcp4: false
      gateway4: 10.0.2.2
      nameservers:
        addresses:
        - 10.0.2.3
        - 8.8.8.8
        search:
        - it-howto.org
    enp0s8:
      addresses:
      - 192.168.101.106/24
      dhcp4: false
      gateway4: 192.168.101.1
      nameservers:
        addresses:
        - 192.168.101.1
        - 8.8.8.8
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:device enp0s3 operstate is up, not changing
DEBUG:device enp0s8 operstate is up, not changing
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for enp0s3
DEBUG:netplan triggering .link rules for enp0s8
julio@julio-PC:~$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:feab:4790  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:ab:47:90  txqueuelen 1000  (Ethernet)
        RX packets 265  bytes 120576 (120.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 470  bytes 61504 (61.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.101.106  netmask 255.255.255.0  broadcast 192.168.101.255
        inet6 fe80::a00:27ff:fe03:22e9  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:03:22:e9  txqueuelen 1000  (Ethernet)
        RX packets 7451  bytes 544346 (544.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 252  bytes 32660 (32.6 KB)
        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 1000  (Loopback Local)
        RX packets 318  bytes 23804 (23.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 318  bytes 23804 (23.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
julio@julio-PC:~$ route -n
Tabela de Roteamento IP do Kernel
Destino         Roteador        MáscaraGen.    Opções Métrica Ref   Uso Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG    100    0        0 enp0s3
0.0.0.0         192.168.101.1   0.0.0.0         UG    101    0        0 enp0s8
10.0.2.0        0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 enp0s3
192.168.101.0   0.0.0.0         255.255.255.0   U     101    0        0 enp0s8
julio@julio-PC:~$ nmcli connection show  
NAME            UUID                                  TYPE      DEVICE 
netplan-enp0s3  0cd33900-1641-328d-802b-91673510829b  ethernet  enp0s3 
netplan-enp0s8  7ba7a298-c741-366c-a1ac-84ad05b0a814  ethernet  enp0s8 

Agora vamos configurar usando o systemd.

Inicialmente vamos  aplicar a configuração de DHCP.

Vamos remover as configurações geradas pelo network manager:

julio@julio-PC:~$ nmcli connection delete netplan-enp0s3  netplan-enp0s8
A conexão "netplan-enp0s3" (0cd33900-1641-328d-802b-91673510829b) foi excluída com sucesso.

(process:3312): libnm-WARNING **: 14:53:14.146: no object known for /org/freedesktop/NetworkManager/ActiveConnection/2

A conexão "netplan-enp0s8" (7ba7a298-c741-366c-a1ac-84ad05b0a814) foi excluída com sucesso.

Editar o arquivo.

sudo vi /etc/netplan/01-network-manager-all.yaml

Conteúdo:

network:
    version: 2
    renderer: networkd
    ethernets:
        enp0s3:
            dhcp4: true
        
        enp0s8:
            dhcp4: true

 

Aplicar a configuração:

julio@julio-PC:~$ sudo netplan --debug  apply 
** (generate:3630): DEBUG: 15:03:28.295: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:3630): DEBUG: 15:03:28.296: starting new processing pass
** (generate:3630): DEBUG: 15:03:28.296: enp0s8: setting default backend to 1
** (generate:3630): DEBUG: 15:03:28.296: enp0s3: setting default backend to 1
** (generate:3630): DEBUG: 15:03:28.296: Generating output files..
** (generate:3630): DEBUG: 15:03:28.296: NetworkManager: definition enp0s8 is not for us (backend 1)
** (generate:3630): DEBUG: 15:03:28.296: NetworkManager: definition enp0s3 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:enp0s3 not found in {}
DEBUG:enp0s8 not found in {'enp0s3': {'dhcp4': True}}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    enp0s3:
      dhcp4: true
    enp0s8:
      dhcp4: true
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:device enp0s3 operstate is up, not changing
DEBUG:device enp0s8 operstate is up, not changing
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for enp0s3
DEBUG:netplan triggering .link rules for enp0s8

Verificamos que o netplan cria esses dois arquivos:

julio@julio-PC:~$ ls -latr /run/systemd/network/
total 8
drwxr-xr-x 22 root root 500 mai 11 14:45 ..
-rw-r--r--  1 root root 102 mai 11 15:03 10-netplan-enp0s8.network
-rw-r--r--  1 root root 102 mai 11 15:03 10-netplan-enp0s3.network
julio@julio-PC:~$ cat  /run/systemd/network/10-netplan-enp0s3.network
[Match]
Name=enp0s3

[Network]
DHCP=ipv4
LinkLocalAddressing=ipv6

[DHCP]
UseMTU=true
RouteMetric=100

Agora vamos de ip fixo.

Editar o arquivo:

sudo vi /etc/netplan/01-network-manager-all.yaml
network:
    version: 2
    renderer: networkd
    ethernets:
        enp0s3:
            dhcp4: no
            addresses: [10.0.2.15/24]
            gateway4: 10.0.2.2
            nameservers:
                addresses: [10.0.2.3,8.8.8.8]
                search: [it-howto.org]

        enp0s8:
            dhcp4: no
            addresses: [192.168.101.106/24]
            gateway4: 192.168.101.1
            nameservers:
                addresses: [192.168.101.1,8.8.8.8]

Aplicar:

julio@julio-PC:~$ sudo netplan --debug  apply 
** (generate:3747): DEBUG: 15:09:21.077: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:3747): DEBUG: 15:09:21.077: starting new processing pass
** (generate:3747): DEBUG: 15:09:21.077: enp0s8: setting default backend to 1
** (generate:3747): DEBUG: 15:09:21.077: enp0s3: setting default backend to 1
** (generate:3747): DEBUG: 15:09:21.078: Generating output files..
** (generate:3747): DEBUG: 15:09:21.078: NetworkManager: definition enp0s8 is not for us (backend 1)
** (generate:3747): DEBUG: 15:09:21.078: NetworkManager: definition enp0s3 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:enp0s3 not found in {}
DEBUG:enp0s8 not found in {'enp0s3': {'dhcp4': False, 'addresses': ['10.0.2.15/24'], 'gateway4': '10.0.2.2', 'nameservers': {'addresses': ['10.0.2.3', '8.8.8.8'], 'search': ['it-howto.org']}}}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    enp0s3:
      addresses:
      - 10.0.2.15/24
      dhcp4: false
      gateway4: 10.0.2.2
      nameservers:
        addresses:
        - 10.0.2.3
        - 8.8.8.8
        search:
        - it-howto.org
    enp0s8:
      addresses:
      - 192.168.101.106/24
      dhcp4: false
      gateway4: 192.168.101.1
      nameservers:
        addresses:
        - 192.168.101.1
        - 8.8.8.8
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:device enp0s3 operstate is up, not changing
DEBUG:device enp0s8 operstate is up, not changing
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for enp0s3
DEBUG:netplan triggering .link rules for enp0s8
julio@julio-PC:~$ ls -latr /run/systemd/network/
total 8
drwxr-xr-x 22 root root 500 mai 11 14:45 ..
-rw-r--r--  1 root root 135 mai 11 15:09 10-netplan-enp0s8.network
-rw-r--r--  1 root root 140 mai 11 15:09 10-netplan-enp0s3.network
drwxr-xr-x  2 root root  80 mai 11 15:09 .
julio@julio-PC:~$ cat  /run/systemd/network/10-netplan-enp0s3.network
[Match]
Name=enp0s3

[Network]
LinkLocalAddressing=ipv6
Address=10.0.2.15/24
Gateway=10.0.2.2
DNS=10.0.2.3
DNS=8.8.8.8
Domains=it-howto.org
julio@julio-PC:~$ cat  /run/systemd/network/10-netplan-enp0s8.network
[Match]
Name=enp0s8

[Network]
LinkLocalAddressing=ipv6
Address=192.168.101.106/24
Gateway=192.168.101.1
DNS=192.168.101.1
DNS=8.8.8.8

Reiniciar o serviço:

julio@julio-PC:~$ sudo systemctl restart systemd-networkd
julio@julio-PC:~$ sudo systemctl status  systemd-networkd
[sudo] senha para julio: 
● systemd-networkd.service - Network Service
   Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled-runtime; vendor preset: enabled)
   Active: active (running) since Mon 2020-05-11 15:15:04 -03; 1min 25s ago
     Docs: man:systemd-networkd.service(8)
 Main PID: 358 (systemd-network)
   Status: "Processing requests..."
    Tasks: 1 (limit: 1098)
   CGroup: /system.slice/systemd-networkd.service
           └─358 /lib/systemd/systemd-networkd

mai 11 15:15:04 julio-PC systemd-networkd[358]: lo: Link is not managed by us
mai 11 15:15:04 julio-PC systemd-networkd[358]: enp0s8: IPv6 successfully enabled
mai 11 15:15:04 julio-PC systemd-networkd[358]: lo: Link is not managed by us
mai 11 15:15:04 julio-PC systemd-networkd[358]: enp0s3: IPv6 successfully enabled
mai 11 15:15:04 julio-PC systemd-networkd[358]: enp0s8: Gained carrier
mai 11 15:15:04 julio-PC systemd-networkd[358]: enp0s3: Gained carrier
mai 11 15:15:05 julio-PC systemd-networkd[358]: enp0s8: Gained IPv6LL
mai 11 15:15:05 julio-PC systemd-networkd[358]: enp0s8: Configured
mai 11 15:15:06 julio-PC systemd-networkd[358]: enp0s3: Gained IPv6LL
mai 11 15:15:06 julio-PC systemd-networkd[358]: enp0s3: Configured
julio@julio-PC:~$ nmcli connection show 
NAME  UUID  TYPE  DEVICE 
julio@julio-PC:~$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:feab:4790  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:ab:47:90  txqueuelen 1000  (Ethernet)                                                                                                                                                                                                                   
        RX packets 450  bytes 27285 (27.2 KB)                                                                                                                                                                                                                                  
        RX errors 0  dropped 0  overruns 0  frame 0                                                                                                                                                                                                                            
        TX packets 124  bytes 13527 (13.5 KB)                                                                                                                                                                                                                                  
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                               
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                                                                                                                                                                                                   
        inet 192.168.101.106  netmask 255.255.255.0  broadcast 192.168.101.255                                                                                                                                                                                                 
        inet6 fe80::a00:27ff:fe03:22e9  prefixlen 64  scopeid 0x20<link>                                                                                                                                                                                                       
        ether 08:00:27:03:22:e9  txqueuelen 1000  (Ethernet)                                                                                                                                                                                                                   
        RX packets 505  bytes 38812 (38.8 KB)                                                                                                                                                                                                                                  
        RX errors 0  dropped 180  overruns 0  frame 0                                                                                                                                                                                                                          
        TX packets 58  bytes 6516 (6.5 KB)                                                                                                                                                                                                                                     
        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 1000  (Loopback Local)                                                                                                                                                                                                                                
        RX packets 49  bytes 5045 (5.0 KB)                                                                                                                                                                                                                                     
        RX errors 0  dropped 0  overruns 0  frame 0                                                                                                                                                                                                                            
        TX packets 49  bytes 5045 (5.0 KB)                                                                                                                                                                                                                                     
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Deixa seu comentário.

 

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *