树莓派安装Ubuntu设置静态IP

ubuntu系统默认登录账号和密码均为ubuntu

本例设置静态IP适用于 Ubuntu 18.04 LTS、 Ubuntu 20.04 LTS

查看 ubuntu 版本号:

// 系统版本
$ cat /etc/issue

// 内核版本
$ uname -a

查看当前ip:

$ ip addr 

$ ifconfig -a

一.网线连接,设置静态IP

修改网络配置文件

$ sudo vi /etc/netplan/50-cloud-init.yaml

设置IP地址为 192.168.1.126, 子网掩码24位即255.255.255.0, 网关为192.168.1.1, DNS1: 233.5.5.5, DNS2: 8.8.8.8

# 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: no
            addresses: [192.168.1.126/24]
            optional: true
            gateway4: 192.168.1.1
            nameservers:
                    addresses: [223.5.5.5,8.8.8.8] 
    version: 2

# 其中nameservers addresses 是配置DNS  addresses: [DNS,备用DNS] 
# gateway4 网关IP

运行命令应用新配置,立即生效

$ sudo netplan apply

二.WIFI连接(每次重新分配IP)

ubuntu@ubuntu:~$ sudo vi /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
            addresses: [192.168.2.166/22]
            gateway4: 59.72.109.254
            nameservers:
                       addresses: [10.10.10.10,10.10.10.11]


    wifis:
            wlan0:
                    dhcp4: true
                    access-points:
                        #WIFI名字
                            "B228":
                        #WIFI密码
                                password: "123456"
    version: 2

运行命令应用新配置,立即生效

$ sudo netplan apply

大功告成!✌

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值