banner
xingli

xingli

猫娘爱好者

Linux Wi-Fi Tutorial

Connecting to WiFi on Linux#

I have reinstalled the Armbian system on my Phicomm N1 (TV box). The machine has a wireless network card but no desktop environment, so I can only control WiFi connection through the command line. Here, I will document the method for setting up WiFi.

Many network card drivers are not integrated and need to be installed by users themselves. The installation method is as follows (make sure the development board is connected to the network using an Ethernet cable):

apt update
apt install armbian-firmware-full

After executing the above two commands, restart the system:

reboot

After the restart, you will find that WiFi is available.

There are two solutions in total:

  1. Updating WiFi system configuration
  2. Connecting to WiFi using nmcli

Updating WiFi System Configuration#

  1. Update the /etc/network/interface file.
  2. Backup the interface file: cd /etc/network && cp interface interface.bak
  3. Update the interface file:
# armbian-config created
source /etc/network/interfaces.d/*

# Local loopback
auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
  1. Update the /etc/wpa_supplicant/wpa_supplicant.conf file.
  2. Backup the wpa configuration file: cd /etc/wpa_supplicant/ && cp wpa_supplicant.conf wpa_supplicant.conf.bak
  3. Update the wpa_supplicant.conf file:
network={
	ssid="Network ID"
	psk="Password"
}
  1. Restart the network and try pinging Baidu to check if it is connected. It should be able to connect successfully.

Connecting to WiFi using nmcli#

nmcli is a command-line tool used to control NetworkManager. It can also be used to display network device status, create, edit, enable/disable, and delete network connections. Armbian system comes with nmcli by default, so I won't explain the installation method here.

After connecting to WiFi directly using nmcli, the system will record the saved APs. Below are the specific connection methods:

  1. Check device status:
nmcli device status
DEVICE  TYPE      STATE         CONNECTION
enp1s0  ethernet  connected     Wired connection 1
wlp2s0  wifi      disconnected  --
lo      loopback  unmanaged     --

Here, the type of wlp2s0 is wifi, indicating our wireless network card, and the status is disconnected, indicating that it has not yet connected to a WiFi hotspot.

  1. Check radio:
nmcli radio
WIFI-HW  WIFI     WWAN-HW  WWAN
enabled  enabled  enabled  enabled
  1. View nearby wireless network signals:
nmcli dev wifi list
SSID                  MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
MYSSID         Infra  11    54 Mbit/s  100     ▂▄▆█  WPA2
MYSSID         Infra  132   54 Mbit/s  100     ▂▄▆█  WPA2
SOMEOTHERSSID  Infra  52    54 Mbit/s  49      ▂▄__  WPA2
MYSSID         Infra  149   54 Mbit/s  45      ▂▄__  WPA2
MYSSID         Infra  11    54 Mbit/s  42      ▂▄__  WPA2
SOMEOTHERSSID  Infra  1     54 Mbit/s  27      ▂___  WPA2

The fifth column represents the signal strength, and the better the signal of an AP, the higher it will be on the list.

  1. Connect to the AP hotspot:
  • For open WiFi networks, execute the following command, where SSID is the name of the WiFi:
nmcli device wifi connect <SSID|BSSID>
  • For encrypted APs, use the following command:
nmcli device wifi connect <SSID|BSSID> password <password>

After executing the command without any errors, ping Baidu to check if it is reachable. If you can ping successfully, it means that you have connected to the AP and can access the internet normally.

Armbian WiFi Configuration Tutorial - Zhihu (zhihu.com)

To modify the default route in Linux, you need to open the terminal and enter the following commands:

sudo route del default
sudo route add default gw [gateway IP address]

Where [gateway IP address] is the IP address of the gateway you want to add as the default route.

For example, if you want to set the default route to a router with the IP address 192.168.0.1, you can execute the following commands:

sudo route del default
sudo route add default gw 192.168.0.1

Please note that these changes will only take effect in your current session. If you want these changes to persist after restarting the computer, you need to add these commands to the startup script.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.