CentOS命令行连接带密码的wifi

  • 安装工具包 yum install -y wpa_supplicant
  • 确定我们要连接的wifi的名称和密码,名称为ESSID。这里假设wifi名称为TPLINK,假设密码为password,下面请注意。
  • 把以上信息写入/etc/wpa_supplicant/wpa_supplicant.conf : wpa_passphrase TPLINK 'password' >> /etc/wpa_supplicant/wpa_supplicant.conf
  • 把ESSID和PSK写入/etc/sysconfig/network-scripts/ifcfg-wlan0:

    wpa_passphrase TPLINK 'password' | grep -v '{\|}' >> /etc/sysconfig/network-scripts/ifcfg-wlan0

    echo 'WPA=yes' >> /etc/sysconfig/network-scripts/ifcfg-wlan0

  • 改好以后我的配置文件内容为:

DEVICE=wlan0

HWADDR=9C:4E:36:9A:64:10

TYPE=Wireless

UUID=f017bd9c-eebf-46fc-823c-7f76cc8d5abf

ONBOOT=no

NM_CONTROLLED=yes

BOOTPROTO=dhcp

ESSID="TPLINK"

PSK=e79bfcc384c1331c82738473e0f938df827fc8b11a

  • 后台运行wpa_supplicant进程:wpa_supplicant -B -c /etc/wpa_supplicant/wpa_supplicant.conf
  • 查找周围的无线网络: iwlist wlan0 scan | grep ESSID
  • 连接无线网络:iwconfig wlan0 essid "TPLINK"
  • DHCP方式获取ip:dhclient wlan0
  • 测试是否联通:ping www.baidu.com

你可能感兴趣的:(centos)