个人工具

老旧文章/WiFiHowto

来自Ubuntu中文

跳转至: 导航, 搜索

Wi-Fi WLAN 无线网络信息

开始进行

被支持的无线网卡信息在 WLANHowtoWPAHowtoMadwifi-ng. 也可以检查 列表

在你的电脑上设置无线网卡之前你需要熟悉一下无线网络的基本知识,同时设定你的无线网络的路由器或接驳点。最好是从路由器的文档入手,它通常有一份关于Wi-Fi的介绍。你同时也很有可能需要参考这份文档来设置路由器。你也许需要看一下网络上关于 在Wikipedia的信息 或者 如何设置 Linux Wlan 的技术概观。这两个都有点专业,但是如果有人能够找到一份简单的网络新手文件加在这里是最好不过了。

你需要做的第一件事情是从网上获取 无线网络工具 包 (参见 SynapticHowto).

有一些Wi-Fi网卡是外置工作的,特别是有Orinoko,Prism2或者Atheros芯片集的那些网卡。如果你的卡并不是外置工作的 [Rt2500WirelessCardsHowTo]。如果你有一台迅驰的笔记本,那么应该会有基于ipw2200的网卡。 It works out of the box but uses an ancient driver. 请参阅Luca_Linux's post以获得一份相当好的关于ipw2200网卡设置的说明。 请见Luca_Linux's post ,一份很好的设置ipw2200卡的指南 (you may want to stop before he takes you into the WPA portion of the setup). For cards that do not work out of the box see [SetupNdiswrapperHowto].

开始时你需要将你的无线路由器设置为'开放'网络. 意思是你需要关闭所有安全,例如WAP,WEP和MAC地址约束. 后续再开启这些,我们只是为了确保它们在开始时不会引起任何麻烦.

你也需要给出你无线网络的ESSID. 几乎所有无线路由器都有一个默认值. 常常是 "default", "linksys" "netgear"或者其他常用的名字.



iwconfig Before You Start

在开始前使用iwconfig命令

(optional, but not a bad idea)

(可选,还不错)
Ubuntu ships with a fantastic GUI network tool called network-admin. It can be run from a terminal but it is also readily available under the system menu. (System)->(Administration)->(Networking). You can jump right in and start poking around with network-admin, but its best to run iwconfig from a terminal first. Since linux names your wifi card based on the driver it uses (can somebody back that up?) we first need to figure out what your card is called. Bring up a terminal (Applications)->(System Tools)->(Terminal) and issue the following command:

Ubuntu系统中安装了一个界面不错的网络工具,其名字叫做network-admin。可以在终端中运行该命令,但是其同样存在于系统菜单中。(系统)->(系统管理)->(联网)。您可以直接执行network-admin,但最好在之前在终端窗口中运行iwconfig命令。一旦linux根据其安装的驱动(有哪位高人备份一下)识别您的无线网卡时,我们需要指出您的网卡的名称。打开终端(应用程序)->(系统工具)->(终端)并输入如下命令:

[email protected]:iwconfig

Your ouput should look like:

您应该会得到类似如下的回复:

lo        no wireless extensions.

eth0      no wireless extensions.

sit0      no wireless extensions.

wlan0     unassociated  ESSID:off/any
Mode:Managed  Channel=0  Access Point: 00:00:00:00:00:00
Bit Rate=0 kb/s   Tx-Power:off
Retry:on   RTS thr:off   Fragment thr:off
Power Management:off
Link Quality:0  Signal level:0  Noise level:0
Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
Tx excessive retries:0  Invalid misc:0   Missed beacon:0

If all devices listed say "no wireless extensions." then your wireless card is not configured. You need to go back and get it setup. Please see the top of this document and also[SetupNdiswrapperHowto] for more information.

如果所有的驱动列表均显示 "no wireless extensions." “未发现无线设备。” 的话,说明您的无线网卡没有配置。您需要返回并重新安装。请参阅本文档前部分和 [SetupNdiswrapperHowto]以获取更多信息。

Based on the iwconfig output from above, we know that "wlan0" is our WiFi card's linux device name. Knowing this you'll be able to use the Networking GUI tool to connect to your wireless router. (You may also see ath0 or even eth1 come up as your device name. Don't worry, that's totally fine, it just depends on the type of card you have and the drivers that are accessing it.)

