Recently, I wanted to create a server for an IoT project I am working on. After finding a old computer and loading it with Ubuntu Server 20.04, it took me hours to get the server hooked up. Below is a quick step by step guide to connecting to your server to WiFi to save you some time and trouble.
1. Find Your Wireless Network Interface
Run the following command
awaldron@xtrarepserver:/$ ls /sys/class/net eno1 lo wlo1
Some common interfaces wlan0, wlp3s0, and wlo1. If one of the outputs starts with a 'w' you'll be ight.
2. Locate Configuration Files
awaldron@xtrarepserver:/$ ls /etc/netplan 00-installer-config.yaml
If a file with extension *.yaml is printed, BINGO! That's your configuration file. Another common one is 50-cloud-init.yaml
3. Edit Configuration File
After you located your file, it's time to throw your Internet info in there. Open the file with nano using the following command.
awaldron@xtrarepserver:/$ sudo nano /etc/netplan/00-installer-config.yaml
Replace 00-installer-config.yaml with the file name you got from the previous step. You should see something like this:
#This is the network config written by 'subiquity' network: ethernets: eno1: dhcp4: true version: 2
Yaml files are super annoying with indentation so make sure to use 2 or 4 spaces (depending how what the file is already using) when you go to input your WiFi Info. On the same indentation as "ethernets" (for me it was two spaces in), input the following information:
wifis: wlo1: dhcp4: true optional: true access-points: "YOUR SSID": password: "YOUR PASSWORD"
Make sure you replace "wlo1" with whatever network interface you got from step 1 and replace YOUR SSID with your WiFi name and YOUR PASSWORD with your WiFi password. Your final yaml file should look something like this:
#This is the network config written by 'subiquity' network: ethernets: eno1: dhcp4: true version: 2 wifis: wlo1: dhcp4: true optional: true access-points: "YOUR SSID": password: "YOUR PASSWORD"
Once your done editing save the file by pressing the ctrl key and "O" key at the same time and exit by pressing the ctrl key and "X" key,
4. Connect To WiFi
The moment we have all been waiting for! First we want to make sure your WiFi network interface is up and running with the following command:
awaldron@xtrarepserver:/$ sudo ip link set wlo1 up
Replace wlo1 with the output from step 1. Then run:
awaldron@xtrarepserver:/$ sudo netplan --debug apply
And for the moment of truth, run the following command to see if your are finally connected:
awaldron@xtrarepserver:/$ ping www.google.com
Let it run for a second and end it by press ctrl+c. You should receive an output like the one below if all was successful:
6 packets transmitted, 6 received, 0% packet loss, time 5010ms
Your numbers will more than likely be different but if your packet loss is 0%, CONGRATS!! You have successfully connected to the internet using the command line. For more Ubuntu and other tech tips, subscribe below!