树莓派3B装ubuntu server后开启wifi

 

树莓派官网选择ubuntu server下载映像

step 1:

  使用SDFormatter格式化SD卡;

step2:

  使用win32diskimager工具将映像写入准备好的SD卡;

step3:

  插入键盘电源和HDMI线链接TV,开电,login界面出现后输入用户名和密码 ubuntu ,重置密码。

step4:

  由于ubuntu server没有安装iwconfig工具,需要找根网线连接有线网络,安装 wireless-tools:

  sudo apt install wireless-tools

 

wireless-tools安装完后,就可以使用iwconfig按下面步骤设置无线网络了:

1、首先设置打开无线网卡并设置SSID

1 sudo iwconfig wlan0 power on
2 sudo ifconfig wlan0 up
3 sudo iwconfig wlan0 essid "无线名称"

 

2、然后使用wpa_passphrase生成无线密钥

 

1 sudo -i 
2 wpa_passphrase 无线名称 密码 > /etc/wpa_supplicant.conf

 

3、接下来编辑 /etc/wpa_supplicant.conf

1 sudo vi /etc/wpa_supplicant.conf
  

确保文件内容如下:
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
ap_scan=1
network={
        ssid="OpenWrt_2.4G_4680A1"
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP TKIP
        group=CCMP TKIP
        psk=0192c3b3469fcf872387c0e069fee5731ce7f8782654e1a5caa0c165700e76c8
}

 

!!!注意配置关键点说明如下:

network={
        ssid="my_network"   #注意ssid名区分大小写。
        proto=RSN           #Robust Security Network:强健安全网络,表示这个网络配置比WEP模式要更安全。
        key_mgmt=WPA-PSK    #请无论你是使用WPA-PSK,WPA2-PSK,都请在这里输入 WPA-PSK。这在wpa_supplicant看来WPA-PSK,WPA2-PSK都是 WPA-PSK
        pairwise=CCMP TKIP  #关键点,wpa_supplicant目前还不认AES的加密标准
        group=CCMP TKIP     #同上
        psk=7b271c9a7c8a6ac07d12403a1f0792d7d92b5957ff8dfd56481ced43ec6a6515 #wpa_supplicant算出来的加密密码。

 

4、以上配置文件设置完成后,接下来手动应用配置

1 sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
2 sudo dhclient wlan0

 

5、为了开机自动开启wifi,需要将启动脚本加到自动执行服务中,首先在/etc/rc.local中加入如下脚本:

#!/bin/bash
ip link set wlan0 up &&
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf &&
dhclient wlan0
exit 0

 

并修改rc.local为可执行:

chmod a+x /etc/rc.local

 

然后编辑 /lib/systemd/system/rc-local.service加入如下配置:

[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionPathExists=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
Alias=rc-local.service

 

6、设置开机默认启动rc-local.service.

执行下面命令后自动在/etc/systemd/system下创建rc-local.service到 /lib/systemd/system/rc-local.service的软链接。

systemctl enable rc-local.service

 

7、最后验证下服务能否正常开启运行

systemctl start rc-local.service &&
system status rc-local.service

 

如果出现下面信息,就ok了,这样就可以实现开机自动连接wifi了。

root@ubuntu:~# systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: active (running) since Fri 2019-10-25 16:03:17 UTC; 26min ago
     Docs: man:systemd-rc-local-generator(8)
  Process: 1621 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
    Tasks: 2 (limit: 1056)
   CGroup: /system.slice/rc-local.service
           ├─1627 wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
           └─1647 dhclient wlan0

Oct 25 16:03:14 ubuntu systemd[1]: Starting /etc/rc.local Compatibility...
Oct 25 16:03:14 ubuntu rc.local[1621]: Successfully initialized wpa_supplicant
Oct 25 16:03:17 ubuntu dhclient[1628]: DHCPREQUEST of 192.168.1.33 on wlan0 to 255.255.255.255 port 67 (xid=0x2399ec15)
Oct 25 16:03:17 ubuntu dhclient[1628]: DHCPACK of 192.168.1.33 from 192.168.1.1Oct 25 16:03:17 ubuntu dhclient[1628]: bound to 192.168.1.33 -- renewal in 32671 seconds.
Oct 25 16:03:17 ubuntu systemd[1]: Started /etc/rc.local Compatibility.

 

posted @ 2019-10-24 00:10  梦想与现实边缘  阅读(6600)  评论(0编辑  收藏  举报