随笔 - 272  文章 - 0  评论 - 283  阅读 - 142万

树莓派命令行配置无线网络

树莓派版本: Raspberry Pi 4B

操作系统 : Ubuntu Server 20.04_x64

使用 ip a 查看无线网卡名称:

复制代码
ubuntu@ubuntu:~$ 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: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether dc:a6:32:6b:bd:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.147/24 brd 192.168.1.255 scope global dynamic eth0
       valid_lft 603225sec preferred_lft 603225sec
    inet6 fe80::dea6:32ff:fe6b:bdcf/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether dc:a6:32:6b:bd:d0 brd ff:ff:ff:ff:ff:ff
ubuntu@ubuntu:~$
复制代码

eth0是有线网卡,wlan0是无线网卡,接下来改/etc/netplan/下的YAML配置文件,不同的机器文件名不一样 :

复制代码
ubuntu@ubuntu:~$ ls /etc/netplan/
50-cloud-init.yaml
ubuntu@ubuntu:~$ cat /etc/netplan/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: true
            optional: true
    version: 2
ubuntu@ubuntu:~$
复制代码

修改后的内容:

复制代码
ubuntu@ubuntu:~$ cat /etc/netplan/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: true
            optional: true
    version: 2

    wifis:
        wlan0:
            dhcp4: true
            access-points:
                "wifi的ssid":
                    password: "wifi密码"

ubuntu@ubuntu:~$
复制代码

配置生效:

ubuntu@ubuntu:~$ sudo netplan try
ubuntu@ubuntu:~$ sudo netplan apply

本文github地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2020/20200529_树莓派命令行配置无线网络.rst

欢迎补充 

posted on   Mike_Zhang  阅读(3155)  评论(1编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示