Ubuntu20.04 網路配置
阿新 • • 發佈:2021-01-21
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