raspberry pi_如何通过命令行在Raspberry Pi上设置Wi-Fi

raspberry pi_如何通过命令行在Raspberry Pi上设置Wi-Fi_第1张图片

raspberry pi

raspberry pi_如何通过命令行在Raspberry Pi上设置Wi-Fi_第2张图片

You configured your headless Raspberry Pi just the way you want it, it’s settled in and running smoothly, but suddenly you want to move it away from its Ethernet tether with a Wi-Fi module. Skip hooking it back up to all the peripherals and quickly add in Wi-Fi support from the command line.

您可以按照自己的方式配置无头Raspberry Pi,它可以安放并平稳运行,但是突然之间,您想通过Wi-Fi模块将其移离以太网束缚。 跳过将其备份回所有外围设备的操作,并从命令行快速添加Wi-Fi支持。

我为什么要这样做? (Why Do I Want to Do This?)

If you’re a Raspberry Pi enthusiast (or quickly becoming one), you know how annoying it can be to realize that your headless Pi project now needs yet another little tweak that likely necessitates hooking up a monitor and keyboard/mouse to the box.

如果您是Raspberry Pi的发烧友(或很快成为一名Raspberry Pi的发烧友),您就会意识到,无头Pi项目现在需要进行另一项微调,这可能很烦人,这可能需要将显示器和键盘/鼠标连接到盒子上。

The best way to avoid falling into that trap is to configure your Raspberry Pi for remote access. Once you have that configured, however, you still need to know how to do tasks remotely that would previously be handled by a GUI interface (like turning on the Wi-Fi). Today we’re going to walk you through the technical (but simple) way to remotely connect to your Pi and activate a Wi-Fi add-on dongle.

避免陷入陷阱的最佳方法是配置Raspberry Pi进行远程访问 。 但是,一旦配置完成,您仍然需要知道如何远程执行以前由GUI界面处理的任务(例如打开Wi-Fi)。 今天,我们将向您介绍技术(但简单)的方法,以远程连接到您的Pi并激活Wi-Fi附加加密狗。

我需要什么? (What Do I Need?)

For this tutorial you’ll need the following items:

对于本教程,您需要以下各项:

  • 1 Raspberry Pi unit with Raspbian installed (this technique should work on other distributions, but we’re using Raspbian)

    1个安装了Raspbian的Raspberry Pi单元(此技术应在其他发行版上有效,但我们正在使用Raspbian)
  • 1 Ethernet connection to Pi unit (necessary for activating the Wi-Fi functionality remotely)

    1个与Pi单元的以太网连接(远程激活Wi-Fi功能所必需)
  • 1 Wi-Fi Dongle (we use this model on all our Pi units with great success)

    1个Wi-Fi加密狗(我们在所有Pi单元上都成功使用了该模型 )

If you don’t use this Wi-Fi dongle model, we strongly recommend researching the model you intend to purchase to see if it is well supported. To that end, the USB Wi-Fi adapter section of the RPi wiki is very helpful.

如果您不使用此Wi-Fi加密狗模型,我们强烈建议您研究打算购买的模型,以查看其是否受到良好支持。 为此, RPi Wiki的USB Wi-Fi适配器部分非常有帮助。

In addition to the above items, you need to take a moment to check the configuration of the Wi-Fi node you intend to connect your Raspberry Pi unit to: you’ll need to make note of the SSID, password, and encryption type/method (e.g. the node is using WPA with TKIP shared-key encryption).

除了上述各项之外,您还需要花一些时间检查要将Raspberry Pi单元连接到的Wi-Fi节点的配置:您需要记下SSID,密码和加密类型/方法(例如,节点正在将WPA与TKIP共享密钥加密一起使用)。

通过终端启用Wi-Fi加密狗 (Enabling the Wi-Fi Dongle via the Terminal)

To get started, power up your Raspberry Pi unit without the Wi-Fi dongle attached. At this point, the only network device should be the onboard Ethernet NIC (which you have connected to your network via Ethernet cable so you can remotely access the headless device).

首先,在未连接Wi-Fi加密狗的情况下启动Raspberry Pi装置。 此时,唯一的网络设备应该是板载以太网NIC(您已通过以太网电缆将其连接到网络,以便可以远程访问无头设备)。

Connect to your Pi via SSH to access a remote terminal prompt. (If you have not yet configured your device for remote access in this fashion, please review the following tutorial).

通过SSH连接到您的Pi,以访问远程终端提示。 (如果尚未将设备配置为以这种方式进行远程访问, 请查看以下教程 )。

At the prompt, enter the following command:

在提示符下,输入以下命令:

sudo nano /etc/network/interfaces

sudo nano /etc/network/interfaces

In the nano text editor, you’ll see something like this:

在nano文本编辑器中,您将看到以下内容:

auto lo

uto lo

iface lo inet loopback
iface eth0 inet dhcp

iface lo inet loopback
iface eth0 inet dhcp

That’s the very basic configuration that governs your Pi’s Ethernet connect (indicated by the eth0 portion). We need to add on a very minor bit to enable the Wi-Fi dongle. Use the arrow keys to move down below the existing entry and add the following lines:

这是控制Pi的以太网连接的最基本配置(由eth0部分指示)。 我们需要增加一点点来启用Wi-Fi加密狗。 使用箭头键向下移动到现有条目下方,并添加以下行:

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Once you’ve annotated the file, press CTRL+X to save the file and exit the nano editor. At the prompt again, enter the following command:

注释文件后,按CTRL + X保存文件并退出nano编辑器。 再次在提示符下,输入以下命令:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Compare the contents of the file, if it exists, to the following code. If the file is empty, you can use this code to populate it. Take note of the commented lines (indicated by the # marks) to reference which variable you should use based on your current Wi-Fi node configuration.

将文件内容(如果存在)与以下代码进行比较。 如果文件为空,则可以使用此代码进行填充。 记下注释行(用#号表示),以引用您应根据当前Wi-Fi节点配置使用的变量。

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="YOURSSID"
psk="YOURPASSWORD"

network={
ssid="YOURSSID"
psk="YOURPASSWORD"

# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA

# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK

# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=TKIP

# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=TKIP

#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP) auth_alg=OPEN }

#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP) auth_alg=OPEN }

When you’re done editing the file, press CTRL+X to save and exit the document. Now is the time to unplug the Ethernet cable and plug in the Wi-Fi dongle.

编辑完文件后,请按CTRL + X保存并退出文档。 现在是时候拔掉以太网电缆并插入Wi-Fi加密狗了。

At the command prompt, enter the following command:

在命令提示符下,输入以下命令:

sudo reboot

sudo reboot

When the device finishes rebooting, it should automatically connect to the Wi-Fi node. If for some reason it fails to appear on the network, you can always plug the Ethernet cable back in to double check the two files and the variables you altered.

设备完成重新启动后,它应自动连接到Wi-Fi节点。 如果由于某种原因它未能出现在网络上,则可以始终插回以太网电缆,以仔细检查两个文件和您更改的变量。

Have a Raspberry Pi related tip, trick, or a tutorial you’d love for us to write? Sound off in the comments below.

是否有Raspberry Pi相关的技巧,窍门或教程,您希望我们为我们编写? 请在下面的评论中说完。

翻译自: https://www.howtogeek.com/167425/how-to-setup-wi-fi-on-your-raspberry-pi-via-the-command-line/

raspberry pi

你可能感兴趣的:(python,linux,java,人工智能,网络)