Play Raspberry Pi - Raspberry, wireless network configuration method

    In order to make the Raspberry Pi easy to operate, you must configure a wireless network card, which can greatly enhance the mobility and convenience of the Raspberry Pi. In fact, configuring a wireless network card is basically the same as configuring a wireless network card on an ordinary Linux platform. Several methods are similar. details as follows:

Confirm that the network card has been successfully installed

It is recommended to use a USB wireless network card with RTL8188CUS chip on the Raspberry Pi (no additional driver installation is required). Use the following command to check whether the installation is successful:

lsusb
#如果无效,查看驱动是否加载
lsmod
#如果未加载,进行加载
modprobe xxx

The first method: by configuring the /etc/network/interfaces file

sudo nano /etc/network/interfaces
The content of the modified file is as follows:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid “你的wifi名称”
wpa-psk “你的wifi密码”

The meaning of each line configuration is as follows:

auto lo //表示使用localhost
iface eth0 inet dhcp //表示如果有网卡ech0, 则用dhcp获得IP地址 (这个网卡是本机的网卡,而不是WIFI网卡)
auto wlan0 //表示如果有wlan设备,使用wlan0设备名
allow-hotplug wlan0 //表示wlan设备可以热插拨
iface wlan0 inet dhcp //表示如果有WLAN网卡wlan0 (就是WIFI网卡), 则用dhcp获得IP地址
wpa-ssid “你的wifi名称”//表示连接SSID名
wpa-psk “你的wifi密码”//表示连接WIFI网络时,使用wpa-psk认证方式,认证密码

After the above definition, if there is a network cable connection, use DHCP to automatically connect to obtain the address, use the command

sudo /etc/init.d/networking restart
sudo service networking restart    #跟上面行的作用一样。

After success, you can see the wlan0 device with the ifconfig command, and have an IP address (connected).

Sometimes you need to execute sudo ifdown wlan0 and sudo ifup wlan0 to work, if not, sudo reboot.

If you are a server, it is recommended to set a static IP

If you want to be a server, it is best to set a static IP address at startup, and add the following part to it:

iface default inet static    #将上面的iface wlan0 inet dhcp改为这一行。
address 192.168.1.2          #静态IP地址。
netmask 255.255.255.0        #IP掩码,为0的部分地址可通过。
gateway 192.168.1.1          #网关,一般就是路由器的主地址。
dns-nameservers x.x.x.x      #你的本地dns地址

The second method: modify sudo nano /etc/wpa_supplicant/wpa_supplicant.conf implementation

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
ap_scan=2
network={   
    ssid=“WIFI名称“
    proto=WPA2
    key_mgmt=WPA-PSK
    pairwise=TKIP
    group=TKIP
    psk=”WIFI密码“
    }

Then modify the file sudo nano /etc/network/interfaces, the contents of the modified file are as follows:

auto lo
iface lo inet loopback
iface eth0 inet dhcp.auto wlan0
iface wlan0 inet dhcp
pre-up wpa_supplicant -B -Dwext -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant.conf
post-down killall -q wpa_supplicant

After the modification is complete, use the following command to restart the network

sudo /etc/init.d/networking restart

After success, you can see the wlan0 device with the ifconfig command, and have an IP address (connected).

Note: We are using DHCP dynamic IP in the above two methods. If you want to set the static ip method and the method of connecting to the hidden SSID AP:

(1) Set static ip

Modify the file sudo nano /etc/network/interfaces

auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers x.x.x.x #你的本地dns地址

(2) Connect WIFI without broadcasting hidden SSID

Add a line scan_ssid=1 under ssid=”XXXX” and restart, as follows:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
ap_scan=2
network={
    ssid=“网络id“
    scan_ssid=1
    proto=WPA2
    key_mgmt=WPA-PSK
    pairwise=TKIP
    group=TKIP
    psk=”密码“}

After restarting, you can connect to the wireless network that does not broadcast the SSID.


{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324215980&siteId=291194637