1.切换到超级用户
[root@centos-servce ~]# su root
2.查询可用的无线网卡,其中红色为网卡号
[root@centos-servce ~]# iw dev
phy#0
Interface wls1
ifindex 2
wdev 0x1
addr 00:26:c6:c8:a1:96
type managed
channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz
注意,如果成功连接网络的话,应该是下面这样子的, ssid就是广播信道名称,也就是你的无线网络信号呀,广播信道就是最后一个
[root@centos-servce ~]# iw dev
phy#0
Interface wls1
ifindex 2
wdev 0x1
addr 00:26:c6:c8:a1:96
type managed
channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz
3.启用无线卡
[root@centos-servce ~]# ip link set wls1 up
4.查看无线网卡连接情况
[root@centos-servce ~]# iw wls1 link
Not connected. (表示没有任何连接)
(以下连接成功)
Connected to 2e:f0:a2:c7:2a:aa (on wls1)
SSID: iPhone 8
freq: 2437
RX: 1349315 bytes (12110 packets)
TX: 21864 bytes (169 packets)
signal: -38 dBm
tx bitrate: 65.0 MBit/s MCS 7
bss flags: short-slot-time
dtim period: 3
beacon int: 100
5.查看所有可用的无线网络信号
[root@centos-servce ~]# iw wls1 scan | grep SSID
SSID: iPhone 8
SSID: MERCURY_2.4G
SSID: 201
SSID: Loading
SSID: CU_Bonnie
SSID: TP-LINK e5532
SSID: clarence
SSID: lanwifi
SSID: ATAJ
SSID: 601\xe6\x97\xa0\xe7\xba\xbf
SSID: TP-LINK_DD21
SSID: TP-LINK_B429
SSID: aduhome
SSID: DYJ652
SSID: Tenda_582B78
SSID: xiaozhuzhijia
SSID: xymx-9-m
SSID: liuruiA-thena
SSID: Bonnie
SSID: TAT
SSID: CU_IbAZ
SSID: ATAJ
SSID: Bonnie_5G
6.连接无线网
[root@centos-servce ~]# wpa_supplicant -B -i wls1 -c <(wpa_passphrase "iPhone 8" "1234567890")
Successfully initialized wpa_supplicant
注意:其中iPhone 8为要连接到的wifi信号SSID,1234567890为无线网络的密码,请读者替换即可。
7.分配IP地址(通过dhclient控制网卡进行网络操作获取IP)
[root@centos-servce ~]# dhclient wls1
8.查看无线网卡地址信息,有ip地址表示网络连接成功了,可以上网冲浪咯
[root@centos-servce ~]# ip addr show wls1
2: wls1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether 00:26:c6:c8:a1:96 brd ff:ff:ff:ff:ff:ff
inet 172.20.10.4/28 brd 172.20.10.15 scope global dynamic wls1
valid_lft 84511sec preferred_lft 84511sec
inet6 fe80::226:c6ff:fec8:a196/64 scope link
valid_lft forever preferred_lft forever