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

Ajo*_*uve 4 server wireless networking raspberrypi

我有一个树莓派 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
Run Code Online (Sandbox Code Playgroud)

然后我运行:

sudo dhclient wlan0
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用。

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

我也尝试通过以下方式做到这一点:

iwconfig wlan0 essid name key password
Run Code Online (Sandbox Code Playgroud)

或者:

iwconfig wlan0 essid name key s:password
Run Code Online (Sandbox Code Playgroud)

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

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

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

我也尝试过wpasupplicant

创建/etc/wpa_supplicant.conf

network={
    ssid="ssid_name"
    psk="password"
}
Run Code Online (Sandbox Code Playgroud)

然后运行 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
Run Code Online (Sandbox Code Playgroud)

Ajo*_*uve 6

它工作更新 /etc/netplan/50-cloud-init.yaml

将这些行添加到 network

wifis:
    wlan0:
        optional: true
        access-points:
            "SSID-NAME":
                password: "WIFI-PASSORD"
        dhcp4: true
Run Code Online (Sandbox Code Playgroud)

然后

$ sudo netplan --debug try
$ sudo netplan --debug generate
$ sudo netplan --debug apply
Run Code Online (Sandbox Code Playgroud)

最后重新启动

$ sudo reboot
Run Code Online (Sandbox Code Playgroud)