18.04上新采用的netplan命令。网卡信息配置在/etc/netplan/50-cloud-init.yaml文件,需做如下配置,
root@fsdsoyu:/etc/netplan# cat 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:
enp9s0:
addresses: [192.168.11.103/24]
gateway4: 192.168.11.1
nameservers:
addresses: [192.168.11.1]
dhcp4: false
version: 2
然后使用以下命令使配置即时生效,
netplan apply
以上操作均在root用户下进行,如在普通用户,请自行加上sudo。
ip配置信息要按如上格式,使用yaml语法格式,每个配置项使用空格缩进表示层级;
对应配置项后跟着冒号,之后要接个空格,否则netplan命令也会报错。
网友评论