繁体   English   中英

命令行连接到无线网络在ubuntu 10.04上不起作用

Command line connect to wireless network does not work on ubuntu 10.04

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

亲爱的诸位大主,

一些专家列出了连接到无线网络的详细信息,例如:

This is a step-to-step guide for connecting to a WPA/WPA2 WiFi network via the Linux command line interface. The tools are:

wpa_supplicant
iw
ip
ping
iw is the basic tool for WiFi network-related tasks, such as finding the WiFi device name, and scanning access points. wpa_supplicant is the wireless tool for connecting to a WPA/WPA2 network. ip is used for enabling/disabling devices, and finding out general network interface information.

The steps for connecting to a WPA/WPA2 network are:

Find out the wireless device name.
$ /sbin/iw dev
phy#0
    Interface wlan0
        ifindex 3
        type managed
The above output showed that the system has 1 physical WiFi card, designated as phy#0. The device name is wlan0. The type specifies the operation mode of the wireless device. managed means the device is a WiFi station or client that connects to an access point.

Check that the wireless device is up.
$ ip link show wlan0
3: wlan0: (BROADCAST,MULTICAST) mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether 74:e5:43:a1:ce:65 brd ff:ff:ff:ff:ff:ff
Look for the word "UP" inside the brackets in the first line of the output.

In the above example, wlan0 is not UP. Execute the following command to bring it up:

$ sudo ip link set wlan0 up  
[sudo] password for peter: 
Note: you need root privilege for the above operation.

If you run the show link command again, you can tell that wlan0 is now UP.

$ ip link show wlan0
3: wlan0: (NO-CARRIER,BROADCAST,MULTICAST,UP) mtu 1500 qdisc mq state DOWN mode DEFAULT qlen 1000
    link/ether 74:e5:43:a1:ce:65 brd ff:ff:ff:ff:ff:ff
Check the connection status.
$ /sbin/iw wlan0 link
Not connected.
The above output shows that you are not connected to any network.

Scan to find out what WiFi network(s) are detected
$ sudo /sbin/iw wlan0 scan
BSS 00:14:d1:9c:1f:c8 (on wlan0)
        ... sniped ...
    freq: 2412
    SSID: stanford
    RSN:     * Version: 1
         * Group cipher: CCMP
         * Pairwise ciphers: CCMP
         * Authentication suites: PSK
         * Capabilities: (0x0000)
        ... sniped ...
The 2 important pieces of information from the above are the SSID and the security protocol (WPA/WPA2 vs WEP). The SSID from the above example is stanford. The security protocol is RSN, also commonly referred to as WPA2. The security protocol is important because it determines what tool you use to connect to the network.

Connect to WPA/WPA2 WiFi network.
This is a 2 step process. First, you generate a configuration file for wpa_supplicant that contains the pre-shared key ("passphrase") for the WiFi network.

$ sudo -s
[sudo] password for peter: 
$ wpa_passphrase stanford >> /etc/wpa_supplicant.conf 
...type in the passphrase and hit enter...
wpa_passphrase takes the SSID as the single argument. You must type in     the passphrase for the WiFi network stanford after you run the command. Using that information, wpa_passphrase will output the necessary configuration statements to the standard output. Those statements are appended to the wpa_supplicant configuration file located at /etc/wpa_supplicant.conf.

Note: you need root privilege to write to /etc/wpa_supplicant.conf.

$ cat /etc/wpa_supplicant.conf 
# reading passphrase from stdin
network={
    ssid="stanford"
    #psk="testtest"
    psk=4dfe1c985520d26a13e932bf0acb1d4580461dd854ed79ad1a88ec221a802061
}
The second step is to run wpa_supplicant with the new configuration file.

$ sudo wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf
-B means run wpa_supplicant in the background.

-D specifies the wireless driver. wext is the generic driver.

-c specifies the path for the configuration file.

Use the iw command to verify that you are indeed connected to the SSID.

$ /sbin/iw wlan0 link
Connected to 00:14:d1:9c:1f:c8 (on wlan0)
    SSID: stanford
    freq: 2412
    RX: 63825 bytes (471 packets)
    TX: 1344 bytes (12 packets)
    signal: -27 dBm
    tx bitrate: 6.5 MBit/s MCS 0

    bss flags:  short-slot-time
    dtim period:    0
    beacon int: 100
Obtain IP address by DHCP
$ sudo dhclient wlan0
Use the ip command to verify the IP address assigned by DHCP. The IP address is 192.168.1.113 from below.

$ ip addr show wlan0
3: wlan0:  mtu 1500 qdisc mq state UP qlen 1000
    link/ether 74:e5:43:a1:ce:65 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.113/24 brd 192.168.1.255 scope global wlan0
    inet6 fe80::76e5:43ff:fea1:ce65/64 scope link 
        valid_lft forever preferred_lft forever
