Connecting to Wi-Fi networks
Connection to Wi-Fi networks on OpenBSD.
258 Words, 2 Minutes
09 Mar 2024
Wi-Fi configuration
To connect to and remember Wi-Fi networks on OpenBSD, a simple configuration is needed.
Tested on OpenBSD 7.4.
Identifying the network interface
The configuration has to be done for the right network interface. The naming convention of the network interfaces is different from Linux, and it depends on the driver. The following command should identify the wireless network interface:
$ dmesg | egrep -i '(wireless)|(^(acx|an|athn?|atu|atw|bwfm|bwi|ipw|iwim?|iwn|iwx|malo|mtw|otus|pgt|qww|ral|rsu|rtwn?|rum|run|uath|upgt|ural|urtwn?|wi|wpi|zyd)\d+( |:))'
The output could be similar to this:
iwm0 at pci2 dev 0 function 0 "Intel Dual Band Wireless-AC 1234" rev 0x42
Here, iwm0 is the network interface name. It should be confirmed by ifconfig iwm0.
Adding the network to the configuration file
To connect to a Wi-Fi network, the network interface has to be configured.
Edit the file /etc/hostname.if, .if being replaced by the name of the network interface. Example: /etc/hostname.iwm0
join 'home' wpakey 'your-Random-P4ssw0rd!-Her3.' join 'work' wpakey 'your-otHer--Pa55w0rd!-Her3' join 'Moe-tavern' wpakey 'M4rge_51mp5on-<3' inet autoconf
The join instruction is better than nwid, since it allows to connect to one of several networks.
The inet autoconf is to use DHCP to get an IP address. It must be the last line of the file.
Note: the single quotes around the network name and the network password aren't mandatory, except if you have a special characters like $ or <space> inside. So, it's better to always use them.
Finally, restart the network service with the following command:
# sh /etc/netstart