前言
ubuntu2204操作系统通过netplan配置网络信息
配置文件:/etc/netplan/00-installer-config.yaml
命令工具:netplan
一、使用dhcp方式配置
network:
ethernets:
ens3:
dhcp4: true
version: 2
备注:要注意冒号后面要带一个空格,在使用编辑器编辑的时候,要注意格式。
二、使用手动配置方式
配置信息:
- IP:192.168.150.55
- NETMASK:24
- 网关:192.168.150.254
- DNS:114.114.114.114, 8.8.8.8
network:
ethernets:
ens3:
addresses: [192.168.150.55/24] # 设置静态IP地址和掩码
gateway4: 192.168.150.254 # 设置网关地址
dhcp4: false # 禁用dhcp
nameservers:
addresses: [114.114.114.114, 8.8.8.8] # 设置主、备DNS
version: 2
使用命令使得配置信息生效
查看命令信息
root@ubuntu:~# sudo netplan --help
usage: /usr/sbin/netplan [-h] [--debug] ...
Network configuration in YAML
options:
-h, --help show this help message and exit
--debug Enable debug messages
Available commands:
help Show this help message
apply Apply current netplan config to running system
generate Generate backend specific configuration files from /etc/netplan/*.yaml
get Get a setting by specifying a nested key like "ethernets.eth0.addresses", or "all"
info Show available features
ip Retrieve IP information from the system
set Add new setting by specifying a dotted key=value pair like ethernets.eth0.dhcp4=true
rebind Rebind SR-IOV virtual functions of given physical functions to their driver
status Query networking state of the running system
try Try to apply a new netplan config to running system, with automatic rollback
执行更新
sudo netplan apply