Connect to Wi-Fi on Ubuntu via Command Line
Quick and simple, without installing anything. Connect to Wi-Fi using only the command line on Ubuntu.
Lately I have been using Ubuntu servers a bit more. In the past I have installed nmcli
for configuring Wi-Fi connections. For servers, I am usually going to set it and forget it. So rather than install something I would only need once, I will go straight to the configs. By the way, I recommend using a wired connection for servers. Especially in production environments. With that said, here are the instructions.
First, find out the name of the interface you need to configure.
1
sudo ifconfig # If it is not found, try `iwconfig`
You will see something like the output below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 8903 bytes 7904472 (7.9 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8903 bytes 7904472 (7.9 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: IEEE 802.11 ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=22 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:on
The name of the interface we need to update in the configs is wlp3s0
. Modify or create /etc/netplan/50-cloud-init.yaml
. You should end up with something like the following config. Change wlp3s0
as needed. If the wifis
section does not exist already, just copy and past it somewhere in the network
section. Keep in mind this is a YAML file which requires correct indentation.
1
2
3
4
5
6
7
8
9
10
network:
version: 2
wifis:
wlp3s0:
dhcp4: true
access-points:
"jasonrav_wifi_essid":
auth:
key-management: "psk"
password: "Bosco"
Apply the new netplan config.
1
sudo netplan apply
For troubleshooting, try using this.
1
sudo netplan --debug apply