Ubuntu20.04 网络配置
设置 ROOT 密码
- 先设置 root 密码,后面直接使用 root 用户操作
it@it:~$ sudo passwd root
[sudo] password for it:
New password:
Retype new password:
passwd: password updated successfully
网络管理工具 netplan
- 在 Ubuntu20.04 版本中使用 netplan 管理网络
- 在安装好的 Ubuntu20.04 中没有 networking 和 NetworkManage 服务
- netplan 配置文件:/etc/netplan/*.yaml ,文件名每个不一样
- netplan 示例文件: /usr/share/doc/netplan/example/ 目录下,在该目录下有各种示例文件,可以提供帮助
修改网卡配置
- 编辑网络配置文件
root@it:~# vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens32:
addresses:
- 192.168.121.25/24
gateway4: 192.168.121.2
nameservers:
addresses:
- 8.8.8.8
version: 2
- 加载刚刚修改的配置文件信息
root@it:~# netplan apply
root@it:~#
root@it:~# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:16:8d:18 brd ff:ff:ff:ff:ff:ff
inet 192.168.121.25/24 brd 192.168.121.255 scope global ens32
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe16:8d18/64 scope link
valid_lft forever preferred_lft forever
netplan 帮助信息
root@it:~# netplan help
usage: /usr/sbin/netplan [-h] [--debug] ...
Network configuration in YAML #YAML中的网络配置
optional arguments:
-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 #应用当前netplan配置到运行系统
generate Generate backend specific configuration files from /etc/netplan/*.yaml #从/etc/netplan/*.yaml中生成特定后端配置文件
info Show current netplan version and available features #显示当前netplan版本和可用特性
ip Retrieve IP information from the system #从系统中检索IP信息
try Try to apply a new netplan config to running system, with automatic rollback #尝试将新的netplan配置应用到正在运行的系统,并自动回滚
- 启用调试信息
root@it:~# netplan --debug apply
** (generate:3189): DEBUG: 01:15:27.908: Processing input file /etc/netplan/00-installer-config.yaml..
** (generate:3189): DEBUG: 01:15:27.908: starting new processing pass
** (generate:3189): DEBUG: 01:15:27.908: We have some netdefs, pass them through a final round of validation
** (generate:3189): DEBUG: 01:15:27.908: ens32: setting default backend to 1
** (generate:3189): DEBUG: 01:15:27.908: Configuration is valid
** (generate:3189): DEBUG: 01:15:27.908: Generating output files..
** (generate:3189): DEBUG: 01:15:27.908: NetworkManager: definition ens32 is not for us (backend 1)
(generate:3189): GLib-DEBUG: 01:15:27.908: posix_spawn avoided (fd close requested)
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:ens32 not found in {}
DEBUG:Merged config:
network:
bonds: {}
bridges: {}
ethernets:
ens32:
addresses:
- 192.168.121.25/24
gateway4: 192.168.121.2
nameservers:
addresses:
- 8.8.8.8
vlans: {}
wifis: {}
DEBUG:Skipping non-physical interface: lo
DEBUG:device ens32 operstate is up, not changing
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for ens32