Red Hat Training
A Red Hat training course is available for RHEL 8
5.5. 使用 nmstatectl 配置 VLAN 标记
您可以使用 nmstatectl
程序配置 Virtual Local Area Network (VLAN)标记。这个示例配置了使用以太网连接 ID 10 的 VLAN。作为子设备,VLAN 连接包含 IP、默认网关和 DNS 配置。
根据您的环境,相应地调整 YAML 文件。例如,要在 VLAN 中使用网桥或绑定设备,请调整您在 VLAN 中使用的端口的 base-iface
属性和 type
属性。
先决条件
- 要将以太网设备用作 VLAN 中的端口,必须在服务器中安装物理或者虚拟以太网设备。
-
nmstate
软件包已安装。
步骤
创建包含以下内容的 YAML 文件,如
~/create-vlan.yml
:--- interfaces: - name: vlan10 type: vlan state: up ipv4: enabled: true address: - ip: 192.0.2.1 prefix-length: 24 dhcp: false ipv6: enabled: true address: - ip: 2001:db8:1::1 prefix-length: 64 autoconf: false dhcp: false vlan: base-iface: enp1s0 id: 10 - name: enp1s0 type: ethernet state: up routes: config: - destination: 0.0.0.0/0 next-hop-address: 192.0.2.254 next-hop-interface: vlan10 - destination: ::/0 next-hop-address: 2001:db8:1::fffe next-hop-interface: vlan10 dns-resolver: config: search: - example.com server: - 192.0.2.200 - 2001:db8:1::ffbb
将设置应用到系统:
# nmstatectl apply ~/create-vlan.yml
验证步骤
显示设备和连接的状态:
# nmcli device status DEVICE TYPE STATE CONNECTION vlan10 vlan connected vlan10
显示连接配置集的所有设置:
# nmcli connection show vlan10 connection.id: vlan10 connection.uuid: 1722970f-788e-4f81-bd7d-a86bf21c9df5 connection.stable-id: -- connection.type: vlan connection.interface-name: vlan10 ...
以 YAML 格式显示连接设置:
# nmstatectl show vlan0
其他资源
-
nmstatectl(8)
手册页 -
/usr/share/doc/nmstate/examples/
目录