树莓派安装Ubuntu设置静态IP

Posted 儒雅随和狗粉丝

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了树莓派安装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的主要内容,如果未能解决你的问题,请参考以下文章

树莓派 ubuntu16.04 安装SSH 配置SSH 开机自启SSH

怎样给树莓派设置静态IP

(11)树莓派3 有线网卡静态IP设置

树莓派如何设置静态IP

树莓派设置静态ip

树莓派手动设置静态IP和DNS方法