Fedora 17/Linux下如何通过命令行连上加密的无线路由

1. 系统版本信息
[root@tp ~]# 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@tp ~]# systemctl stop NetworkManager.service
[root@tp ~]# 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@tp ~]# 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@tp ~]# iw wlan0 link
Not connected.
4. 获取SSID
[root@tp ~]# iw wlan0 scan | grep SSID
command failed: Network is down (-100)
[root@tp ~]# ifconfig wlan0 up
[root@tp ~]# 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
[root@tp ~]# iw wlan0 scan | grep SSID
SSID: n13u
SSID: FAST_Diablo

5. 连接无线加密路由
[root@tp ~]# 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@tp ~]# 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@tp ~]# 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@tp ~]# dhclient -r wlan0 #申请前先release
[root@tp ~]# dhclient wlan0
[root@tp ~]# 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@tp ~]# 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@tp ~]# iw wlan0 disconnect
[root@tp ~]# iw wlan0 link
Not connected.
[root@tp ~]# 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@tp ~]# 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@tp ~]#


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值