If you have configured a couple of Wireless connections at home or work on your Laptop and each of the remote Wi-FI access points are at different distance (some APs are situated at closer range than others) and your Linux OS keeps connecting sometimes to the wrong AP by default you'll perhaps want to change that behavior, so you keep connected to the Wi-Fi AP that has the best Link Quality (is situatated physically at closest location to your laptop integrated wifi card).
Using a Graphical tool such as Gnome Network Manager / Wicd Network Manager or KDE's Network Manager is great and easy way to do it but sometimes if you do upgrade of your GNU / Linux and the upgrade fails and your Graphical Environment GNOME / KDE / OpenBox / Window Maker or whatever Window Manager you use fails to start it is super handy to use text console (terminal) to connect to the right wiki in order to do a deb / rpm package rollback to revert your GUI environment or Xorg to the older working release.
Connection to WPA or WEP protected APs on GNU / Linux on a low level is done by /sbin/iwlist , /sbin/iwconfig and wpa_supplicant
wpasupplicant and network-manager (if you're running Xorg server).
/sbin/iwlist scan
wlp3s0 Scan completed :
Cell 01 – Address: 10:FE:ED:43:CB:0E
Channel:6
Frequency:2.437 GHz (Channel 6)
Quality=64/70 Signal level=-46 dBm
Encryption key:on
ESSID:"Magdanoz"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s
Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=00000032cff7c214
Extra: Last beacon: 144ms ago
IE: Unknown: 00084D616764616E6F7A
IE: Unknown: 010882848B960C121824
IE: Unknown: 030106
IE: Unknown: 0706555320010B1B
IE: Unknown: 2A0100
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : CCMP TKIP
Authentication Suites (1) : PSK
IE: Unknown: 32043048606C
iwlist command is used to get more detailed wireless info from a wireless interface (in terminal this command shows you the wifi networks available to connect to and various info such as the type of Wifi network the Wifi Name / network quality Frequency (is it it spreading the wifi signal at 2.4 Ghz or 5 Ghz frequency) etc.
# ifconfig interafce_name down
For example on my Thinkpad the wifi interface is wlp3s0 to check what is yours do ifconfig -a e.g.
root@jeremiah:~# /sbin/ifconfig -a
enp0s25: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 00:21:cc:cc:b2:27 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xf3900000-f3920000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 350 bytes 28408 (27.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 350 bytes 28408 (27.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.103 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::6267:20ff:fe3c:20ec prefixlen 64 scopeid 0x20<link>
ether 60:67:20:3c:20:ec txqueuelen 1000 (Ethernet)
RX packets 299735 bytes 362561115 (345.7 MiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 278518 bytes 96996135 (92.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Next use iwconfig on Debian / Ubuntu Linux it is part of wireless-tools deb package.
root@jeremiah:~# /sbin/iwconfig interface essid "Your-Acess-Point-name"
To check whether you're connected to a wireless network you can do:
root@jeremiah:~# iwconfig
enp0s25 no wireless extensions.
lo no wireless extensions.
wlp3s0 IEEE 802.11 ESSID:"Magdanoz"
Mode:Managed Frequency:2.437 GHz Access Point: 10:FE:ED:43:CB:0E
Bit Rate=150 Mb/s Tx-Power=15 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=61/70 Signal level=-49 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:5 Invalid misc:1803 Missed beacon:0
N.B. ! To get a list of all your PC network interfaces you can use cmd:
root@jeremiah:/home/hipo# ls -al /sys/class/net/
total 0
drwxr-xr-x 2 root root 0 Oct 8 22:53 .
drwxr-xr-x 52 root root 0 Oct 8 22:53 ..
lrwxrwxrwx 1 root root 0 Oct 8 22:53 enp0s25 -> ../../devices/pci0000:00/0000:00:19.0/net/enp0s25
lrwxrwxrwx 1 root root 0 Oct 8 22:53 lo -> ../../devices/virtual/net/lo
lrwxrwxrwx 1 root root 0 Oct 8 22:53 wlp3s0 -> ../../devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlp3s0
or use netstat like so:
root@jeremiah:/home/hipo# netstat -i | column -t
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
enp0s25 1500 0 0 0 0 0 0 0 0 BMU
lo 65536 590 0 0 0 590 0 0 0 LRU
wlp3s0 1500 428112 0 1 0 423538 0 0 0 BMRU
To get only the Wireless network card interface on Linux (e.g. find out which of the listed above interfaces is your wireless adapter's name), use iw command (that shows devices and their configuration):
root@jeremiah:/home/hipo# iw dev
phy#0
Interface wlp3s0
ifindex 3
wdev 0x1
addr 60:67:20:3c:20:ec
type managed
channel 6 (2437 MHz), width: 40 MHz, center1: 2427 MHz
txpower 15.00 dBm
- If you need to get only the active Wireless adapter device assigned by Linux kernel
root@jeremiah:~# iw dev | awk '$1=="Interface"{print $2}'
To check the IP / Netmask and Broadcase address assigned by connected Access Point use ifconfig
with your Laptop Wireless Interface Name.
root@jeremiah:~# /sbin/ifconfig wlp3s0
wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.103 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::6267:20ff:fe3c:20ec prefixlen 64 scopeid 0x20<link>
ether 60:67:20:3c:20:ec txqueuelen 1000 (Ethernet)
RX packets 319534 bytes 365527097 (348.5 MiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 285464 bytes 99082701 (94.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
As you can see in above 3 examples iwconfig could configure various settings regarding the wireless network interface.
It is really annoying because sometimes if you have configured your Linux to connect to multiple access points, the wifi adapter might keep connecting to an access point that is more distanced from you and because of that the Bandwidth might be slower and that could impact your Internet connectivity, to fix that and get rid of any networks that are automatically set to connect to that you don't want to, just delete the correspodning files (the Wifi file name coincides with the Wireless AP network name).
All stored Wi-FI access points that your Linux is configured to connect to are stored inside /etc/NetworkManager/system-connections/
For example to delete an auto connection to wireless router with a name NetGear do:
root@jeremiah:~# rm -f /etc/NetworkManager/system-connections/NetGear
For a complete list of stored Wifi Networks that your PC might connect (and authorize to if configured so) do:
root@jeremiah:~# ls -a /etc/NetworkManager/system-connections/
Magdanoz
NetGear
LinkSys
Cobra
NetIs
WirelessNet
…
After deleting the required Networks you want your computer to not automatically connect to to make NetworkManager aware of that restart it with:
hipo@jeremiah:~# systemctl restart NetworkManager.service
or if you hate systemd like I do just use the good old init script to restart:
hipo@jeremiah:~# /etc/init.d/network-manager restart
To get some more informatoin on the exact network you're connected, you can run:
hipo@jeremiah:~# systemctl status NetworkManager.service
● NetworkManager.service – Network Manager
Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-10-08 22:35:09 EEST; 15s ago
Docs: man:NetworkManager(8)
Main PID: 13721 (NetworkManager)
Tasks: 5 (limit: 4915)
CGroup: /system.slice/NetworkManager.service
├─13721 /usr/sbin/NetworkManager –no-daemon
└─13742 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /var/run/dhclient-wlp3s0.pid -lf /var/lib/NetworkManager/dhclie
Oct 08 22:35:15 jeremiah NetworkManager[13721]:
[1539027315.6657] dhcp4 (wlp3s0): state changed unknown -> bound
Oct 08 22:35:15 jeremiah dhclient[13742]: bound to 192.168.0.103 — renewal in 2951 seconds.
Oct 08 22:35:15 jeremiah NetworkManager[13721]:[1539027315.6735] device (wlp3s0): state change: ip-config -> ip-check (reason 'none') [70 80
Oct 08 22:35:15 jeremiah NetworkManager[13721]:[1539027315.6744] device (wlp3s0): state change: ip-check -> secondaries (reason 'none') [80 9
Oct 08 22:35:15 jeremiah NetworkManager[13721]:[1539027315.6747] device (wlp3s0): state change: secondaries -> activated (reason 'none') [90
Oct 08 22:35:15 jeremiah NetworkManager[13721]:[1539027315.6749] manager: NetworkManager state is now CONNECTED_LOCAL
Oct 08 22:35:15 jeremiah NetworkManager[13721]:[1539027315.6812] manager: NetworkManager state is now CONNECTED_GLOBAL
Oct 08 22:35:15 jeremiah NetworkManager[13721]:[1539027315.6813] policy: set 'Magdanoz' (wlp3s0) as default for IPv4 routing and DNS
Oct 08 22:35:15 jeremiah NetworkManager[13721]:[1539027315.6816] device (wlp3s0): Activation: successful, device activated.
Oct 08 22:35:15 jeremiah NetworkManager[13721]:[1539027315.6823] manager: startup complete