1.安装wpa_supplicant:
yum install -y wpa_supplicant
2.然后找到我们路由的 ESSID,比如我是 MERCURY_702,明码是:12345678,然后生成密码配置文件
wpa_passphrase long 'my password'
它会输出如下内容
[root@localhost ~]# wpa_passphrase MERCURY_702 '12345678'
network={
ssid="MERCURY_702"
#psk="12345678"
psk=5876babab26046b9f60c5c2764b2cbf7df5a1b4e1ecaaf043f3a42b6788f40cf
}
执行以下命令,将输出的内容追加到文件:
wpa_passphrase MERCURY_702 '12345678'>> /etc/wpa_supplicant/wpa_supplicant.conf
3.再把其中 ssid= 和 psk= 加入到wlan0 的配置文件,或执行一下命令
wpa_passphrase MERCURY_702 '12345678' | grep -v '{\|}' >> /etc/sysconfig/network-scripts/ifcfg-wlan0
echo 'WPA=yes' >> /etc/sysconfig/network-scripts/ifcfg-wlan0
4.现在我的配置文件内容如下:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-wlan0
DEVICE=wlan0
HWADDR=00:24:2C:AB:F9:49
TYPE=Wireless
UUID=a91e5374-4001-449b-b961-d4a93e16399c
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.139
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ssid="MERCURY_702"
#psk="12345678"
psk=ba11cfc198536df4a47bdb21b23a003efc57509fa110c78ebbbb98c6c2a9af36
WPA=yes
5.然后启动无线网络:
ifup wlan0
wpa_supplicant -iwlan0 -B -c /etc/wpa_supplicant/wpa_supplicant.conf
6.我们需要随机启动的话,加入到 /etc/rc.local,命令行执行:
cat >> /etc/rc.local<<EOF
wpa_supplicant -iwlan0 -B -c /etc/wpa_supplicant/wpa_supplicant.conf
EOF