Show Table of Contents
E.2. 配置路由和默认路由
主机可以通过两种方法获得默认路由设置。如果接口使用 DHCP,而且 DHCP 服务器提供了一个网关地址,系统会使用那个网关作为默认路由。在其它情况下,您可以使用一个静态 IP 在一个接口上设置一个默认的路由。
虽然 Linux 内核支持多个默认网关,但它只会使用 metric 值最低的那个。当有多个 DHCP 接口时,就可能会造成不可预测的默认网关。在这种情况下,推荐为不被用作默认路由使用的接口设置
defroute=no。
例如,您可能需要一个 DHCP 接口(
nic3)作为默认的路由。使用以下 YAML 禁用另外一个 DHCP 接口(nic2)上的路由:
# No default route on this DHCP interface - type: interface name: nic2 use_dhcp: true defroute: false # Instead use this DHCP interface as the default route - type: interface name: nic3 use_dhcp: true
注意
defroute 参数只会应用到通过 DHCP 获得的路由。
如需在一个接口上使用静态 IP 设置一个静态路由,为子网指定一个路由。例如,在 Internal API 网络上把到 10.1.2.0/24 子网的路由设置为使用地址为 172.17.0.1 的网关:
- type: vlan
device: bond1
vlan_id: {get_param: InternalApiNetworkVlanID}
addresses:
- ip_netmask: {get_param: InternalApiIpSubnet}
routes:
- ip_netmask: 10.1.2.0/24
next_hop: 172.17.0.1

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.