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}
中的路由表特定路由
先决条件
- 您已成功安装 undercloud。如需更多信息,请参阅 Director 安装和使用指南中的安装 director。https://access.redhat.com/documentation/zh-cn/red_hat_openstack_platform/16.2/html-single/director_installation_and_usage/index#installing-the-undercloud
-
您已从
openstack-tripleo-heat-templates
目录中呈现了默认的.j2
网络接口模板。更多信息请参阅 第 10.2 节 “呈现用于自定义的默认网络接口模板”。
流程
从
~/templates/custom-nics
目录在自定义 NIC 模板中创建route_table
和interface
条目,为接口定义路由,并定义与您的部署相关的规则:$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"
将
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
在部署命令中包含自定义 NIC 配置和网络环境文件,以及与部署相关的任何其他环境文件:
$ openstack overcloud deploy --templates \ -e ~/templates/<custom-nic-template> -e <OTHER_ENVIRONMENT_FILES>
验证
在 Controller 节点上输入以下命令验证路由配置是否正常工作:
$ cat /etc/iproute2/rt_tables $ ip route $ ip rule