将带有 ubuntu 服务器的 raspberry pi 4 连接到 wifi

将带有 ubuntu 服务器的 raspberry pi 4 连接到 wifi

我有一台 Raspberry Pi 4。

由于我没有可用的屏幕和键盘,因此我通过以太网电缆连接它。

我希望 Raspberry Pi 连接到 Wi-Fi,而不是通过以太网。

我尝试更新/etc/network/interfaces至:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
wpa-essid MYESSID12345
wpa-psk MYPASSWORD$1234567

然后我跑:

sudo dhclient wlan0

但它似乎不起作用。

ifconfig返回:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.41  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::dea6:32ff:fe62:c4fc  prefixlen 64  scopeid 0x20<link>
        ether dc:a6:32:62:c4:fc  txqueuelen 1000  (Ethernet)
        RX packets 118  bytes 13529 (13.5 KB)
        RX errors 0  dropped 52  overruns 0  frame 0
        TX packets 63  bytes 9012 (9.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 168  bytes 12300 (12.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 168  bytes 12300 (12.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether dc:a6:32:62:c4:fd  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

我也尝试过通过以下方式来实现:

iwconfig wlan0 essid name key password

或者:

iwconfig wlan0 essid name key s:password

但是我出现无效参数错误,因为我的密码是 8 个字符。

Error for wireless request "Set Encode" (8B2A) :
    SET failed on device wlan0 ; Invalid argument.

我也尝试过iwconfig wlan0 essid name使用 wps 但是不起作用。

我也尝试过wpasupplicant

创造/etc/wpa_supplicant.conf

network={
    ssid="ssid_name"
    psk="password"
}

然后运行sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D wext

但我也有错误。

Successfully initialized wpa_supplicant
ioctl[SIOCSIWENCODEEXT]: Invalid argument
ioctl[SIOCSIWENCODEEXT]: Invalid argument

答案1

它正在更新/etc/netplan/50-cloud-init.yaml

将这些行添加到network

wifis:
    wlan0:
        optional: true
        access-points:
            "SSID-NAME":
                password: "WIFI-PASSORD"
        dhcp4: true

然后

$ sudo netplan --debug try
$ sudo netplan --debug generate
$ sudo netplan --debug apply

最后重新启动

$ sudo reboot

答案2

我在 RPi4B 上通过 Unbuntu 20.04 获得了无头 Wi-Fi,无需禁用 cloud-init。简而言之,我将其用于我的网络配置:


# This file contains a netplan-compatible configuration which cloud-init
# will apply on first-boot. Please refer to the cloud-init documentation and
# the netplan reference for full details:
#
# https://cloudinit.readthedocs.io/
# https://netplan.io/reference
#

#Replace the entire user-data on the imaged SD Card with this file.

version: 2
renderer: networkd
wifis:
  wlan0:
    dhcp4: true
    dhcp6: true
    optional: true
    access-points:
      "SSID":
         password: "PassPhrase"

然后,我将以下内容附加到用户数据的末尾:

power_state:
  mode: reboot

我的配置文件、分步说明和注释在这里:https://github.com/DavidUnboxed/Ubuntu-20.04-WiFi-RaspberyPi4B

答案3

尝试更新/etc/network/interfaces至:

auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant.conf

创建/etc/wpa_supplicant.conf

network={
    ssid="ssid_name"
    psk="password"
}

然后运行sudo wpa_supplicant -B -iwlan0 -Dwext -c/etc/wpa_supplicant.conf && sudo dhclient wlan0

或者尝试更新/etc/network/interfaces到:

auto wlan0
iface wlan0 inet dhcp
    wpa-ssid YOUR-SSID-HERE
    wpa-psk YOUR-PASSWORD-HERE

然后重新启动。

相关内容