无法在 ubuntu 服务器 22.04 Raspberry Pi 中启动接口 wlan0

无法在 ubuntu 服务器 22.04 Raspberry Pi 中启动接口 wlan0

我在 Raspberry Pi 4 上安装 Ubuntu Server 22.04 后遇到问题

接口 wlan0 已关闭。

按照 ubuntu 的官方教程操作后(https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#3-wifi-or-ethernet),我无法设置接口。我已配置网络配置文件并重新启动,但无法连接。我还尝试过:

ip link set dev wlan0 up

但它拒绝设置接口。 syslog 和 dmesg 中没有任何信息。

另外,我根据给出的示例编辑了 /etc/netplan/50-cloud-init.yaml 并运行了 netplan apply,但它显示了以下错误:

/etc/netplan/50-cloud-init.yaml:12:1: Error in network definition: unknown key 'wifis'

有人知道如何解决这个问题吗?

我对 netplan 还不太熟悉

我已编辑帖子以包含以下命令的输出:ip a && cat /etc/netplan/*.yaml

# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
   valid_lft forever preferred_lft forever
inet6 ::1/128 scope host 
   valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether yy:yy:yy:yy:yy:yy brd ff:ff:ff:ff:ff:ff

# cat /etc/netplan/*.yaml   

# This file is generated from information provided by the datasource. Changes
# to it will not persist acrossan instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
    eth0:
        dhcp4: true
        optional: true
version: 2
wifis:
  wlan0:
    dhcp4: true
    optional: true
    access-point:
      "My SSID":
        password: "My Password"

答案1

您的 netplan 文件格式有很多错误。我建议:

network:   
  version: 2   
  renderer: networkd   
  ethernets:
    eth0:
      dhcp4: true
      optional: true   
  wifis:
    wlan0:
    dhcp4: true
    optional: true
    access-points:
      "My SSID":
        password: "My Password"

Netplan 对缩进和间距非常严格,因此请仔细校对两遍。/usr/share/doc/netplan/examples 中有许多 netplan 模板可供参考。

接下来是:

sudo netplan generate
sudo netplan apply

请确保您安装了 wpa-supplicant:

sudo apt update
sudo apt install wpasupplicant

答案2

我试图对此发表评论,但我没有足够的积分。但是,根据提供的答案,我相信 wlan0 条目后列出的项目应该缩进。使用所示的代码会产生与 wlan0 后缩进相关的错误。我建议进行以下更改:

network:   
  version: 2   
  renderer: networkd   
  ethernets:
    eth0:
      dhcp4: true
      optional: true   
  wifis:
    wlan0:
      dhcp4: true
      optional: true
      access-points:
        "My SSID":
          password: "My Password"

另外,我发现如果使用隐藏的 SSID,请在 SSID 条目后添加“隐藏”:例如:

  wifis:
    wlan0:
      dhcp4: true
      optional: true
      access-points:
        "My SSID":
          hidden: true
          password: "My Password"

相关内容