Connect to Wi-Fi
Even though I prefer physical connection, even on a laptop, and I plug in an Ethernet cable whenever I can, it is sometimes necessary to use WiFi. This requires remembering a few commands on OpenBSD.
Figure out network interface name
OpenBSD offers support for various network cards. It used to be way worse, but now I would say it's pretty uncommon to find a wireless card that doesn't work at all, however, features might differ from driver to driver.
First, we need to get the name of our wireless interface. To do so, run ifconfig
:
$ ifconfig
In the output, look for one of these interface names (list of possible wireless interfaces in OpenBSD, the name differs based on the wireless driver that handles the Wi-Fi card). Other clues that it's a wireless interface include wlan
, 802.11
etc.
iwn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:11:22:33:44:55
index 2 priority 4 llprio 3
groups: wlan
media: IEEE802.11 autoselect
status: no network
ieee80211: nwid ""
In my case, the interface name is iwn0
.
Up the interface
Before we can start scanning or connecting to networks, we need to make sure the wireless interface is UP
. Replace iwn0
with the name of your interface.
$ doas ifconfig iwn0 up
Scan for Wi-Fi networks
Basically all operating systems allow you to view all available wireless networks around you in some way. Usually in a form of a list that appears after you turn on Wi-Fi access. It's basically the same on OpenBSD, it just took me a bit longer to figure out since OpenBSD won't give you shiny buttons, but a simple (and powerful!) terminal.
$ ifconfig iwn0 scan
Which will give you the aforementioned list:
iwn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
lladdr 00:11:22:33:44:55
index 2 priority 4 llprio 3
groups: wlan
media: IEEE802.11 autoselect
status: no network
ieee80211: nwid ""
nwid MyWiFi chan 11 bssid 55:44:33:22:55:66 -49dBm HT-MCS15 privacy,short_preamble,short_slottime,wpa2
nwid AnotherNetwork chan 112 bssid 88:00:11:99:55:33 -58dBm HT-MCS15 privacy,short_preamble,short_slottime,wpa2
nwid TP-Link chan 7 bssid 99:55:11:11:11:11 -91dBm HT-MCS15 privacy,short_slottime,radio_measurement
...
...
Connect to a Wifi Network
Choose your desired network from the list generated by ifconfig iwn0 scan
and run:
$ doas ifconfig iwn0 nwid "MyWiFi" wpakey MySuperSecretPassword
iwn0
– Name of the interfaceMyWifi
– Name of your Wi-Fi networkMySuperSecretPassword
– password for your network, omitwpakey
if the network is open
You should now be connected, but you most likely won't be able to ping anything yet.
$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
ping: sendmsg: No route to host
ping wrote 8.8.8.8 64 chars, ret=-1
That is because you haven't asked for a DHCP lease yet.
Get IP from DHCP server
This option assumes you want a DHCP address, not a static one. To get the address from DHCP, simply run dhclient
on your Wi-Fi interface.
$ doas dhclient iwn0
iwn0: 192.168.1.58 lease accepted from 192.168.1.1 (11:11:11:11:11:11)
Success! You are now connected to a Wi-Fi network with a valid IP address. There's, however, way more to discover and learn – auto connecting, configuration files so you don't have to remember all the commands etc. This guide was mainly designed to show you how to connect to a wireless network one-off.