在 Ubuntu 12.04 中通过命令行配置和连接无线网络

在 Ubuntu 12.04 中通过命令行配置和连接无线网络

已检测到无线网络,但我无法连接到它们。

以下是我尝试过的代码:

sudo iwlist wlan0 scan (Working)
iwconfig wlan0 essid "Network name" key s:"key" (Error for wireless request "Set Encode" (8B2A)) SET failed on device wlan0 ; Invalid argument

wpa_passphrase essid password > /etc/wpa_supplicant.conf
wpa_supplicant -B -Dwext -iwlan0 -c/etc/wpa_supplicant.conf

ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument

ctrl_interface=/var/run/wpa_supplicant然后我尝试在文件开头添加wpa_supplicant.conf并运行相同的 wpa_supplicant 命令,但结果是

ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ctrl_iface exists and seems to be in use - cannot override it
Delete '/var/run/wpa_supplicant/wlan0' manually if it is not used anymore
Failed to initialize control interface '/var/run/wpa_supplicant'.
You may have another wpa_supplicant process already running or the file was
left by an unclean termination of wpa_supplicant in which case you will need
to manually remove this file before starting wpa_supplicant again.

如何在 Ubuntu 12.04 中通过命令行连接到指定的无线网络?

答案1

这篇简短的文章帮助我将 12.04 LTS 服务器连接到 WPA2 PSK 网络:prupert @ WordPress。我运行的服务器没有桌面,所以它要求所有 cmd 行。

我正在简要概括这些步骤,但请点击链接查看全文:

(此时你需要连接到网络)

安装软件:

(如果不是开放网络,则只需要 WPASupplicant) sudo apt-get install wireless-tools wpasupplicant

激活您的无线网络:

sudo ifconfig wlan0 up

检查无线运行:

iwconfig

然后:

sudo iwlist scan

(sacn 命令应该返回可见的无线网络,但如果没有,则表明没有可见的无线网络或您的硬件/软件存在问题,超出了链接文章的范围)

运行:(接收您的 WiFi 密钥)

wpa_passphrase YOURSSID YOURWIFIPASSWORD

生成的文本示例:(由链接文章提供)

network={
ssid="YOURSSID"
#psk="YOURWIFIPASSWORD"
psk=fe727aa8b64ac9b3f54c72432da14faed933ea511ecab1 5bbc6c52e7522f709a
}

将“psk”复制到可访问的地方,这将允许您连接到您的网络。

编辑接口文件:

sudo nano /etc/network/interfaces

使用以下选项和语法将您的 WiFi 网络附加到此文件的末尾:

auto wlan0     #change this to the name of your WiFi interface
iface wlan0 inet dhcp     #this is normally fine, if you want a static IP address replace “dhcp” with “static”
netmask 255.255.255.0     #change this as appropriate for your network, this value is usually right
gateway 192.168.1.1     #change this as appropriate for your network
address 192.168.1.100     #only needed for a static IP address
dns-nameservers 192.168.1.1     #only needed for a static IP address
wpa-driver wext     #you shouldn’t need to change this
wpa-ssid YOURSSID     #just type the name of your SSID here
wpa-ap-scan 1     #if the name of your SSID is hidden usually, type 2 instead of 1
wpa-proto WPA    #if you use WPA1 type WPA, if you use WPA2 type RSN
wpa-pairwise CCMP     #if you use AES type CCMP, if you use TKIP type TKIP
wpa-group CCMP     #if you use AES type CCMP, if you use TKIP type TKIP
wpa-key-mgmt WPA-PSK     #usually WPA-PSK (if you share a key) but sometimes WPA-EAP (for enterprises)
wpa-psk YOURHEXKEYFROMABOVE     #the hex key that you generated earlier

链接文章作者的示例:

auto wlan0
iface wlan0 inet dhcp
netmask 255.255.255.0
gateway 192.168.1.1
wpa-driver wext
wpa-ssid MYPLACE
wpa-ap-scan 1
wpa-proto WPA
wpa-pairwise CCMP
wpa-group CCMP
wpa-key-mgmt WPA-PSK
wpa-psk 71c81a844973ae7bb1243141e5caa7b6bb0e2d7eetcetcetc

您现在可以注释掉 Interfaces 文件的顶部,这将禁用以太网。本文作者建议这样做以防止冲突,但我决定不这样做,因为我可以访问我的服务器接口的唯一方法是通过 PuTTY SSH,所以如果无线连接中断,我希望有一种连接方法,这样我就不需要使用鼠标和显示器:(如果您需要以太网连接再次工作,请稍后删除“#”)

#auto eth0
#iface eth0 inet dhcp

写出文件并保存更改,重新启动计算机

如果这不起作用,您可能需要编辑 WPASupplicant 程序的配置文件:

sudo nano /etc/wpa_supplicant.conf

你可以用大部分相同的信息来编辑这个文件,除了 wpa- 部分:(下面是来自链接文档作者的示例)

ap_scan=1
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="MYPLACE"
scan_ssid=0
psk=71c81a844973ae7bb1243141e5caa7b6bb0e2d7eetcetcetc
key_mgmt=WPA-PSK
proto=WPA
pairwise=CCMP
group=CCMP
}

“据我所知,选项是相同的。因此,请根据需要编辑此文件,确保在开头添加 ctrl_interface 和 network={,并在结尾添加 } 部分。保存并尝试重新启动。如果仍然不起作用,则启动您的 PC,希望您安装了 Windows 7,然后去谷歌搜索一下。您会在 Ubuntu 论坛上找到答案,您会再次感到高兴。

相关内容