配置 WLAN 特定参数
iwconfig ethX essid <wlan_name>
key AAAA-AAAA-AA key BBBB-BBBB-BB key CCCC-CCCC-CC key DDDD-DDDD-DD
: Set 64-bit WEP Keys and ESSID in the driver
iwconfig ethX : Display WLAN parameters
iwpriv : Get nongeneric, driver-specific parameters
iwlist : List Information and statistics from an interface
iwspy : Read quality of link for a set of addresses
一、iwconfig
iwconfig是Linux Wireless Extensions(LWE)的用户层配置工具之一。LWE是Linux下对无线网络配置的工具,
包括内核的支持、用户层配置工具和驱动接口的支持三部分。目前不少无线网卡都支持LWE,并且主流的Linux发布版本,好比Redhat Linux、Ubuntu Linux都已经带了这个配置工具。
用法: iwconfig interface [essid {NN|on|off}]
[nwid {NN|on|off}]
[mode {managed|ad-hoc|...}
[freq N.NNNN[k|M|G]]
[channel N]
[ap {N|off|auto}]
[sens N]
[nick N]
[rate {N|auto|fixed}]
[rts {N|auto|fixed|off}]
[frag {N|auto|fixed|off}]
[enc {NNNN-NNNN|off}]
[power {period N|timeout N}]
[retry {limit N|lifetime N}]
[txpower N {mW|dBm}]
[commit]
说明:iwconfig是LWE最主要的工具,能够对无线网卡的大部分参数进行配置。
参数:
essid:设置无线网卡的ESSID(Extension Service Set ID)。经过ESSID来区分不一样的无线网络,正常状况下只有相同ESSID的无线站点
才能够互相通信,除非想监听无线网络。其后的参数为双引号括起的ESSID字符串,或者是any/on/off,若是ESSID字符串中包含
any/no/off,则须要在前面加"--"。
示例:
#ifconfig eth0 up/down 启动/禁用无线网卡
#iwconfig eth0 essid any 容许任何ESSID,也就是混杂模式
#iwconfig eth0 essid "My Network" 设置ESSID为"My Network"
#iwconfig eth0 essid -- "ANY" 设置ESSID为"ANY"
#iwconfig eth0 key [1] 设置key id
#iwconfig eth0 key 1231231234 设置password为1231231234
#iwpriv eth0 auth 2 设置认证方式为Shared
#iwpriv eth0 enc 2 设置加密方式为WEP
#iwlist eth0 scanning 搜索周围存在的无线网络
iwconfig eth0 nwid AB34
iwconfig eth0 nwid o
iwconfig eth0 nickname “My Linux Node”
iwconfig eth0 txpower off
iwconfig eth0 rts 250
iwconfig eth0 rts off
iwconfig eth0 mode Managed
iwconfig eth0 mode Ad-Hoc
iwconfig eth0 freq 2422000000
iwconfig eth0 freq 2.422G
iwconfig eth0 channel 3
iwconfig eth0 channel auto
iwconfig eth0 ap 00:60:1D:01:23:45
iwconfig eth0 ap any
iwconfig eth0 ap off
iwconfig eth0 rate 11M
iwconfig eth0 rate auto
iwconfig eth0 rate 5.5M auto
iwconfig eth0 txpower 15
iwconfig eth0 txpower 30mW
iwconfig eth0 txpower auto
iwconfig eth0 txpower off
iwconfig eth0 sens -80
iwconfig eth0 sens 2
iwconfig eth0 retry 16
iwconfig eth0 retry lifetime 300m
iwconfig eth0 retry min limit 8
nwid: Network ID,只用于pre-802.11的无线网卡,802.11网卡利用ESSID和AP的MAC地址来替换nwid,如今基本上不用设置。
示例:
#iwconfig eth0 nwid AB34
#iwconfig eth0 nwid off
nick: Nickname,一些网卡须要设置该参数,可是802.11协议栈、MAC都没有用到该参数,通常也不用设置。
示例:
#iwconfig eth0 nickname "My Linux Node"
mode:设置无线网卡的工做模式,能够是
Ad-hoc:不带AP的点对点无线网络
Managed:经过多个AP组成的网络,无线设备能够在这个网络中漫游
Master:设置该无线网卡为一个AP
Repeater:设置为无线网络中继设备,能够转发网络包
Secondary:设置为备份的AP/Repeater
Monitor:监听模式
Auto:由无线网卡自动选择工做模式
示例:
#iwconfig eth0 mode Managed
#iwconfig eth0 mode Ad-Hoc
freq/channel:设置无线网卡的工做频率或者频道,小于1000的参数被认为是频道,大于10000的参数被认为是频率。频率单位为Hz,
能够在数字后面附带k, M, G来改变数量级,好比2.4G。频道从1开始。使用lwlist工具能够查看无线网卡支持的频率
和频道。参数off/auto指示无线网络自动挑选频率。
注意:若是是Managed模式,AP会指示无线网卡的工做频率,所以该设置的参数会被忽略。Ad-hoc模式下只使用该设定的频率初始无线网络,若是加入已经存在的Ad-hoc网络则会忽略该设置的频率参数。
示例:
#iwconfig eth0 freq 2422000000
#iwconfig eth0 freq 2.422G
#iwconfig eth0 channel 3
#iwconfig eth0 channel auto
ap:链接到指定的AP或者无线网络,后面的参数能够是AP的MAC地址,也能够是iwlist scan出来的标识符。若是是Ad-hoc,则链接到
一个已经存在的Ad-hoc网络。使用off参数让无线网卡不改变当前已链接的AP下进入自动模式。any/auto参数,无线网卡自动选择
最好的AP。
注意:若是无线信号低到必定程度,无线网络会进入自动选择AP模式。
示例:
#iwconfig eth0 ap 00:60:1D:01:23:45
#iwconfig eth0 ap any
#iwconfig eth0 ap off
rate/bit:若是无线网卡支持多速率,则能够经过该命令设置工做的速率。小于1000的参数由具体的无线网卡驱动定义,通常是传输速
率的索引值,大于1000的为速率,单位bps,能够在数字后面附带k, M, G来指定数量级。auto参数让无线网卡自动选择速率
fixed参数让无线网卡不使用自动速率模式。
示例:
#iwconfig eth0 rate 11M
#iwconfig eth0 rate auto
#iwconfig eth0 rate 5.5M auto //自动选择5.5M如下的速率
txpower:若是无线网卡支持多发射功率设定,则使用该参数设定发射,单位为dBm,若是指定为W(毫瓦),只转换公式为:
dBm=30+log(W)。参数on/off能够打开和关闭发射单元,auto和fixed指定无线是否自动选择发射功率。
示例:
#iwconfig eth0 txpower 15
#iwconfig eth0 txpower 30mW
#iwconfig eth0 txpower auto
#iwconfig eth0 txpower off
sens:设置接收灵敏度的下限,在该下限之下,无线网卡认为该无线网络信号太差,不一样的网卡会采起不一样的措施,一些现代的无线网卡
会自动选择新的AP。正的参数为raw data,直接传给无线网卡驱动处理,通常认为是百分比。负值表示dBm值。
示例:
#iwconfig eth0 sens -80
#iwconfig eth0 sens 2
retry:设置无线网卡的重传机制。limit ‘value’ 指定最大重传次数;lifetime ‘value’指定最长重试时间,单位为秒,能够附带m和u来
指定单位为毫秒和微秒。若是无线网卡支持自动模式,则在limit和lifetime以前还能够附加min和max来指定上下限值。
示例:
#iwconfig eth0 retry 16
#iwconfig eth0 retry lifetime 300m
#iwconfig eth0 retry min limit 8
rts:指定RTS/CTS握手方式,使用RTS/CTS握手会增长额外开销,但若是无线网络中有隐藏无线节点或者有不少无线节点时能够提升性能。
后面的参数指定一个使用该机制的最小包的大小,若是该值等于最大包大小,则至关于禁止使用该机制。能够使用auto/off/fixed
参数。
示例:
#iwconfig eth0 rts 250
#iwconfig eth0 rts off
frag:设置发送数据包的分片大小。设置分片会增长额外开销,但在噪声环境下能够提升数据包的到达率。通常状况下该参数小于最大包
大小,有些支持Burst模式的无线网卡能够设置大于最大包大小的值来容许Burst模式。还能够使用auto/fixed/off参数。
示例:
#iwconfig eth0 frag 512
#iwconfig eth0 frag off
key/enc[ryption]:设置无线网卡使用的加密密钥,此处为设置WEP模式的加密key,若是要使用WPA,须要wpa_supplicant工具包。
密钥参数能够是 XXXX-XXXX-XXXX-XXXX 或者 XXXXXXXX 格式的十六进制数值,也能够是s:xxxxxx的ASCII字符。若是在密钥参数以前
加了[index],则只是设置该索引值对应的密钥,并不改变当前的密钥。直接指定[index]值能够设置当前使用哪个密钥。指定on/
off能够控制是否使用加密模式。open/restricted指定加密模式,取决于不一样的无线网卡,大多数无线网卡的open模式不使用加密且
容许接收没有加密的数据包,restricted模式使用加密。能够使用多个key参数,但只有最后一个生效。
WEP密钥能够是40bit,用10个十六进制数字或者5个ASCII字符表示,也能够是128bit,用26个十六进制数字或者13个ASCII字符表
示。
示例:
#iwconfig eth0 key 0123-4567-89
#iwconfig eth0 key [3] 0123-4567-89
#iwconfig eth0 key s:password [2]
#iwconfig eth0 key [2]
#iwconfig eth0 key open
#iwconfig eth0 key off
#iwconfig eth0 key restricted [3] 0123456789
#iwconfig eth0 key 01-23 key 45-67 [4] key [4]
power:设置无线网卡的电源管理模式。period ‘value’ 指定唤醒的周期,timeout ‘value’指定进入休眠的等待时间,这两个参数以前能够
加min和max修饰,这些值的单位为秒,能够附加m和u来指定毫秒和微秒。off/on参数指定是否容许电源管理,all/unicast/multicast
指定容许唤醒的数据包类型。
示例:
#iwconfig eth0 power period 2
#iwconfig eth0 power 500m unicast
#iwconfig eth0 power timeout 300u all
#iwconfig eth0 power off
#iwconfig eth0 power min period 2 power max period 4
commit:提交全部的参数修改给无线网卡驱动。有些无线网卡驱动会先缓存无线网卡参数修,使用这个命令来让无线网卡的参数修改生效。不过通常不须要使用该命令,由于无线网卡驱动最终都会是参数的修改生效,通常在debug时会用到。
-------------------------------------------------------------------------
iwlist eth1 scan 搜索无线网络:
显示搜到的网络(此处只显示一个):
eth1 Scan completed :
Cell 01 - Address: 00:04:E2:E3:04:FC
ESSID:"ap_demo"
Mode:Managed
Frequency:2.437 GHz
Quality:0/0 Signal level=-61 dBm Noise level=-96 dBm
Encryption key:on
Bit Rate:1 Mb/s
Bit Rate:2 Mb/s
Bit Rate:5.5 Mb/s
Bit Rate:11 Mb/s
Bit Rate:6 Mb/s
Bit Rate:9 Mb/s
Bit Rate:12 Mb/s
Bit Rate:18 Mb/s
Bit Rate:24 Mb/s
Bit Rate:36 Mb/s
Bit Rate:48 Mb/s
Bit Rate:54 Mb/s
Cell 02 ……
---------------------------------------------------------------------------
设置板子的channel
iwlist eth1 channel 11
-----------------------------------------------------------------------------
设置模式:
iwconfig eth1 mode managed
经过MAC 设置AP:
iwconfig eth1 ap 00:0A:EB:CA:79:B0
链接到WEP on 的AP:
iwconfig eth1 key s:12345 等效于 iwconfig eth1 enc 3132333435(12345的hex值) (为何AP64bit的口令是40bit呢)
iwconfig eth1 key on
iwconfig eth1 essid sychip_demo
断开WEP:
iwconfig eth1 enc off
查看IP:
ifconfig eth1
设置IP:
ifconfig eth1 10.3.1.74
把IP: 129.158.215.204 , netmask: 255.255.255.0分配给rh0,
# ifconfig rh0 129.158.215.204 netmask 255.255.255.0
获取IP; ifconfig eth1 dhcp start (从eth1走,不须要ip便可dhcp) udhcpc -i eth1 udhcpc --help 路由处理: 若要删除以 10. 起始的 IP 路由表中的全部路由,请键入: route delete 10.* route del default route add -net 10.3.0.0 netmask 255.255.0.0 eth1 (eth1得到IP以前,使用此命令显示:No such device)