Ubuntu Server 22.04 WiFi only, headless

Using single fixed IPv4 and IPv6 addresses with netplan and,

how to change WiFi adaptors over the WiFi

This came about through a need to set up a pair of outdoor speakers to play sound recordings of nesting swifts to try to attract birds looking for a new nest site. It was not possible to conveniently run cabling to where I needed to site the mini amplifier so it had to be done with a spare industrial type mini ITX board and WiFi.

During installation using a keyboard and monitor with a very cheap little WiFi adaptor, the Server 22.04 installer detects what I call the adaptor ID which for USB WiFi adaptors always seems to start with wlx followed by twelve more alphanumeric characters. It uses this along with the requested WiFi network SSID and passcode to build a yaml file in /etc/netplan/

I was experimenting with the format of the yaml file at the same time as I was Google searching answers to questions and responding to file format warnings so didn't keep notes at the time but this is the working configuration I ended up with:-

# This is the network config written by 'subiquity'
network:
  version: 2
  wifis:
    wlxAdaptorID:
      access-points:
        YourWiFiSSID:
          password: YourWiFiPasscode
      accept-ra: no
      dhcp4: no
      dhcp6: no
      addresses:
        - 192.168.x.y/24
        - Your:Fixed:IPv6::y/64
      routes:
        - to: default
          via: 192.168.x.1
        - to: default
          via: Your:Fixed:IPv6::1
      nameservers:
        addresses:
          - 208.67.222.222
          - 208.67.220.220
          - 8.8.8.8
          - 2620:119:35::35
          - 2620:119:53::53
assuming that, under routes: the router address 192.168.something.1. The file name will be something like 00-installer-config-wifi.yaml. There was also another yaml file for the on board Ethernet socket which I disabled by adding .hide to the end of the file name.

I am no expert at all on this stuff, but as far as I know the
accept-ra: no
line prevents the kernel from automatically generating an IPv6 address for the interface so that I can specify my own static address which can then be referenced in my DNS settings. I also disable DHCP so that I can specify my own choice of name servers.

Now, how to change WiFi adaptors without messing up and locking yourself out of your server!

The very cheap adaptor (about £5.00 posted from China) I first used really didn't have enough signal strength to reliably reach maybe six metres through internal walls and a floor. You can't just pull it out and replace it with another because the adaptor ID then won't match the ID in the yaml file and there will be no connection.

The solution

Take your alternative adaptor and plug it into any other Linux computer and use the command
ls /sys/class/net
which will give you the wlx ID of the adaptor. Then, ssh into your server, make sure you are admin and do
cd /etc/netplan/
then make a copy of your working yaml file
sudo cp 00-installer-config-wifi.yaml 01-installer-config-wifi.yaml
and edit the copy with the ID of the new adaptor. That's it!

Now, tell the server to reboot itself in a few minutes
sudo shutdown -r HH:MM
giving yourself time to go to the server and swap in the new adaptor before it does so. You shouid then be able to ssh in again over the WiFi and the new adaptor.

If you should happen to find this page and it is of use to you please email me using hswf at my domain thefletchers.net.