树莓派安装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

大功告成!✌

树莓派安装Ubuntu设置静态IP_第1张图片

你可能感兴趣的:(#,Linux,ubuntu,linux)