树莓派安装ubuntu,设置静态ip,通过SSH连接

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

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

查看 ubuntu 版本号

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

// 内核版本
$ uname -a

查看当前ip

1.
$ ip addr 

2.
$ 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

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

$ sudo netplan apply

测试网络连通

$ ping 192.168.1.126
$ ping www.baidu.com

你可能感兴趣的:(DevOps,raspberry,pi,ubuntu,ssh)