There are various ways to connect to a network e.g. using GUI. A GUI lists all the available networks/ SSIDs and we just have to click, enter password(if the connection is secured) and done. The other ways to connect include
nmcli(a cli to control NetworkManager),
wpa_supplicant(a relatively low level tool).
wpa_supplicant is a cross platform free software implementation of an IEEE 802.11i supplicant. A supplicant is simply an entity at one end of a LAN. The other end of the LAN has an authenticator that authenticates a connection to it.
wpa_supplicant, we need to install wpa_supplicant(e.g. for arch linux,
pacman -S wpa_supplicant) which installs two more utilities with it i.e.
wpa_cli is the frontend tool of
wpa_supplicant while as
wpa_passphrase is used to create a configuration file which contains the network details e.g. the password.
Connecting to a network
Before following the steps below, make sure your network interface is
sudo ip link
UP in the output corresponding to your network interface(e.g.
- Scan SSIDs/ Networks:
iw scan wlan0
wlan0with your network interface(use
ip linkto find yours). Note down the SSID name from the above command.
iw scan wlan0 | grep SSIDwill return only SSIDs only which is what we require here.
- Create passphrase configuration:
wpa_passphrase myssid | sudo tee /etc/wpa_supplicant.conf, write the SSID password and press enter.
SSIDthat you want to connect to.
This will create a file
/etc/wpa_supplicant.conf. We will use this file in our
wpa_supplicantcommand to connect to our network.
sudois required with
teecommand because the file is being created in root owned directory. We can however create this file in any directory.
teesimply puts the output of
wpa_supplicantin the given
- Start wpa_supplicant daemon:
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
This says that start
wpa_supplicantin the background(
wlan0network interface and
/etc/wpa_supplicant.confas the configuration file. With an extra
Dflag, we can set the driver to be used e.g.
sudo wpa_supplicant -B -D nl80211 -i wlan0 -c /etc/wpa_supplicant.conf. This will use
nl80211driver rather than the default being picked.
At this point, you are connected but no ip address has been assigned. Use
iw wlan0 linkto confirm
- Obtain an ip address:
sudo dhclient wlan0.
You are now connected to the network. Use
pingcommand to confirm.