wifi--wpa_supplicant

本文详细介绍了在Linux系统中如何使用wpa_supplicant命令行工具连接到WPA/WPA2加密的WiFi网络,并通过dhclient获取IP地址。此外,还提供了设置WEP加密WiFi的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux命令行连接wifi--wpa_supplicant

https://wiki.gentoo.org/wiki/Handbook:AMD64/Networking/Wireless
CentOS7为例:
先启用无线网卡再扫描wifi信号
root@jlive:~#ip link set wlp3s0 up
root@jlive:~#iw dev wlp3s0 scan|grep wifi


A.WPA/WPA2加密
root@jlive:~# vim /etc/sysconfig/wpa_supplicant
network={
        ssid="wifi"
        psk="foo.123"
        priority=1
}
root@jlive:~# wpa_supplicant -i wlp3s0 -c /etc/sysconfig/wpa_supplicant
Successfully initialized wpa_supplicant
wlp3s0: Trying to associate with ec:26:ca:67:0b:fe (SSID='rukawa' freq=2437 MHz)
ioctl[SIOCSIWFREQ]: Device or resource busy
wlp3s0: Association request to the driver failed
wlp3s0: Associated with ec:26:ca:67:0b:fe
wlp3s0: WPA: Key negotiation completed with ec:26:ca:67:0b:fe [PTK=CCMP GTK=CCMP]
wlp3s0: CTRL-EVENT-CONNECTED - Connection to ec:26:ca:67:0b:fe completed [id=0 id_str=]
看到这个提示,应该感到非常兴奋,成功连接
root@jlive:~# ifconfig wlp3s0
wlp3s0: flags=4163  mtu 1500
        inet6 fe80::466d:57ff:feb3:a7e5  prefixlen 64  scopeid 0x20
        ether 44:6d:57:b3:a7:e5  txqueuelen 1000  (Ethernet)
        RX packets 2  bytes 282 (282.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10  bytes 1096 (1.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
再看下是否拿到IP,发现没有,所以还差一步,主动发起DHCP请求地址
root@jlive:~# dhclient wlp3s0
root@jlive:~# ifconfig wlp3s0
wlp3s0: flags=4163  mtu 1500
        inet 192.168.100.108  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::466d:57ff:feb3:a7e5  prefixlen 64  scopeid 0x20
        ether 44:6d:57:b3:a7:e5  txqueuelen 1000  (Ethernet)
        RX packets 2885  bytes 2092956 (1.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2708  bytes 488745 (477.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

B.wep加密
https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Networking

For most users, there are only two settings that might be important to change, the ESSID (aka wireless network name) or the WEP key. If the ESSID and Access Point address listed are already those of the environment's access point and the environment is not not using WEP, then the wireless configuration is already working.

To change the ESSID, or add a WEP key, issue the following commands.

  • To set the network name to GentooNode:
root # iwconfig eth0 essid GentooNode
  • To set a hex WEP key:
root # iwconfig eth0 key 1234123412341234abcd

To set an ASCII WEP key, prefix the key with s::

root # iwconfig eth0 key s:some-password
或者 
root #iwconfig eth0 key s:some-password
root@jlive:~# iw dev wlp3s0 connect "wifi名" key 0:密码
root@jlive:~# dhclient wlp3s0

转载于:https://www.cnblogs.com/lixuebin/p/10814413.html

### 替换 `wpa_supplicant-2.9` 为了将现有的 `wpa_supplicant-2.10` 版本替换为 `wpa_supplicant-2.9`,需要遵循一系列操作来确保系统的稳定性和功能正常。 #### 卸载现有版本 如果系统上已经安装了 `wpa_supplicant-2.10` 或其他更高版本,则应先卸载这些版本: ```bash sudo apt-get remove wpa_supplicant ``` 这一步骤可以防止不同版本之间的冲突[^1]。 #### 下载并解压新版本 下载 `wpa_supplicant-2.9` 的源码包,并将其解压缩到指定位置: ```bash tar -xvf wpa_supplicant-2.9.tar.gz cd wpa_supplicant-2.9/wpa_supplicant/ ``` 设置适当的权限以便于后续编译过程顺利进行: ```bash sudo chmod 777 -R ../wpa_supplicant/ cp defconfig .config ``` 上述命令会创建所需的配置文件 `.config` 并赋予必要的读写权限给项目目录及其子项。 #### 编译与安装 完成准备工作之后,可以通过以下方式编译新的 `wpa_supplicant` 库: ```bash make sudo make install ``` 此过程中将会生成多个可执行程序,包括但不限于 `wpa_cli`, `wpa_passphrase`, 和 `wpa_supplicant` 自身[^2]。 #### 配置启动参数 当准备运行时,需注意调整启动参数以适应具体环境需求。例如,在某些情况下可能需要用如下形式调用该服务: ```bash /system/bin/wpa_supplicant -Dwext -ieth0 -c/data/wifi/wpa_supplicant.conf -f/data/wifi/wpa_log.txt ``` 这里 `-Dwext` 表示驱动接口名称;`-ieth0` 是网络接口名;而 `-c` 后面跟的是配置文件路径以及日志记录的位置[^3]。 通过以上步骤即可成功实现从较高版本向较低版本回退的目的。然而需要注意的是,降级可能会带来兼容性风险或其他未知问题,因此建议事先备份重要数据并测试新旧版本间的差异影响范围。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值