What’s the worst thing that can happen when you install a new Linux distribution on your system? I think it’s staring at the cursor on the command line and not knowing what to do next!!
This happened when I installed Debian on my system recently. After installing it all I got was a command line. And even if I wanted to install something or search something, I needed an internet connection. I have a wifi connection at home so I had to connect to WPA/WPA2 wifi using just a command line.
Now how would you do that?
We will find out the name of your wireless adapter.
This will generate an output like this:
channel 6 (2437 MHz), width: 40 MHz, center1: 2447 Mhz
From this, you can understand that your device name is wlan0. Type managed means the device is a WiFi station or client that connects to an access point. You will get Interface index as per connected ports.
Check if the wireless device wlan0 is up.
Run the following command:
ip link show wlan0
and in the output check, if you can see UP. You mostly will get an output like this. As you can see there’s no UP in those brackets.
If your wireless device is not up, execute this command to bring it up.
sudo ip link set wlan0 up
and you can verify if it is up using the command from step 2.
ip link show wlan0
which should give you and output like this:
As you can see now the wireless device is UP.
Now let’s check if you are connected to any network
/sbin/iw wlan0 link
This means that you are not connected to any network as of now. First, we will have to see what all networks are available. To do that execute the following command.
sudo /sbin/iw wlan0 scan
This will list out all the available networks for you. You will see something like this:
beacon interval: 100 TUs
Information elements from Probe Response frame:
Supported rates: 1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0
Extended supported rates: 24.0 36.0 48.0 54.0
RSN: * Version: 1
* Group cipher: CCMP
* Pairwise ciphers: CCMP
* Authentication suites: PSK
* Capabilities: 1-PTKSA-RC 1-GTKSA-RC (0x0000)
WPS: * Version: 1.0There are two things to look out here.
2. Security Protocol
RSN i.e. WPA2
Now let’s connect to your network.
Execute the following command:
sudo su wpa_passphrase Manish >> /etc/wpa_supplicant.conf <enter your wifi password> cat /etc/wpa_supplicant.conf
wpa_passphrase will create necessary configuration entries based on your input. Now to connect to your network execute the following command:
wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
-B means run wpa_supplicant in the background.
-D specifies the wireless driver. wext is the generic driver
-c specifies the path for the configuration file.
execute this of you are connected to the network you selected
/sbin/iw wlan0 link
Output will be
RX: 11068520 bytes (58070 packets)
TX: 1355722 bytes (7569 packets)
signal: -36 dBm
tx bitrate: 150.0 MBit/s MCS 7 40MHz short GIbss flags: short-preamble short-slot-time
dtim period: 0
beacon int: 100
Obtain IP address:
sudo dhclient wlan0
verify if IP address was set
ip addr show wlan0
link/ether 4c:bb:58:41:ac:45 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.105/24 brd 192.168.0.255 scope global dynamic wlan0
valid_lft 7086sec preferred_lft 7086sec
inet6 fe80::4ebb:58ff:fe41:ac45/64 scope link
valid_lft forever preferred_lft forever
To add a default routeing rule to pass all other traffic through wlan0 execute the following command:
sudo ip route add default via 192.168.0.105 dev wlan0
Now we can check if we can access the internet using a simple ping command.
64 bytes from 220.127.116.11: icmp_seq=1 ttl=59 time=6.91 ms
64 bytes from 18.104.22.168: icmp_seq=2 ttl=59 time=7.17 ms
64 bytes from 22.214.171.124: icmp_seq=3 ttl=59 time=7.40 ms
64 bytes from 126.96.36.199: icmp_seq=4 ttl=59 time=6.72 ms
64 bytes from 188.8.131.52: icmp_seq=5 ttl=59 time=7.99 ms
64 bytes from 184.108.40.206: icmp_seq=6 ttl=59 time=6.89 ms
64 bytes from 220.127.116.11: icmp_seq=7 ttl=59 time=6.86 ms
— 18.104.22.168 ping statistics —
7 packets transmitted, 7 received, 0% packet loss, time 6010ms
rtt min/avg/max/mdev = 6.725/7.137/7.996/0.419 ms