Linux无线网络管理命令(ip/iw/iwconfig/iwlist/ifconfig/wpa_supplicant) 运维

 

 

Linux无线网络管理命令(ip/iw/iwconfig/iwlist/ifconfig/wpa_supplicant) 运维
https://blog.csdn.net/DXCyber409/article/details/80574111

 

 

 

Linux无线网络管理命令(ip/iw/iwconfig/iwlist/ifconfig/wpa_supplicant)
原创DXCyber409 最后发布于2018-06-05 22:14:27 阅读数 3313  收藏
展开
前言
以下各小节的前半部分介绍无线网络相关的各种命令的背景以及适用范围。

后半部分演示常用命令搭配和相关操作。

iw命令
man手册中可以找到说明 iw - show / manipulate wireless devices and their configuration

这意味着iw既可以查看信息,又可以管理无线网络设备,还能更改配置,属于比较全能的命令。

缺点:实测对USB网卡支持性很差,几乎只适用于物理接入设备(PCI板载设备)。

常用命令列表:   

iw list  # 查看本机支持的无线特性,such as band information (2.4 GHz, and 5 GHz), and 802.11n information
iw dev wlan0 scan # 扫描无线网络,列表的内容都是实时更新的
iw dev wlan0 link # 获取设备连接状态信息(实测不包含IP地址)
iw wlan0 info # 获取设备工作状态信息
iw event # 获取所有网络设备的工作日志信息
英文原文介绍:https://wireless.wiki.kernel.org/en/users/Documentation/iw

译文:https://blog.csdn.net/robertsong2004/article/details/40044947

ifconfig命令
ifconfig - configure a network interface 配置网络接口命令

通用的接口操作命令,但通用意味着只能做一些少量配置,例如打开关闭设备接口,配置IP、子网掩码,查看IP地址等。

ifconfig eth0 down # 关闭eth0接口
ifconfig wlan0 up  # 打开wlan0接口
ifconfig eth0 192.168.1.3 netmask 255.255.255.0 # 设置IP地址和子网掩码
route add default gw 192.168.1.1 # 顺便附带设置网关命令
man ifconfig 可以看到详情。

ip命令
ip - show / manipulate routing, devices, policy routing and tunnels

ip命令用于显示/操作路由、设备、策略路由和隧道,和iw一样是较为综合而强大的命令,与之相似的原型命令可以看作是ifconfig。

[root@localhost ~]# ip --help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
                   tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
                   netns | l2tp | macsec | tcp_metrics | token }
       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
                    -h[uman-readable] | -iec |
                    -f[amily] { inet | inet6 | ipx | dnet | bridge | link } |
                    -4 | -6 | -I | -D | -B | -0 |
                    -l[oops] { maximum-addr-flush-attempts } |
                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
                    -rc[vbuf] [size] | -n[etns] name | -a[ll] }
最最常用搭配

ip link set wlan0 [up] [down]  # 设置网络接口的开启关闭

其他常用命令格式搭配可以参阅此文:https://blog.csdn.net/radkitty/article/details/3022181

iwlist命令
iwlist  - Get more detailed wireless information from a wireless interface

DXCyber409@DXCyber409:/etc/wpa_supplicant$ iwlist --help
Usage: iwlist [interface] scanning [essid NNN] [last]
              [interface] frequency 
              [interface] channel 
              [interface] bitrate 
              [interface] rate 
              [interface] encryption 
              [interface] keys 
              [interface] power 
              [interface] txpower 
              [interface] retry 
              [interface] ap 
              [interface] accesspoints 
              [interface] peers 
              [interface] event 
              [interface] auth 
              [interface] wpakeys 
              [interface] genie 
              [interface] modulation 

可以通过该命令来获取最后一次扫描的缓存信息:iwlist wlan0 scanning

对于USB网卡,要扫描周围的SSID广播,该命令几乎是唯一选项,因为iw支持不好。

iwconfig命令
和ifconfig是同级别的用户级管理工具,但专注于无线网络管理。

