- 环境
- 介绍
- 使用
- 其它
介绍ubuntu20.02
Ubuntu 18.04 网络配置与Ubuntu 16.04网络配置变动较大. Ubuntu 18.04网络的配置与控制发生了很大的变化。不需要 interfaces 文件和 /etc/init.d/networking ,现在使用 Netplan。Netplan 是某些 Linux 发行版配置网络连接的命令行工具。Netplan 使用 YAML 描述文件来配置网络接口,然后,通过这些描述为任何给定的呈现工具生成必要的配置选项。
netplan 为多种后端抽象YAML网络配置. netplan在linux系统上轻松配置网络。只需网络接口的YAML描述以及各接口应配置的功能。
使用sudo vim /etc/netplan/01-netcfg.yaml
修改模板
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd # 可不配置用;Configured devices get handled by systemd-networkd by default, unless explicitly marked as managed by a specific renderer (NetworkManager)
ethernets:
# 网卡名
ens18:
# 是否使用 dhcp4
dhcp4: no
# ip 地址
addresses: [A.A.A.A/24]
# 网关
gateway4: G.G.G.G
# dns 域名解析服务器地址
nameservers:
addresses: [N.N.N.N]
# 测试配置; 应用配置,等待用户确认;如果网络中断或未给出确认,将回滚。 $ sudo netplan try # 应用渲染器的配置,根据需要重新启动它们。 $ sudo netplan apply # 如果应用失败,可以查看错误日志并调试 $ sudo netplan --debug apply其它
使用/etc/netplan来为渲染器生成所需的配置
# 生成默认配置yaml配置文件; netplan generate