Add default routing rule.
The last configuration step is to make sure that you have the proper routing rules.

$ ip route show
192.168.1.0/24 dev wlan0  proto kernel  scope link  src 192.168.1.113 
The above routing table contains only 1 rule which redirects all traffic destined for the local subnet (192.168.1.x) to the wlan0 interface. You may want to add a default routing rule to pass all other traffic through wlan0 as well.

$ sudo ip route add default via 192.168.1.254 dev wlan0
$ ip route show
default via 192.168.1.254 dev wlan0 
192.168.1.0/24 dev wlan0  proto kernel  scope link  src 192.168.1.113 
ping external ip address to test connectivity
$ 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=48 time=135 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=48 time=135 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=48 time=134 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 134.575/134.972/135.241/0.414 ms
The above series of steps is a very verbose explanation of how to connect a WPA/WPA2 WiFi network. Some steps can be skipped as you connect to the same access point for a second time. For instance, you already know the WiFi device name, and the configuration file is already set up for the network. The process needs to be tailored according to your situation.

完全按照上述教程操作,我无法连接无线路由器。

(以root身份工作)

......
#wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D wext
#iw wlan0 link
Not connected.

即使我禁用WPA身份验证,

iwconfig wlan0 essid XXXXXXXXXXXXX

无济于事。

但是GNOME无线托盘正在运行(可以选择,连接,断开连接等)

提前非常感谢。

1 个回复

最新的wpa_supplicant能够自己完成所有工作。
您写的wpa_supplicant选项在我看来还不错。
但是,请检查文件“ /etc/wpa_supplicant.conf”中的选项,如果可读且格式正确(ssid,wpa,密码正确...)。

1 连接到无线网络

我创建了几个PowerShell脚本,这些脚本配置了培训课程中使用的计算机。 有些类需要连接到其他无线网络(SSID)。 我可以指导用户如何使用Windows XP设施来更改他们连接的网络,但是我希望能够将网络选择加入到我的PowerShell脚本中。关于如何在PowerShell中更改无线 ...

2 从命令行强制刷新(重新扫描)无线网络?

在我的程序中我使用命令“netsh wlan SHOW NETWORKS MODE = BSSID”来显示可用的SSID并将它们传递给我的程序,问题是命令不刷新可用的网络列表它只显示上次扫描的现金和我需要立即重新扫描当我告诉程序我发现有些东西禁用然后通过netsh命令重新启用界面,它的工作暂时,但我 ...

4 如何在android中连接到无线网络?

我已设法扫描无线网络并在我的应用程序中获取扫描结果。 但有没有办法可以使用我的应用程序本身连接到他们? 我想知道是否必须为我正在尝试连接的网络指定加密类型? 我的要求是连接到任何无线网络而不管它的加密类型? 有任何想法吗? 谢谢 ...

5 要求Facebook喜欢连接到无线网络

我今天收到朋友的请求。 他拥有一家咖啡店,并有一个免费的WIFI接入点。 现在他想要求访问者喜欢咖啡馆的Facebook页面才能连接到网络。 我不知道该怎么做。 他的路由器是TP-Link TL-WR940N。 我的点子: 安装DD-WRT 重定向到自定义登录页面 ...

6 是否可以检查谁连接到您的无线网络?

经过几个小时的研究后,我对这个问题一无所知。 是否可以使用C#查看谁连接到我的无线网络? 示例:我有2台笔记本电脑 - 笔记本电脑A和笔记本电脑B. A正在运行我制作的程序并连接到我的无线网络。 B正在启动并连接到我的无线网络。 A现在可以看到B通过我制作的程序连 ...

7 如何以编程方式连接到无线网络?

我的桌面上有一个Java应用程序和两个不同的无线网络连接(wifi)。 这是桌面应用程序,不是android。 此应用程序的一种方法适用于wifi1 ,第二种方法适用于wifi2 。 到目前为止,为了使用不同的方法,我必须手动更改桌面上的wifi设置。 有什么办法可以通过程序 ...

8 vb.net wince连接到无线网络

我在vb.net中有一个使用Wince Compact框架的应用程序,现在我需要它通过单击一个按钮才能连接到指定的无线网络,对此我进行了很多研究,甚至还得到了使用wlanapi.dll,但是我刚刚发现此API不在紧凑框架中。 有谁知道是否有可能将wlanapi.dll加载到紧凑型框架上,或 ...

9 连接到AR.Drone和独立的无线网络(Ubuntu 12.04)

我正在尝试连接到无线网络,同时能够与Ubunutu 12.04上的Parrot AR.Drone通信。 我可以同时连接到无人机和有线网络,但是在连接到无人机和无线网络上没有任何成功。 我知道我需要两个无线适配器来执行此任务,我的问题是在连接到第一个无线连接(AR.Drone)之后尝试连接 ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2022 STACKOOM.COM