DXCyber409@DXCyber409:/etc/wpa_supplicant$ iwconfig --help
Usage: iwconfig [interface]
                interface essid {NNN|any|on|off}
                interface mode {managed|ad-hoc|master|...}
                interface freq N.NNN[k|M|G]
                interface channel N
                interface bit {N[k|M|G]|auto|fixed}
                interface rate {N[k|M|G]|auto|fixed}
                interface enc {NNNN-NNNN|off}
                interface key {NNNN-NNNN|off}
                interface power {period N|timeout N|saving N|off}
                interface nickname NNN
                interface nwid {NN|on|off}
                interface ap {N|off|auto}
                interface txpower {NmW|NdBm|off|auto}
                interface sens N
                interface retry {limit N|lifetime N}
                interface rts {N|auto|fixed|off}
                interface frag {N|auto|fixed|off}
                interface modulation {11g|11a|CCK|OFDMg|...}
                interface commit 
       Check man pages for more details.
可以使用此命令来连接开放(未加密)的WI-FI网络,和查看接入点的情况。

iwconfig wlan0 essid "WIFI名称" # 连接开放的WI-FI网络
iwconfig wlan0 # 查看wlan0连接情况,如果成功连接,将在Access Point显示下一路由的MAC地址,否则表示尚未连接。
wpa_supplicant命令
wpa_supplicant  - Wi-Fi Protected Access client and IEEE 802.1X supplicant

该命令可用于WPA/WPA2-PSK/WEP加密网络的连接管理,现代WI-FI环境必备。

DXCyber409@DXCyber409:/etc/wpa_supplicant$ wpa_supplicant --help
wpa_supplicant: invalid option -- '-'
wpa_supplicant v2.6
Copyright (c) 2003-2016, Jouni Malinen <j@w1.fi> and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/)

usage:
  wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] [-g<global ctrl>] \
        [-G<group>] \
        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \
        [-b<br_ifname>] [-e<entropy file>] [-f<debug file>] \
        [-o<override driver>] [-O<override ctrl>] \
        [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
        [-m<P2P Device config file>] \
        [-p<driver_param>] [-b<br_ifname>] [-I<config file>] ...]

drivers:
  nl80211 = Linux nl80211/cfg80211
  wext = Linux wireless extensions (generic)
  wired = Wired Ethernet driver
  none = no driver (RADIUS server/WPS ER)
options:
  -b = optional bridge interface name
  -B = run daemon in the background
  -c = Configuration file
  -C = ctrl_interface parameter (only used if -c is not)
  -d = increase debugging verbosity (-dd even more)
  -D = driver name (can be multiple drivers: nl80211,wext)
  -e = entropy file
  -f = log output to debug file instead of stdout
  -g = global ctrl_interface
  -G = global ctrl_interface group
  -h = show this help text
  -i = interface name
  -I = additional configuration file
  -K = include keys (passwords, etc.) in debug output
  -L = show license (BSD)
  -m = Configuration file for the P2P Device interface
  -N = start describing new interface
  -o = override driver parameter for new interfaces
  -O = override ctrl_interface parameter for new interfaces
  -p = driver parameters
  -P = PID file
  -q = decrease debugging verbosity (-qq even less)
  -s = log output to syslog instead of stdout
  -t = include timestamp in debug messages
  -T = record to Linux tracing in addition to logging
       (records all messages regardless of debug verbosity)
  -u = enable DBus control interface
  -v = show version
  -W = wait for a control interface monitor before starting
example:
  wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf
接下来演示如何通过wpa_supplicant连接加密的Wi-Fi网络,详细的解释以及配套的CLI交互程序使用,如有需要请详见参考文献。

博主所使用的Linux环境为Kali-Rolling,开机是会自己启动好wpa_supplicant的,因此已经提前kill掉相关进程用于演示。

首先按照手机等连接Wi-Fi的习惯,我们需要知道扫描无线网络广播并记录需要连接的SSID名称(iw命令和iwlist命令都可以完成,请查阅本文小关小节)。

根据手册我们需要一个配置文件,填入连接配置信息,sudo vim /etc/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant

network={
    ssid="Wifi Network 1" 
    psk="12345678"
}
network={
    ssid="Wifi Network 2"
    psk="87654321"
}
随后启动wpa_supplicant
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf 

其中守护进程启动的-B参数如果不使用,可以看到连接过程用于监控错误的发生,例如密码输入错误。

启动后通过iwconfig命令可以看到wlan0接口已经有了Access Point地址,证明已经连接。

但ifconfig wlan0没有显示IP,此时需要获取IP地址才能上网。

dhclient wlan0 之后即可打开网页测试。

补充:USB无线网卡使用wpa_supplicant时出现错误信息

