11.3. 配置基于策略的路由

在 Controller 节点上,若要配置来自不同网络的无限访问,请配置基于策略的路由。基于策略的路由使用路由表,在具有多个接口的主机上,您可以根据源地址通过特定接口发送流量。您可以将来自不同源的数据包路由到不同的网络,即使目的地相同。

例如,您可以将路由配置为根据数据包的源地址将流量发送到内部 API 网络,即使默认路由用于外部网络。您还可以为每个接口定义特定的路由规则。

Red Hat OpenStack Platform 使用 os-net-config 工具为您的 overcloud 节点配置网络属性。os-net-config 工具管理 Controller 节点上的以下网络路由:

  • /etc/iproute2/rt_tables 文件中的路由表
  • /etc/sysconfig/network-scripts/rule-{ifname} 文件中的 IPv4 规则
  • /etc/sysconfig/network-scripts/rule6-{ifname} 文件中的 IPv6 规则
  • /etc/sysconfig/network-scripts/route-{ifname}中的路由表特定路由

先决条件

流程

  1. ~/templates/custom-nics 目录在自定义 NIC 模板中创建 route_tableinterface 条目,为接口定义路由,并定义与您的部署相关的规则:

    $network_config:
      network_config:
    
      - type: route_table
        name: custom
        table_id: 200
    
      - type: interface
        name: em1
        use_dhcp: false
        addresses:
          - ip_netmask: 192.0.2.1/24
    
        routes:
          - ip_netmask: 10.1.3.0/24
            next_hop: 192.0.2.5
            route_options: "metric 10"
            table: 200
        rules:
          - rule: "iif em1 table 200"
            comment: "Route incoming traffic to em1 with table 200"
          - rule: "from 192.0.2.0/24 table 200"
            comment: "Route all traffic from 192.0.2.0/24 with table 200"
          - rule: "add blackhole from 172.19.40.0/24 table 200"
          - rule: "add unreachable iif em1 from 192.168.1.0/24"
  2. run-os-net-config.sh 脚本位置设置为您创建的每个自定义 NIC 模板的绝对路径。该脚本位于 undercloud 上的 /usr/share/openstack-tripleo-heat-templates/network/scripts/ 目录中:

    resources:
      OsNetConfigImpl:
        type: OS::Heat::SoftwareConfig
        properties:
          group: script
          config:
            str_replace:
              template:
                get_file: /usr/share/openstack-tripleo-heat-templates/network/scripts/run-os-net-config.sh
  3. 在部署命令中包含自定义 NIC 配置和网络环境文件,以及与部署相关的任何其他环境文件:

    $ openstack overcloud deploy --templates \
    -e ~/templates/<custom-nic-template>
    -e <OTHER_ENVIRONMENT_FILES>

验证

  • 在 Controller 节点上输入以下命令验证路由配置是否正常工作:

    $ cat /etc/iproute2/rt_tables
    $ ip route
    $ ip rule