樹莓派 ubuntu 命令列配置wlan wifi 親測有效(轉自:How to set up WIFI on Ubuntu running on the Raspberry Pi 4)
轉自:https://oastic.com/posts/how-to-set-up-wifi-on-ubuntu-running-on-the-raspberry-pi-4/
test @
pi 400
ubuntu-18.04.5-preinstalled-server-arm64+raspi4.img.xz
(不要勾選skip first-run wizard,否則裝os不成功)
正文:
不用裝net-tools
注意
network:
version: 2
renderer: networkd
wifis:
wlan0:
dhcp4: yes
dhcp6: no
access-points:
"<your network ESSID>":
password: "<your WIFI Password>"
注意:可能忘記 wifis:下面寫wlan0
How to set up WIFI on Ubuntu running on the Raspberry Pi 4
April 2, 2020·2 min·Yvoictra|- Translations:
- Es
First step is to check the status of the interfaces. For this, we will use thenet-toolspackage.
sudo apt install net-tools
Then, we can see the interfaces status
ifconfig -a
In my case, I have this status of my interface wlan0:
ubuntu@ubuntu:~$ ifconfig -a wlan0
wlan0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether dc:a6:32:6c:xx:xx 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
In the flags only there are 2(BROADCAST,MULTICAST), but there is no “UP” flag.
In order to configure the WIFI network, I recommend to use the programnetplan, available from Ubuntu 18.04. It doesn’t require any additional installation, it comes with the base system.
For the wireless configuration, you may follow the example:
/usr/share/doc/netplan/examples/wireless.yaml
so next step is to copy the file in the directory/etc/netplan/
sudo cp /usr/share/doc/netplan/examples/wireless.yaml /etc/netplan/
Then, edit the new file created and change the values. Probably you want to enable dhcp configuration and remove static parts. In my case, the file looks like this:
network:
version: 2
renderer: networkd
wifis:
wlan0:
dhcp4: yes
dhcp6: no
access-points:
"<your network ESSID>":
password: "<your WIFI Password>"
Last step is to execute the netplan
sudo netplan try
As an alternative, you could modify the existing file/etc/netplan/50-cloud-init.yaml
which is created by default. In this file you could add the WIFI configuration.
network:
version: 2
ethernets:
eth0:
dhcp4: true
optional: true
wifis:
wlan0:
dhcp4: true
dhcp6: false
access-points:
"<your network ESSID>":
password: "<your WIFI Password>"
Last step is to execute the netplan
sudo netplan try
After this, your WIFI should be established. You could check it with ifconfig tool:
ubuntu@ubuntu:~$ ifconfig -a wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.220 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::dea6:32ff:fe6c:xxxx prefixlen 64 scopeid 0x20
ether dc:a6:32:6c:xx:xx txqueuelen 1000 (Ethernet)
RX packets 5047 bytes 936652 (936.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 78 bytes 9491 (9.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
And now the flags UP and RUNNING are set.