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

Arj*_*nti 6 command-line wireless networking 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
Run Code Online (Sandbox Code Playgroud)

然后我尝试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.
Run Code Online (Sandbox Code Playgroud)

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

小智 6

这篇短文帮助我将 12.04 LTS 服务器连接到我的 WPA2 PSK 网络:prupert @ WordPress。我在没有桌面的情况下运行服务器,因此它需要所有 cmd 行。

我正在解释这些步骤的快速细分,但请单击完整文章的链接:

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

安装软件:

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

激活您的无线网络:

sudo ifconfig wlan0 up
Run Code Online (Sandbox Code Playgroud)

检查无线运行:

iwconfig
Run Code Online (Sandbox Code Playgroud)

然后:

sudo iwlist scan
Run Code Online (Sandbox Code Playgroud)

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

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

wpa_passphrase YOURSSID YOURWIFIPASSWORD
Run Code Online (Sandbox Code Playgroud)

结果文本示例:(由链接文章提供)

network={
ssid="YOURSSID"
#psk="YOURWIFIPASSWORD"
psk=fe727aa8b64ac9b3f54c72432da14faed933ea511ecab1 5bbc6c52e7522f709a
}
Run Code Online (Sandbox Code Playgroud)

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

编辑您的接口文件:

sudo nano /etc/network/interfaces
Run Code Online (Sandbox Code Playgroud)

使用以下选项和语法将您的 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
Run Code Online (Sandbox Code Playgroud)

来自链接文章作者的示例:

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
Run Code Online (Sandbox Code Playgroud)

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

#auto eth0
#iface eth0 inet dhcp
Run Code Online (Sandbox Code Playgroud)

写出文件并保存您的更改重新启动您的机器

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

sudo nano /etc/wpa_supplicant.conf
Run Code Online (Sandbox Code Playgroud)

您使用许多相同的信息编辑此文件,但 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
}
Run Code Online (Sandbox Code Playgroud)

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