這兩天移植程式到樹莓派的時候遇到了一個網路方面的問題,樹莓派的有線網用靜態IP地址連接設備,無線網設定靜態IP地址連接局域網,另一臺主機wifi連接同一個局域網用ssh遠程登錄,樹莓派wifi的連接設定網上有很多,如https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
大多都設定wpa_supplicant.conf, 但因為我是安裝的Ubuntu18.05,所以這些參照這些設定都沒有解決問題,最后參考了這篇博客的內容解決https://www.cnblogs.com/MikeZhang/p/raspi-ubuntu-set-wlan-20200529.html
設定無線網路
設備版本:樹莓派4B 2G
系統:ubuntu 18.05
1、進入netplan組態檔夾
cd /etc/netplan/
2、配置無線網
sudo vim 50-cloud-init.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an 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: false
dhcp6: no
addresses: [192.168.1.111/24]
gateway4: 192.168.1.1
#nameservers:
#addresses: [114.114.114.114, 8.8.8.8]
wifis:
wlan0:
dhcp4: true
access-points:
"無線網的ssid":
password: "無線網密碼password"
version: 2
注意在冒號后面,記得要有個空格或者換行
3、啟用配置
sudo netplan try
sudo netplan apply
systemctl daemon-reload
如果配置寫得有問題,sudo netplan try 的時候會報錯,注意一下錯誤提示,一般是少了空格,少了雙引號,多了中括號之類的格式錯誤,吐槽一下這種奇怪語法格式,有的地方IP地址要用中括號括起來,有的又不用,有的“:”后面有配置內容,有的沒有,總之亂七八糟,
可能遇到的問題:
修改無線網路生效了以后可能遇到開機變慢的問題,
問題一:a start job is running for Netscript network interfaces(5min 07s )
進入系統后修改檔案
sudo vim /etc/systemd/system/network-online.target.wants/networking.service
將里面的TimeoutStartSec=5min 修改為TimeoutStartSec=2sec,
問題二:A start job is running for wait for network to be Configured(5min 07s )
修改檔案
sudo vim /etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service
在 [Service] 下,增加了一句TimeoutStartSec=2sec,
重啟樹莓派后開機就不卡了
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/226341.html
標籤:其他
上一篇:成功解決:curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to bit.ly:443
