在Ubuntu下配置netplan的步骤如下:
在Ubuntu系统中,首先需要安装netplan,可以通过以下命令进行安装:
“`
sudo aptget update
sudo aptget install netplan.io
“`
2、查看当前网络配置文件
通过以下命令查看当前系统中的网络配置文件:
“`
ls /etc/netplan/
“`
一般情况下,会看到以下几个文件:
01netcfg.yaml(主网络配置文件)
50cloudinit.yaml(云初始化网络配置文件)
51networkmanagerall.yaml(NetworkManager网络配置文件)
3、编辑网络配置文件
选择一个合适的网络配置文件,使用文本编辑器打开并进行编辑,选择01netcfg.yaml文件进行编辑:
“`
sudo nano /etc/netplan/01netcfg.yaml
“`
4、编写网络配置内容
根据实际需求,编写网络配置内容,以下是一个简单的示例:
“`
network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.2/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
version: 2
bonds:
bond0:
interfaces: [enp0s3, enp0s8]
parameters:
mode: balancerr
lacprate: fast
version: 2
bridges:
br0:
interfaces: [enp0s3, enp0s8]
gateway4: 192.168.1.1
addresses: [192.168.1.2/24]
version: 2
vlans:
vlan100:
id: 100
link: br0
addresses: [192.168.100.1/24]
version: 2
routes:
192.168.1.0/24 via 192.168.1.1 dev bond0 table bond0_routes src 192.168.1.2 table main src 192.168.1.2 metric 2032 initcwnd 100 initrwnd 100 mtu 9000 gw4e onlink off limit 65535 useprefixlength preservettl routemap bond0_routes default via 192.168.1.1 dev bond0 table bond0_routes src 192.168.1.2 table main src 192.168.1.2 metric 2032 initcwnd 100 initrwnd 100 mtu 9000 gw4e onlink off limit 65535 useprefixlength preservettl routemap bond0_routes default via 192.168.100.1 dev vlan100 table vlan_routes src 192.168.100.2 table main src 192.168.100.2 metric 2032 initcwnd 100 initrwnd 100 mtu 9000 gw4e onlink off limit 65535 useprefixlength preservettl routemap vlan_routes default via 192.168.1.1 dev bond0 table bond0_routes src 192.168.1.2 table main src 192.168.1.2 metric 2032 initcwnd 100 initrwnd 100 mtu 9000 gw4e onlink off limit 65535 useprefixlength preservettl routemap vlan_routes default via 192.168.100.1 dev vlan100 table vlan_routes src 192.168.100.2 table main src 192.168.100.2 metric 2032 initcwnd 100 initrwnd 100 mtu 9000 gw4e onlink off limit 65535 useprefixlength preservettl routemap vlan_routes default via 192.168.1.1 dev bond