Ubuntu设置固定IP地址

Posted by 刘巨 on 2020-08-26

Ubuntu基本信息

  • 版本:18.04

Ubuntu基本信息

默认网络配置信息

  • 配置文件:/etc/netplan/50-cloud-init.yaml

  • 默认配置:DHCP 自动获取IP

1
2
3
4
5
6
7
8
9
10
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# 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
version: 2

Ubuntu默认网络配置信息

设置为固定IP

  • 修改后的配置文件:/etc/netplan/50-cloud-init.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# 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: false
addresses: [10.76.20.162/24]
gateway4: 10.76.20.1
nameservers:
addresses: [114.114.114.114,8.8.8.8]
version: 2

Ubuntu固定IP配置信息

应用新的配置

1
2
#应用新的配置
netplan apply
1
2
#查看IP信息
ip addr

Ubuntu IP信息