DXCyber409@DXCyber409:~$ sudo wpa_supplicant -i wlan1 -c /etc/wpa_supplicant.conf
Successfully initialized wpa_supplicant
nl80211: Could not configure driver mode
nl80211: deinit ifname=wlan1 disabled_11b_rates=0
wlan1: Failed to initialize driver interface
在wpa_supplicant启动参数中补充 -D wext 参数即可。

同时在wpa_supplicant的输出中可以看到

Successfully initialized wpa_supplicant
rfkill: Cannot get wiphy information
博主的USB网卡驱动并没有使用默认的n80211驱动模式,而是换成了扩展驱动wext模式。因此并没有被归纳入系统支持设备中,这也正是iw命令不能很好的支持USB网卡的原因。

参考文献

wpa_cli命令解析:https://blog.csdn.net/jy1075518049/article/details/51015141

linux下连接无线网出现nl80211: Could not configure driver mode nl80211:

http://www.cnblogs.com/dakewei/p/7750433.html
————————————————
版权声明:本文为CSDN博主「DXCyber409」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/DXCyber409/article/details/80574111

 

 

 

 

 

iwlist/iwconfig/iw命令 - 文刀文刀 - 博客园
https://www.cnblogs.com/liuliu-word/p/9646060.html

 

1、iwlist 命令:用于对/proc/net/wireless文件进行分析,得出无线网卡相关信息

# iwlist wlan0 scanning 搜索当前无线网络

# iwlist wlan0 frequen 显示频道信息

# iwlist wlan0 rate 显示连接速度

# iwlist wlan0 power 显示电源模式

# iwlist wlan0 txpower 显示功耗

# iwlist wlan0 retry 显示重试连接次数(网络不稳定查看)

# iwlist wlan0 ap 显示热点信息

# iwlist --help 显示帮助信息

# iwlist --version 显示版本信息

2、iwconfig 系统配置无线网络设备或显示无线网络设备信息。iwconfig 命令类似于ifconfig命令,但是他配置对象是无线网卡,它对网络设备进行无线操作,如设置无线通信频段

 

auto 自动模式

essid 设置ESSID

nwid 设置网络ID

freq 设置无线网络通信频段

chanel 设置无线网络通信频段

sens 设置无线网络设备的感知阀值

mode 设置无线网络设备的通信设备

ap 强迫无线网卡向给定地址的接入点注册

nick<名字> 为网卡设定别名

rate<速率> 设定无线网卡的速率

rts<阀值> 在传输数据包之前增加一次握手,确信信道在正常的

power 无线网卡的功率设置

3、iw 是一种新的基于 nl80211 的用于无线设备的CLI配置实用程序。它支持最近已添加到内核所有新的驱动程序。采用无线扩展接口的旧工具iwconfig已被废弃,强烈建议切换到 iw 和 nl80211。

Linux内核的其余部分,iw 仍处于开发阶段。功能被随时添加。 iw 的唯一文档就是此页和“iw help”的输出。 请帮助扩大这个页面。

有一个页面列出iwconfig和iw的用例:替换 iwconfig.

# iw help # 帮助

# iw ibss leave # 查看WiFi是否打开状态

# iw list # 获得所有设备的功能,如带宽信息(2.4GHz,和5GHz),和802.11n的信息

# iw dev wlan0 scan # 扫描

# iw event # 监听事件

# iw dev wlan0 link # 获得链路状态

# iw wlan0 connect foo # 连接到已禁用加密的AP,这里它的SSID是foo

# iw wlan0 connect foo 2432 # 假设你有两个AP SSID 都是 foo ,你知道你要连接的是在 2432 频道

# iw wlan0 connect foo keys 0:abcde d:1:0011223344 # 连接到使用WEP的AP

# iw dev wlan1 station dump # 获取station 的统计信息

# iw dev wlan1 station get # 获得station对应的peer统计信息

# iw wlan0 set bitrates legacy-2.4 12 18 24 # 修改传输比特率

# iw dev wlan0 set bitrates mcs-5 4 # 修改tx HT MCS的比特率

# iw dev wlan0 set bitrates mcs-2.4 10

# iw dev wlan0 set bitrates mcs-5 # 清除所有 tx 比特率和设置的东西来恢复正常

# iw dev set txpower [] #设置传输功率

# iw phy set txpower [] #设置传输功率

# iw dev wlan0 set power_save on #设置省电模式

# iw dev wlan0 get power_save #查询当前的节电设定

# iw phy phy0 interface add moni0 type monitor #添加一个 monitor 接口

分类: Android sdk adb 命令

 

 

 

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值