Red Hat Training
A Red Hat training course is available for RHEL 8
7.5. 使用 nmstatectl 配置网络桥接
要使用 Nmstate API 配置网桥,请使用 nmstatectl
工具。
例如,以下步骤使用以下设置在 NetworkManager 中创建桥接:
-
网桥中的网络接口:
enp1s0
和enp7s0
- Spanning Tree Protocol (STP): 启用
-
静态 IPv4 地址:
192.0.2.1
,子网掩码为/24
-
静态 IPv6 地址:
2001:db8:1::1
,子网掩码为/64
-
IPv4 默认网关:
192.0.2.254
-
IPv6 默认网关:
2001:db8:1::fffe
-
IPv4 DNS 服务器:
192.0.2.200
-
IPv6 DNS 服务器:
2001:db8:1::ffbb
-
DNS 搜索域:
example.com
先决条件
- 在服务器中安装两个或者两个以上物理或者虚拟网络设备。
- 要将以太网设备用作网桥中的端口,必须在服务器中安装物理或者虚拟以太网设备。
-
要使用团队、绑定或 VLAN 设备作为网桥中的端口,请在
port
列表中设置接口名称,并定义对应的接口。 -
nmstate
软件包已安装。
步骤
创建包含以下内容的 YAML 文件,如
~/create-bridge.yml
:--- interfaces: - name: bridge0 type: linux-bridge 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 bridge: options: stp: enabled: true port: - name: enp1s0 - name: enp7s0 - name: enp1s0 type: ethernet state: up - name: enp7s0 type: ethernet state: up routes: config: - destination: 0.0.0.0/0 next-hop-address: 192.0.2.254 next-hop-interface: bridge0 - destination: ::/0 next-hop-address: 2001:db8:1::fffe next-hop-interface: bridge0 dns-resolver: config: search: - example.com server: - 192.0.2.200 - 2001:db8:1::ffbb
将设置应用到系统:
# nmstatectl apply ~/create-bridge.yml
验证步骤
显示设备和连接的状态:
# nmcli device status DEVICE TYPE STATE CONNECTION bridge0 bridge connected bridge0
显示连接配置集的所有设置:
# nmcli connection show bridge0 connection.id: bridge0 connection.uuid: e2cc9206-75a2-4622-89cf-1252926060a9 connection.stable-id: -- connection.type: bridge connection.interface-name: bridge0 ...
以 YAML 格式显示连接设置:
# nmstatectl show bridge0
其他资源
-
nmstatectl(8)
手册页 -
/usr/share/doc/nmstate/examples/
目录 - 如何使用 vlan 信息配置网桥?