Linux如何配置无线网络

  • 格式:docx
  • 大小:22.27 KB
  • 文档页数:16

Linux如何配置无线网络

目前您可以使用我们提供的wireless-tools 或wpa_supplicant工具来配置无线网络。请记住重要的一点是,您对无线网络的配置是全局性的,而非针对具体的接口。

wpa_supplicant是一个最好的选择,但缺点是它不支持所有的驱动。请浏览wpa_supplicant网站获得它所支持的驱动列表。另外,wpa_supplicant目前只能连接到那些你已经配置好ESSID的无线网络。

wireless-tools支持几乎所有的无线网卡和驱动,但它不能连接到那些只支持WPA的AP。

WPA Supplicant工具包可以让您连接到那些使用WPA的AP。因为还只是beta版,所以它的配置方法仍会常常变化——尽管如此,在大部分情况下它已经能很好的工作。

我们还需要配置wpa_supplicant本身,这将会比较麻烦一些,具体取决于你要连接的AP的安全程度。下面的例子是从/usr/share/doc/wpa_supplicant-/wpa_supplicant.conf.gz中抽取并简化而来的,此文件出自wpa_supplicant软件包。

代码 2.3: 一个/etc/wpa_supplicant/wpa_supplicant.conf的例子

# 请不要修改下面这一行内容,否则将不能正常工作

ctrl_interface=/var/run/wpa_supplicant

# 确保只有root用户能读取WPA的配置

ctrl_interface_group=0

# 使用wpa_supplicant来扫描和选择AP

ap_scan=1

# 简单的情形:WPA-PSk密码验证方式,PSK是ASCII密码短语,所有合法的加密方式都允许连接

network={

ssid="simple"

psk="very secret passphrase"

# 优先级越高,就能越早匹配到。

priority=5

}

# 与前面的设置相同,但要求对特定的SSID进行扫描(针对那些拒绝广播SSID的AP)

network={

ssid="second ssid"

scan_ssid=1

psk="very secret passphrase"

priority=2

}

# 仅使用WPA-PSK方式。允许使用任何合法的加密方式的组合

network={

ssid="example"

proto=WPA

key_mgmt=WPA-PSK

pairwise=CCMP TKIP

group=CCMP TKIP WEP104 WEP40

psk=06b4be19da289f475aa46a33cb793029d4ab3db7a23ee92382eb0106c72ac7bb

priority=2

}

# 明文连接方式(不使用WPA和IEEE802.1X)

network={

ssid="plaintext-test"

key_mgmt=NONE

}

# 共享WEP秘钥连接方式(不使用WPA和IEEE802.1X)

network={

ssid="static-wep-test"

key_mgmt=NONE

wep_key0="abcde"

wep_key1=0102030405

wep_key2="1234567890123"

wep_tx_keyidx=0

priority=5

}

# 共享WEP秘钥连接方式(无WPA和IEEE802.1X),使用共享秘钥IEEE802.11验证方式

network={

ssid="static-wep-test2"

key_mgmt=NONE

wep_key0="abcde"

wep_key1=0102030405

wep_key2="1234567890123"

wep_tx_keyidx=0

priority=5

auth_alg=SHARED

}

# 在IBSS/ad-hoc网络中使用WPA-None/TKIP

network={

ssid="test adhoc"

mode=1

proto=WPA

key_mgmt=WPA-NONE

pairwise=NONE

group=TKIP

psk="secret passphrase"

}

命令执行例子:

wpa_supplicant -B -ieth0 -c /etc/wpa_supplicant.conf

获得地址:

dhcpcd eth0

察看网卡状态以及参数:

bt ~ # iwconfig eth0

eth0 IEEE 802.11g ESSID:"youssid"

Mode:Managed Frequency:2.462 GHz Access Point:

00:00:00:00:00:00

Bit Rate:54 Mb/s Tx-Power:14 dBm

Retry limit:15 RTS thr:off Fragment thr:off

Encryption key:xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx Security mode:open

Power Management:off

Link Quality=74/100 Signal level=-57 dBm Noise level=-57

dBm

Rx invalid nwid:0 Rx invalid crypt:1 Rx invalid frag:0

Tx excessive retries:0 Invalid misc:21 Missed beacon:0

bt ~ # ifconfig eth0

eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx

inet

addr:192.168.2.100 Bcast:192.168.2.255 Mask:255.255.255.0

inet6 addr: fe80::218:deff:feb0:38e5/64 Scope:Link

UP BROADCAST NOTRAILERS RUNNING

MULTICAST MTU:1500 Metric:1

RX packets:33 errors:2 dropped:31 overruns:0 frame:0

TX packets:12 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:11177 (10.9 KiB) TX bytes:4324 (4.2 KiB)

Interrupt:11 Base address:0x2000 Memory:edf00000-edf00fff

这样linux就可以使用wpa 访问无线网络了.

---------------------------------------------------

wpa_supplicant usage

---------------------------------------------------

You will need to make a configuration file, e.g.,

/etc/wpa_supplicant.conf, with network configuration for the

networks

you are going to use. Configuration file section below

includes

explanation for the configuration file format and includes

various

examples. Once the configuration is ready, you can test

whether the

configuration work by first running wpa_supplicant with

following command to start it on foreground with debugging enabled:

wpa_supplicant -i wlan0 -c/etc/wpa_supplicant.conf -d

Assuming everything goes fine, you can start using following

command

to start wpa_supplicant on background without debugging:

wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -B

Please note that if you included more than one driver

interface in the

build time configuration (.config), you may need to specify

which

interface to use by including -D option on the command

line. See following section for more details on command line

options

for wpa_supplicant.

Command line options

--------------------

usage:

wpa_supplicant [-BddehLqqvw] -i -c [-D] \

[-N -i -c [-D] ...]

options:

-B = run daemon in the background