根据上面的iwconfig的输出,我们知道了 “wlan0” 是我们的无线网卡在linux设备中的名称。 在这样的情况下,您可以使用网络图形工具来联接到您的无线路由器。(您也许会看到ath0 或 ath1 出现在设备名称中。 请别担心,这样更好,能否出现这样的情况取决于卡的类型和驱动。)

Click on (System)->(Administration)->(Networking) and see if your wireless network card is listed. If it isn't you've got a problem. (Somebody needs to describe what to do next)

请单击(系统)->(系统管理)->(联网)来观察您的无线网卡是否在列表中。如果没有的话,说明某个地方依然存在问题。 (某些人需要知道接下来该怎么做。)



使用图形用户界面工具

As mentioned before Ubuntu ships with a fantastic GUI network tool called network-admin. It can be run from a terminal but it is also readily available under the system menu. (System)->(Administration)->(Networking).


Once it is launched you'll be presented with a list of network adapters that are available on your system. You should see an entry that named "Wireless connection" and just beneath it it may say "The interface wlan0 is not active". Your setup may not say "wlan0" however it should match the device name that we looked up in iwconfig above.


Since your card is listed in network-admin you can easily setup the network configuring. In network-admin select the Wireless connection entry and then click the Properties button.


This is where you actually specify the network to connect to. You should type the ESSID that you have assigned to your router into the box that says "Network Name (ESSID):". Since we have disabled WEP we can leave the WEP Key field blank. Normaly Configuration can be left as Automatic (DHCP). Chances are you have set up your wireless router as a DHCP Server, if not do so (refer to Router documentation). Click on OK.


Select the eth0 network and click on Deactivate button (if you have one - basically deactivate all Network cards other than the WiFi). Then select wlan0 (or whatever your wireless card is called) and click on the Activate button. You should end up with the checkbox under Active for wlan0 checked and the others not checked. You can now fire up a web browser and see if you can browse the web. Alternativly the best way of checking if you have a working internet connection is to use ping which checks that a domain exists and can be reached (think SONAR ping, but for networks). Open a terminal and type:

ping -n 4.2.2.2 -c 4

这将送出4次ping到internet地址4.2.2.2.


你的输出应该看起来像这样:

PING 4.2.2.2 (4.2.2.2) 56(84) bytes of data
64 bytes from from 4.2.2.2: icmp_seq=1 ttl=205 time={some value}
64 bytes from from 4.2.2.2: icmp_seq=2 ttl=205 time={some value}
64 bytes from from 4.2.2.2: icmp_seq=3 ttl=205 time={some value}
64 bytes from from 4.2.2.2: icmp_seq=4 ttl=205 time={some value}

If it doesn't and you get statements saying "Destination host unreachable" or "request timed out", then you've got a problem and you aren't connected. (somebody should write some instructions on what to do next).


If you do get the results listed above then you are able to ping an internet address and your wireless card is working. Next you'll want to try a domain name. Lets go with google:

ping google.com -c 4

你的输出应该看起来像这样:

PING google.com (216.239.37.99) 56(84) bytes of data
64 bytes from from 216.239.37.99: icmp_seq=1 ttl=205 time={some value}
64 bytes from from 216.239.37.99: icmp_seq=2 ttl=205 time={some value}
64 bytes from from 216.239.37.99: icmp_seq=3 ttl=205 time={some value}
64 bytes from from 216.239.37.99: icmp_seq=4 ttl=205 time={some value}

If your first ping to 4.2.2.2 worked and your ping to google.com doesn't (ie: you get "unknown host") then something is wrong with your DNS. (somebody needs to describe what to do next).


If both pings work then you can be pretty sure that your network is running. Fire up your favorite web browser and surf off to your favorite site. Everything should be good.



使用命令行

如果你可以浏览网页,你的网卡已经设置了并且正在工作。如果不是,我们可以尝试从另一个途径达到这个目的。开一个终端窗口然后输入

ifconfig

这个将会列出你的网络。标准的网络通常是叫eth0。输入以下指令来停止这个网络

sudo ifdown eth0

除了“lo”,对所有的网络做这样的操作。然后输入以下指令以开始你的无线网络

sudo ifup wlan0

输入ifconfig以确认这个已经工作了,如果所有的都好了,尝试浏览网页或者ping。如果不行,尝试以下的命令

iwconfig wlan0 mode managed
iwconfig wlan0 channel 11
iwconfig wlan0 essid networkname

mode managed是如果你在连接一个无线路由器时所需要的。channel和esidd需要设置的跟你的路由器一致。


你使你的网络工作,但是它是一个开放的网络或者说是一个不安全的网络。参考你的路由器文档以查找到如何设置一个安全的网络。每一个网卡(不论有线还是无线)有一个唯一的数字,这个数字叫硬件地址。大多数无线路由器允许你限制那些可以连接它们的硬件地址。输入以下命令以查找你的硬件地址类型

ifconfig wlan0

这个是 !HWaddr 下面的第一行。


加密

设置加密同样是有好处的(我们将使用WEP加密,因为Ubuntu能很好的支持它),因为硬件地址限制是可以被循环的。第一,你需要设置你的路由器以使用 WEP加密。这篇文章剩下的部分,因为虽然不同的路由器工作有着细微的区别,但是仍需要提供一个概念。参考你的路由器手册,但是WEP的设置应该像你路由器的网络接口上的一些类似wireless(无线)->security(安全)的东西。一般在这个时候你能够使用WEP安全并且选择一个key size。越大越好,但是在这里的例子是使用的64bit(有时候会提到40bit)keys。通常你可以键入一个passphrase(一个密码,但是你必须使用一些紧靠在一起的单词)。一般来讲这时候再点击类似Generate(生成),several keys(常规是4)就被创建了。其中之一将会被标记为默认key,这个就是我们将要用到的。


在Computer(电脑)->System Configuration(系统配置)->Networking(网络)->(wlan0)properties(属性)。这个想法是你将你的key填在这里,但是我没法让它工作,我所能做的使它工作的办法就是输入

iwconfig wlan0 key FEFEFEFEFE

FEFEFEFEFE的地址是WEP key的十六进制表达。十六进制将0-F而不是0-9(这是以16为基数,A代表10然后一直以此种方式到F,F代表15,10代表16)。所有的key 都是以这种方法来说明的。你接下来应该可以浏览网页或者ping。虽然并不是完全确认,但是有时候好像你需要等它一分钟左右开始工作。

将它添加到 /etc/network/interfaces

/etc/network/interfaces 是定义你的网络接口的文件。eth0是标准的有线网络接口。为了使无线网络在你开启你的电脑时出现,赋# in front of 'auto eth0'(以此来阻止它自动的开始运行)同时添加类似于以下内容的几条指令。

auto wlan0
iface wlan0 inet dhcp
name Wireless LAN card
wireless_essid   MYNETWOTK
wireless_key     FEFEFEFEFE
wireless_channel 11
wireless_mode    managed

我已经编写了一个小的脚本来使我的膝上型电脑自动的选择几个配置过的WLAN网络。它使用无线工具在“ifup interface”上来搜索已知的或者开放的网络。脚本wlan-scan.sh类似以下内容:

#!/bin/sh

IFACE=$1

ip link set $IFACE up

SCAN=$( \
iwlist $IFACE scan 2>&1 | grep -v "<sup>$IFACE" | grep -v "</sup>$" | \
sed -e "s/^\ *//" \
-e "s/^Cell [0-9]\+ - /#/" \
-e "s/^#Address: /#AP=/" \
-e "s/^Quality:\([0-9]\+\)\/.*$/QUALITY=\1/" \
-e "s/^.*Channel \([0-9]\+\).*$/CHANNEL=\1/" \
-e "s/^ESSID:/ESSID=/" \
-e "s/^Mode:/MODE=/" \
-e "s/^Encryption key:/ENC=/" \
-e "s/<sup>[</sup>#].*:.*//" | \
tr "\n#" "|\n" \
)

ip link set $IFACE down

which=""
while read glob scheme; do
AP=""; QUALITY=""; CHANNEL=""; ESSID=""; MODE=""; ENC=""
for i in $SCAN ; do
for j in $(echo $i | sed -e "s/|/ /g" ) ; do
case $j in
AP=*)
AP=${j#AP=}
;;
QUALITY=*)
QUALITY=${j#QUALITY=}
;;
CHANNEL=*)
CHANNEL=${j#CHANNEL=}
;;
ESSID=*)
ESSID=${j#ESSID=}
;;
MODE=*)
MODE=${j#MODE=}
;;
ENC=*)
ENC=${j#ENC=}
;;
esac
done

case "$AP,$ESSID,$ENC,$MODE,$CHANNEL" in
$glob)
echo $scheme
exit 0
;;
esac
done
done

exit 1

而且是和底层映射的接口文件一起使用。

我的看起来跟这个类似:

mapping wlan0

script /path/to/wlan-scan.sh
# Accesspoint,"ESSID",Encryption,Mode,Channel
map 00:FE:FE:FE:00:00,"MY_NET",*,*,* wlan0-home
map *,"COMPANY",on,Master,*          wlan0-office
map *,*,off,Master,*                 wlan0-open

iface wlan0-home inet dhcp
wireless-essid HOMENET
wireless-mode managed
wireless-enc FEFEFEFEFEFE

iface wlan0-office inet dhcp
wireless-essid COMPANY
wireless-mode managed
wireless-enc s:Secret_password

# This is a fallback, selected for all unencrypted WLANs
iface wlan0-open inet dhcp
wireless-essid ANY
wireless-mode managed

如果在你那边无法工作说请报告上来.

Wi-Fi漫游

Wi-Fi对于膝上型电脑而言是最方便的。带着你的膝上型电脑云游四方同样意味着频繁的更换网络。每次当你要寻找一个不同的网络时都要改变设置是比较令人烦恼的。

为了解决这个问题,发展了很多程序,这些程序在一个网络被探测到的时候可以自动的调出你的网络接口。比较老一些的加密方法WEP已经被WPA取代了。如何设置WPA可以参考 如何设置WPA 中的关于设置wpa_supplicatiot的描述。不过wpa_supplicatiot仍然有一些关于驱动程序的争论。特别是徘徊在旧的WEP网络在wpa_supplicant中并没有获得很好的支持,因此还需参考网络上旧一些的 waproamd.

有些人也许会喜欢一个切换网络的脚本,请参看:

尽管其他人也许会喜欢用GUI工具来实现网络切换,请参看:

解决故障

参考 WiFiTroubleshooting.

有用的信息



From JBBell Sat Apr 16 18:26:15 +0100 2005 From: J B Bell Date: Sat, 16 Apr 2005 18:26:15 +0100 Subject: WEP key Message-ID: <[email protected]https://www.ubuntulinux.org>

You can also use a text-based key if you prepend it with "s:", both in the graphical interface and in the /etc/networking files.

From SoniaHamilton Sat Apr 23 04:56:37 +0100 2005 From: Sonia Hamilton Date: Sat, 23 Apr 2005 04:56:37 +0100 Subject: May need to install linux-restricted-modules Message-ID: <[email protected]https://www.ubuntulinux.org>

You may need to install linux-restricted-modules-* to get wireless going (Atheros chipset, under Hoary)

From samtygier Tue May 17 16:05:01 +0100 2005 From: sam tygier Date: Tue, 17 May 2005 16:05:01 +0100 Subject: ip address 4.2.2.2 ? Message-ID: <[email protected]>

whos ip address is this? do they mind being pinged, by people who want to check whether their dns is work? should we put the ip addess of the ubuntu homepage, or google or something else?

From WoutervanWijk Thu May 19 17:55:54 +0100 2005 From: Wouter van Wijk Date: Thu, 19 May 2005 17:55:54 +0100 Subject: gui key entry Message-ID: <[email protected]https://www.ubuntulinux.org>

I saw this about the gui wep-key entry (here http://www.ubuntulinux.org/support/documentation/faq/helpcenterfaq.2004-10-07.0031507315): One detail that was essential for me to get my laptop running on a Linksys WRT54G router: when you generate a WEP key that is 10 digits long (XXXXXXXXXX), you cannot just copy and paste this key into the WEP key field within the Network Settings dialogue. You must insert a dash after every fourth character, ie, XXXX-XXXX-XX. Once you do this, WEP encryption works fine.

This script is great! It should come standard with Ubuntu. Very out of the way and allows you to keep configuration in /etc/networking/interfaces.

The wlan-scan.sh looks really nice. However, it doesn't like ESSIDs with spaces in them, so I had to specify the MAC address of the access point insted of the ESSID because when I specified "WG 2 OG" in the map line, ifup would just complain it couldn't bring up the unknown interface eth1=eth1 or something like that.

翻译:Lucia