CentOS7使用无线WiFi连接并设置为开机启动

1.使用wpa_supplicant联网
1.1查看无线网卡名称

[root@localhost ~]# ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp5s0:  mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 1c:83:41:26:b4:52 brd ff:ff:ff:ff:ff:ff
3: enp6s0:  mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 1c:83:41:26:b4:53 brd ff:ff:ff:ff:ff:ff
4: wlp3s0:  mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether b4:69:21:8f:de:50 brd ff:ff:ff:ff:ff:ff
    inet 192.168.40.78/24 brd 192.168.40.255 scope global noprefixroute dynamic wlp3s0
       valid_lft 28644sec preferred_lft 28644sec
    inet6 fe80::8ff2:24eb:5e8f:333f/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

其中wlp3s0是我的无线网卡名称。
1.2将无线网口wlp3s0开启

ip link set wlp3s0 up

1.3显示无线网口wlp3s0连接情况

ip link show wlp3s0

1.4连接无线网ssid,密码psk

wpa_supplicant -B -i wlp3s0 -c <(wpa_passphrase "ssid" "psk")

1.5为wlp8s0自动分配ip地址

dhclient wlp3s0

2.设置NetworkManager自动启动
2.1由于上个方法操作结束重启机器后会出现以下问题(因此需安装使用NetworkManager-wifi):
㈠无线网卡没有启动
㈡启动后无法自动连接WiFi
㈢使用ip link set xxx up,wpa_xxx启动网卡连接WiFi后重新登陆无法自动启动连接WiFi
2.2设置NetworkManager自动启动

chkconfig NetworkManager on

2.3安装NetworkManager-wifi

yum -y install NetworkManager-wifi

2.4开启WiFi

nmcli r wifi on

2.5.测试(扫描信号)

nmcli dev wifi

2.6.连接(无线网ssid,密码psk)

nmcli d wifi connect "ssid" password "psk" wlp3s0

3.重启自动连接网络失败解决方案
3.1查看网络连接

[root@localhost ~]# nmcli connection 
NAME           UUID                                  TYPE      DEVICE 
mywifi1001  fa0e9356-5f66-410e-a1f0-4b44db624c7e  wifi      wlp3s0 
有线连接 1     260d53fc-3f54-38e5-9fdc-54bb99eb7134  ethernet  --     
有线连接 2     203fe47d-cb0e-3953-8786-b6f91ff7043c  ethernet  -- 

3.2依次删除全部无线连接

nmcli c delete  fa0e9356-5f66-410e-a1f0-4b44db624c7e

3.3重新连接(无线网ssid,密码psk)

nmcli d wifi connect "ssid" password "psk" wlp3s0
ifconfig可看到已连接上网

3.4重启验证

reboot后ifconfig可看到已连接上网

 

你可能感兴趣的:(linux)