3.6. 使用 nmstatectl 配置网络绑定


使用 nmstatectl 工具通过 Nmstate API 配置网络绑定。Nmstate API 确保设置配置后结果与配置文件匹配。如果有任何失败,nmstatectl 会自动回滚更改以避免系统处于不正确的状态。

根据您的环境,相应地调整 YAML 文件。例如,要使用与绑定中以太网适配器不同的设备,请调整您在绑定中使用的端口的 base-iface 属性和 type 属性。

先决条件

  • 在服务器中安装两个或者两个以上物理或者虚拟网络设备。
  • 要将以太网设备用作绑定中的端口,必须在服务器中安装物理或者虚拟以太网设备。
  • 要将网桥或 VLAN 设备用作绑定中的端口,请在 port 列表中设置接口名称,并定义对应的接口。
  • nmstate 软件包已安装。

流程

  1. 创建一个包含以下内容的 YAML 文件,如 ~/create-bond.yml

    ---
    interfaces:
    - name: bond0
      type: bond
      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
      link-aggregation:
        mode: active-backup
        port:
        - enp1s0
        - 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: bond0
        metric: 300
      - destination: ::/0
        next-hop-address: 2001:db8:1::fffe
        next-hop-interface: bond0
        metric: 300
    
    dns-resolver:
      config:
        search:
        - example.com
        server:
        - 192.0.2.200
        - 2001:db8:1::ffbb
    Copy to Clipboard Toggle word wrap

    这些设置使用以下设置定义网络绑定:

    • 绑定中的网络接口:enp1s0enp7s0
    • 模式: active-backup
    • 静态 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
  2. 将设置应用到系统:

    # nmstatectl apply ~/create-bond.yml
    Copy to Clipboard Toggle word wrap

验证

  1. 显示设备和连接的状态:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    bond0       bond      connected  bond0
    Copy to Clipboard Toggle word wrap
  2. 显示连接配置集的所有设置:

    # nmcli connection show bond0
    connection.id:              bond0
    connection.uuid:            79cbc3bd-302e-4b1f-ad89-f12533b818ee
    connection.stable-id:       --
    connection.type:            bond
    connection.interface-name:  bond0
    ...
    Copy to Clipboard Toggle word wrap
  3. 以 YAML 格式显示连接设置:

    # nmstatectl show bond0
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat