wifi

In this blog, we assume that you want to connect your laptop (having a WLAN interface) to your local wifi in command-line without using the Linux Network Manager shown below

network-manager

First, find what wifi device you have on your machine using iw command.

iw dev

Example:

ziadi@linuxnix:~$ iw dev
phy#0
Interface wlan0
ifindex 3
wdev 0x1
addr 68:17:29:62:83:ec
type managed
channel 4 (2427 MHz), width: 20 MHz, center1: 2427 MHz

Configuring wifi though CLI on Ubuntu Linux

To do that, you must modify the file /etc/network/interfaces in Linux Ubuntu

/etc/network/interfaces: this file describes the network interfaces available on your system and how to activate them.

Edit that file as root or sudo permissions:

user@server: ~$ sudo vi /etc/network/interfaces

Search for the WLAN interface and add/modify like below:

# The loopback network interface
auto lo
iface lo inet loopback

[...]

auto wlan0
iface wlan0 inet dhcp
wpa-ssid YOUR_WIFI_NAME
wpa-psk YOUR_WIFI_PASSWORD

[...]

Now, restart the networking service:

user@server: ~$ sudo service networking restart

[....] Running /etc/init.d/networking restart is deprecated because it may not re-enable some interfac[warn. (warning).
[....] Reconfiguring network interfaces...Internet Systems Consortium DHCP Client 4.2.2
Copyright 2004-2011 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/00:21:5d:7d:18:68
Sending on LPF/wlan0/00:21:5d:7d:18:68
Sending on Socket/fallback
DHCPRELEASE on wlan0 to 192.168.1.1 port 67
Reloading /etc/samba/smb.conf: smbd only.
Internet Systems Consortium DHCP Client 4.2.2
Copyright 2004-2011 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/00:21:5d:7d:18:68
Sending on LPF/wlan0/00:21:5d:7d:18:68
Sending on Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPOFFER from 192.168.0.254
DHCPACK from 192.168.0.254
Reloading /etc/samba/smb.conf: smbd only.
bound to 192.168.0.11 -- renewal in 330251 seconds.
done.

Configuring wifi though CLI on Redhat Linux

Check that your WLAN interface obtained an IP

user@server: ~$ sudo ifconfig wlan0

wlan0 Link encap:Ethernet HWaddr 00:21:5d:7d:18:68
inet adr:192.168.0.11 Bcast:192.168.0.255 Masque:255.255.255.0
adr inet6: 2a01:e35:8bd7:3020:221:5dff:fe7d:1868/64 Scope:Global
adr inet6: fe80::221:5dff:fe7d:1868/64 Scope:Lien
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:952199 errors:0 dropped:0 overruns:0 frame:0
TX packets:510113 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1000
RX bytes:1050900199 (1002.2 MiB) TX bytes:106792007 (101.8 MiB)

Test your connectivity to the internet by pinging an external website

user@server: ~$ ping google.com
PING google.com (216.58.213.174) 56(84) bytes of data.
64 bytes from par21s04-in-f14.1e100.net (216.58.213.174): icmp_seq=1 ttl=53 time=6.95 ms
64 bytes from par21s04-in-f14.1e100.net (216.58.213.174): icmp_seq=2 ttl=53 time=6.60 ms
64 bytes from par21s04-in-f14.1e100.net (216.58.213.174): icmp_seq=3 ttl=53 time=6.59 ms
64 bytes from par21s04-in-f14.1e100.net (216.58.213.174): icmp_seq=4 ttl=53 time=6.56 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 6.568/6.681/6.957/0.188 ms

I hope that this blog helped you. Please visit our website for other interesting blogs and feel free to leave your feedbacks and thoughts. Till next time!