Linux commands to connect to WiFi

1. Access network card

Connect a USB wireless network card to the Linux host (not a drive-free network card needs to install the driver)

2. Find available network cards

iw dev

where wlan0 is the network card name

phy#0
	Interface wlan0
		ifindex 9
		wdev 0x1
		addr d4:83:04:38:89:5c
		type managed
		txpower 12.00 dBm

3. Find available networks

sudo iw wlan0 scan |grep SSID
	SSID: CMCC-2.4-5G
	SSID: TP-LINK_301
	SSID: IPCS5C24602785220
	SSID: CMCC-501
	SSID: CMCC-Yfbj

The SSID is followed by the network name

4. Add network information

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

Fill in the following content

network={
    
    
    ssid="WiFi名称"
    psk="密码"
}

5. Start wpa_supplicant for authentication

sudo wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B

6. Obtain IP address

sudo dhclient wlp2s0

After iw devthat, if there is SSID information, it means that it is connected to the network, and you can use to ifconfigview the IP address

7. Disconnect from the network

dhclient -r wlan0

Guess you like

Origin blog.csdn.net/weixin_50497501/article/details/131657215