ubuntu下cli連接無線網絡
iwconfig
wlan2 IEEE 802.11abgn ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=20 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Power Management:on
lo no wireless extensions.
eth0 no wireless extensions.
ifconfig wlan2
wlan2 Link encap:Ethernet HWaddr 68:7f:74:72:00:53
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:10944 errors:0 dropped:0 overruns:0 frame:0
TX packets:10209 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6214930 (6.2 MB) TX bytes:1032870 (1.0 MB)
sudo ifconfig wlan2 up
ifconfig wlan2
wlan2 Link encap:Ethernet HWaddr 68:7f:74:72:00:53
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:10944 errors:0 dropped:0 overruns:0 frame:0
TX packets:10209 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6214930 (6.2 MB) TX bytes:1032870 (1.0 MB)
sudo iwlist wlan2 scan
Cell 01 - Address: 00:03:7F:BE:0A:01
Channel:6
Frequency:2.437 GHz (Channel 6)
Quality=31/70 Signal level=-79 dBm
Encryption key:off
ESSID:"whx-cpe"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s
Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=000000000d6ad4c6
Extra: Last beacon: 48ms ago
IE: Unknown: 00077768782D637065
IE: Unknown: 010882848B960C121824
IE: Unknown: 030106
IE: Unknown: 0706434E20010D3F
IE: Unknown: 2A0104
IE: Unknown: 32043048606C
IE: Unknown: 2D1AAD0103FFFF000000000000000000000000000000000000000000
IE: Unknown: 331AAD0103FFFF000000000000000000000000000000000000000000
IE: Unknown: 3D1606000100000000000000000000000000000000000000
IE: Unknown: 341606000100000000000000000000000000000000000000
IE: Unknown: DD180050F2020101830003A4000027A4000042435E0062322F00
IE: Unknown: DD0900037F01010000FF7F
sudo iwconfig wlan2 essid whx-cpe
iwconfig wlan2
wlan2 IEEE 802.11abgn ESSID:"whx-cpe"
Mode:Managed Frequency:2.437 GHz Access Point: 00:03:7F:BE:0A:01
Bit Rate=6.5 Mb/s Tx-Power=20 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Power Management:on
Link Quality=27/70 Signal level=-83 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:5 Invalid misc:0 Missed beacon:0
dhclient wlan2
ifconfig wlan2
wlan2 Link encap:Ethernet HWaddr 68:7f:74:72:00:53
inet addr:192.168.11.151 Bcast:192.168.11.255 Mask:255.255.255.0
inet6 addr: fe80::6a7f:74ff:fe72:53/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:10955 errors:0 dropped:0 overruns:0 frame:0
TX packets:10226 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6216678 (6.2 MB) TX bytes:1035222 (1.0 MB)
route -n
。。。。。。。。。。。。。。。。。。。。。。
0.0.0.0 192.168.11.33 0.0.0.0 UG 0 0 0 wlan2
。。。。。。。。。。。。。。。。。。。。。。
192.168.11.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan2
。。。。。。。。。。。。。。。。。。。。。。
web訪問192.168.11.33可打開網關主頁,至此連接成功。
其中需要注意的這個過程中,我們是先和AP認證關聯,然後再獲得IP地址,獲得IP地址的方法可以是DHCP,也可以是靜態。
可以認為認證關聯和IP配置沒有關系!!!
AP信息:ESSID:whx-cpe 認證模式:wpa-pskifc加密,密鑰:whx-cpee,地址為192.168.11.33,開啟dhcp
安裝wpasupplicant
sudo apt-get install wpasupplicant
清除wlan2的wifi關聯
sudo iwconfig wlan2 essid ""
清除wlan2的ip配置
sudo ifconfig wlan2 0.0.0.0
sudo iwlist wlan2 scan
Cell 04 - Address: 00:03:7F:BE:0A:01
Channel:6
Frequency:2.437 GHz (Channel 6)
Quality=29/70 Signal level=-81 dBm
Encryption key:on
ESSID:"whx-cpe"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s
Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=000000000039d180
Extra: Last beacon: 2776ms ago
IE: Unknown: 00077768782D637065
IE: Unknown: 010882848B960C121824
IE: Unknown: 030106
IE: Unknown: 0706434E20010D3F
IE: Unknown: 2A0104
IE: Unknown: 32043048606C
IE: Unknown: DD180050F2020101810003A4000027A4000042435E0062322F00
IE: Unknown: DD0900037F01010000FF7F
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (1) : TKIP
Authentication Suites (1) : PSK
wpa_passphrase whx-cpe whx-cpee > wpa.conf
cat wpa.conf
network={
ssid="whx-cpe"
#psk="whx-cpee"
psk=6c50c71830a47aa6f59c3ed0f28e6f89a1dff2570f8b5b03d1d7d575992e7b3b
}
iwconfig wlan2
wlan2 IEEE 802.11abgn ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=20 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Power Management:on
wpa_supplicant -Dwext -iwlan2 -c./wpa.conf
另起一個窗口,或者運行上一條命令是加個&在後台運行
iwconfig wlan2
wlan2 IEEE 802.11abgn ESSID:"whx-cpe"
Mode:Managed Frequency:2.437 GHz Access Point: 00:03:7F:BE:0A:01
Bit Rate=1 Mb/s Tx-Power=20 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Power Management:on
Link Quality=27/70 Signal level=-83 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
從上面可用看出與AP認證關聯成功,配置靜態IP
sudo ifconfig wlan2 192.168.11.157
至此可訪問AP主頁,要想訪問外網還得配置DNS、route等