Linux netplan

2023/02/04


Go back

I installed Ubuntu Server 22.04 in an old tablet. When I installed it, it asked me for the wifi connection, which ended up getting stored by default for subsequent use. That’s fine, but I want to disable the wifi connection, and instead use the ethernet connection I plugged in via a USB-ethernet converter. Unfortunately, such connection does not get enabled by default, and needs some additional manual tweaking. Here’s what I did:

  1. Confirm with the ip command that the ethernet connection is detected. It does not show up with the name eth0 as usual, but with a very long and complicated name, enx1234a1234567. The wifi connection is wwlp1s0:
    carlos@tabletbox:~$ ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
     inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
     inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
    2: enx1234a1234567: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
     link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
     inet 192.168.0.5/24 metric 100 brd 192.168.0.255 scope global enx1234a1234567
        valid_lft forever preferred_lft forever
     inet6 ffff::111:ffff:ffff:1111/64 scope link
        valid_lft forever preferred_lft forever
    3: wlp1s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
     link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff
    
  2. There are two files created by default under /etc/netplan during the server OS installation. One is for the wifi, the other one for the ethernet:
carlos@tabletbox:~$ ls /etc/netplan
00-installer-config-wifi.yaml  00-installer-config.yaml
  1. The wifi file is 00-installer-config-wifi.yaml. I opened it with sudo nano and commented every line:
carlos@tabletbox:~$ sudo cat /etc/netplan/00-installer-config-wifi.yaml
# This is the network config written by 'subiquity'
#network:
#  version: 2
#  wifis:
#    wlp1s0:
#      access-points:
#        my-wifi-ssid:
#          password: my-password
#      dhcp4: true
  1. There is no file describing the ethernet connection since I plugged it in after installing the OS. The configuration should go in the other file, 00-installer-config.yaml, which originally looked like this:
carlos@tabletbox:~$ sudo cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  version: 2
  1. I edited that file using sudo nano so that it configured the ethernet connection with dhcp on boot:
carlos@tabletbox:~$ sudo cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    enx1234a1234567:
      dhcp4: true
  version: 2
  1. Then I ran two commands as sudo: netplan generate and netplan apply. If it all goes well, these commands should show no output.

  2. Then I disabled the wifi connection using sudo ifconfig wlp1s0 down.

  3. Finally, I confirmed the ethernet connection had a proper IP, and that the wifi connection is not enabled:

carlos@tabletbox:~$ ifconfig
enx1234a1234567: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.5  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 ffff::111:ffff:ffff:1111  prefixlen 64  scopeid 0x20<link>
        ether 00:11:22:33:44:55  txqueuelen 1000  (Ethernet)
        RX packets 71716  bytes 6652012 (6.6 MB)
        RX errors 71  dropped 0  overruns 0  frame 0
        TX packets 122180  bytes 164685467 (164.6 MB)
        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  (Local Loopback)
        RX packets 14290  bytes 5731069 (5.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14290  bytes 5731069 (5.7 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  1. If you want to make sure the ethernet connection and the wifi will remain that way permanently, reboot the machine, and re-run the ifconfig command to verify the output is the same.