16.04以后的版本配置静态IP是类似这样的文件 /etc/netplan/50-cloud-init.yaml
查询网卡名称 ip a

修改配置文件/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.
# 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:
ens33:
dhcp4: no
dhcp6: no
addresses: [192.168.1.250/24]
optional: true
gateway4: 192.168.1.1
nameservers:
addresses: [114.114.114.114,8.8.8.8]
version: 2
执行如下命令让配置生效,静态IP就配置好了
netplan apply
********************************

在Ubuntu 18.04及更高版本中,配置静态IP需编辑/etc/netplan/50-cloud-init.yaml文件。首先通过`ip a`查询网卡名称,然后修改配置文件,例如ens33的配置包括禁用dhcp,设置IP地址、子网掩码、网关和DNS。完成修改后,运行`netplan apply`使配置生效。
934

被折叠的 条评论
为什么被折叠?



