[原创] 在树莓派的Ubuntu MATE 18.04系统上连接WiFi

要查看更多树莓派相关文章,请点击这里

树莓派3B(V1.2)有板载WiFi模块,而Ubuntu MATE 18.04也支持它,下面来看看怎么在命令行启用。

▶▶ 修改网络配置文件,添加WiFi配置内容
cd /etc/netplan
里面只有一个文件:
01-network-manager-all.yaml
备份,然后编辑它:
sudo cp 01-network-manager-all.yaml 01-network-manager-all.yaml.bak
sudo vim.tiny 01-network-manager-all.yaml
下面的蓝色部分,是我新添加的内容:
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  # below are WiFi info
  wifis:
    wlan0:
      optional: true
      access-points:
        "MyWiFi":
          password: "my_password"
      dhcp4: true
 
其中的"wlan0"是用 iwconfig 命令得到的网卡名;"MyWiFi",则是我的无线网络的SSID;"my_password"是无线网络的密码。这些参数要根据实际情况修改。
保存文件,接着就可以测试这个配置了。
文章来源:https://www.codelast.com/
▶▶ 测试配置
sudo netplan --debug try
会输出一堆信息,部分内容如下:
DEBUG:New interfaces: set()
** (generate:1387): DEBUG: 00:07:20.808: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:1387): DEBUG: 00:07:20.809: starting new processing pass
** (generate:1387): DEBUG: 00:07:20.809: wlan0: adding wifi AP 'MyWiFi'
** (generate:1387): DEBUG: 00:07:20.809: wlan0: setting default backend to 2
** (generate:1387): DEBUG: 00:07:20.810: Configuration is valid             
** (generate:1387): DEBUG: 00:07:20.810: Generating output files..
** (generate:1387): DEBUG: 00:07:20.810: networkd: definition wlan0 is not for us (backend 2)
DEBUG:no netplan generated networkd configuration exists
DEBUG:netplan generated NM configuration changed, restarting NM
DEBUG:wlan0 not found in {}
(...中间省略...)
DEBUG:Skipping non-physical interface: lo
DEBUG:Skipping non-physical interface: eth0
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for eth0
DEBUG:netplan triggering .link rules for wlan0
Do you want to keep these settings?
(...后面省略...)
 
如果不出错的话,回车就会保存刚才添加的配置(如果不回车,过一段时间之后会自动revert到修改之前的版本)。
为确保成功,再执行一遍:
sudo netplan --debug generate
输出:
DEBUG:command generate: running ['/lib/netplan/generate']
** (generate:1579): DEBUG: 00:13:42.069: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:1579): DEBUG: 00:13:42.070: starting new processing pass
** (generate:1579): DEBUG: 00:13:42.070: wlan0: adding wifi AP 'MyWiFi'
** (generate:1579): DEBUG: 00:13:42.070: wlan0: setting default backend to 2
** (generate:1579): DEBUG: 00:13:42.070: Configuration is valid
** (generate:1579): DEBUG: 00:13:42.070: Generating output files..
** (generate:1579): DEBUG: 00:13:42.070: networkd: definition wlan0 is not for us (backend 2)
最后应用配置:
sudo netplan --debug apply
 
如果上面的命令不出错一切正常,现在可以重启树莓派了:
sudo shutdown -r now
▶▶ 一些问题
如果不能连接WiFi,要看你的树莓派能不能扫描到你在配置文件中设置的SSID,可以用下面的命令查看树莓派能扫描到哪些SSID:
sudo iw dev wlan0 scan | grep SSID
输出类似于:
SSID: ChinaNet-HG5o
SSID: ASUS-HuHu
SSID: TP-LINK_6D7F
如果你设置的SSID是公开的,并且不在这个列表中,那么树莓派就连不上了。
文章来源:https://www.codelast.com/
➤➤ 版权声明 ➤➤ 
转载需注明出处:codelast.com 
感谢关注我的微信公众号(微信扫一扫):

wechat qrcode of codelast

发表评论

电子邮件地址不会被公开。 必填项已用*标注