歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Fedora 17/Linux下如何通過命令行連上加密的無線路由

1. 系統版本信息
[root@ www.linuxidc.com ~]# uname -a
Linux tp 3.3.4-5.fc17.x86_64 #1 SMP Mon May 7 17:29:34 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

2. 為防止NetworkManager服務帶來干擾,先停止該服務
[root@ www.linuxidc.com ~]# systemctl stop NetworkManager.service
[root@ www.linuxidc.com ~]# systemctl status NetworkManager.service
NetworkManager.service - Network Manager
      Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled)
      Active: inactive (dead) since Sun, 12 Aug 2012 22:37:23 +0800; 4s ago
     Process: 8569 ExecStart=/usr/sbin/NetworkManager --no-daemon (code=exited, status=0/SUCCESS)
      CGroup: name=systemd:/system/NetworkManager.service

Aug 12 22:37:23 tp NetworkManager[8569]: <info> (em1): device state change: ...]
Aug 12 22:37:23 tp NetworkManager[8569]: <info> (em1): cleaning up...
Aug 12 22:37:23 tp NetworkManager[8569]: <info> (em1): taking down device.
Aug 12 22:37:23 tp NetworkManager[8569]: <info> (wlan0): now unmanaged
Aug 12 22:37:23 tp NetworkManager[8569]: <info> (wlan0): device state change...]
Aug 12 22:37:23 tp NetworkManager[8569]: <info> (wlan0): deactivating device...]
Aug 12 22:37:23 tp NetworkManager[8569]: <info> (wlan0): canceled DHCP trans...8
Aug 12 22:37:23 tp NetworkManager[8569]: <info> (wlan0): cleaning up...
Aug 12 22:37:23 tp NetworkManager[8569]: <info> (wlan0): taking down device.
Aug 12 22:37:23 tp NetworkManager[8569]: <info> exiting (success)

3. 查看連接前的初始狀態
[root@ www.linuxidc.com ~]# ifconfig wlan0
wlan0: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 60:d8:19:cc:74:84  txqueuelen 1000  (Ethernet)
        RX packets 13547  bytes 13381624 (12.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12659  bytes 1974514 (1.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@ www.linuxidc.com ~]# iw wlan0 link
Not connected.

4. 獲取SSID
[root@ www.linuxidc.com ~]# iw wlan0 scan | grep SSID
command failed: Network is down (-100)
[root@ www.linuxidc.com ~]# ifconfig wlan0 up
[root@ www.linuxidc.com ~]# ifconfig wlan0
wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 60:d8:19:cc:74:84  txqueuelen 1000  (Ethernet)
        RX packets 13547  bytes 13381624 (12.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12659  bytes 1974514 (1.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

5. 連接無線加密路由
[root@ www.linuxidc.com ~]# iw wlan0 connect -w n13u key d:0:'1234567890123'
wlan0 (phy #0): connected to bc:ae:c5:7e:ba:fc
# 此處對key的寫法略作解釋:key d:index:data
d: default (transmit) key, 默認傳輸密碼
index: 0至3之間的單個數字,我第一次給的是0,能獲取到dhcp ip,後面換成其他數字後運行dhclient獲取不到ip
data: 必須是5或13位的ascii字符,或者10或26位的16進制數字

6. 查看連接完成後無線網卡的狀態
[root@ www.linuxidc.com ~]# iw wlan0 link
Connected to bc:ae:c5:7e:ba:fc (on wlan0)
    SSID: n13u
    freq: 2412
    RX: 9499 bytes (134 packets)
    TX: 342 bytes (4 packets)
    signal: -47 dBm
    tx bitrate: 54.0 MBit/s

    bss flags:    
    dtim period:    0
    beacon int:    100
[root@ www.linuxidc.com ~]# ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::62d8:19ff:fecc:7484  prefixlen 64  scopeid 0x20<link>
        ether 60:d8:19:cc:74:84  txqueuelen 1000  (Ethernet)
        RX packets 13550  bytes 13381882 (12.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12662  bytes 1974832 (1.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

7.獲取無線路由提供的dhcp ip地址
[root@ www.linuxidc.com ~]# dhclient -r wlan0 #申請前先release
[root@ www.linuxidc.com ~]# dhclient  wlan0
[root@ www.linuxidc.com ~]# ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.168.139  netmask 255.255.255.0  broadcast 192.168.168.255
        inet6 fe80::62d8:19ff:fecc:7484  prefixlen 64  scopeid 0x20<link>
        ether 60:d8:19:cc:74:84  txqueuelen 1000  (Ethernet)
        RX packets 13567  bytes 13386147 (12.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12682  bytes 1979923 (1.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

8. 已經可以連通外網
[root@ www.linuxidc.com ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=44 time=338 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=44 time=362 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 338.816/350.498/362.181/11.697 ms

9. 斷開連接
[root@ www.linuxidc.com ~]# iw wlan0 disconnect
[root@ www.linuxidc.com ~]# iw wlan0 link
Not connected.
[root@ www.linuxidc.com ~]# ifconfig wlan0
wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.168.139  netmask 255.255.255.0  broadcast 192.168.168.255
        inet6 fe80::62d8:19ff:fecc:7484  prefixlen 64  scopeid 0x20<link>
        ether 60:d8:19:cc:74:84  txqueuelen 1000  (Ethernet)
        RX packets 14214  bytes 13620419 (12.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13375  bytes 2424481 (2.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@ www.linuxidc.com ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 192.168.168.139 icmp_seq=10 Destination Host Unreachable
From 192.168.168.139 icmp_seq=11 Destination Host Unreachable
From 192.168.168.139 icmp_seq=12 Destination Host Unreachable
From 192.168.168.139 icmp_seq=13 Destination Host Unreachable
^C
--- 8.8.8.8 ping statistics ---
14 packets transmitted, 0 received, +4 errors, 100% packet loss, time 13001ms
pipe 4
[root@ www.linuxidc.com ~]#

Copyright © Linux教程網 All Rights Reserved