mrlesmithjr.frr

目录 DocToc 生成

ansible-frr

Ansible 角色,用于安装/配置 FRR

注意:FRRouting (FRR) 是一个适用于 Linux 和 Unix 平台的 IP 路由协议套件,其中包括 BFD、BGP、IS-IS、LDP、OSPF、PIM 和 RIP 的协议守护进程。

构建状态

GitHub Actions

Molecule 测试

Travis CI

构建状态

要求

有关所需 Ansible 角色的详细信息,请查看: requirements.yml

角色变量

defaults/main.yml

依赖项

示例剧本

playbook.yml

路由映射和前缀列表

路由映射

配置路由映射

以下是路由映射配置的示例:

frr_route_map:
  RTBH:
    permit 10:
      interface: blackhole
      prefix_list: Bad_IPs
      origin: igp
      community: "12345:100"
      src: 2001:db8::bf03
  RTBH_IN:
    deny 10: []

常规选项

IP/IPv6 转发

以下是启用 IP 和 IPv6 转发的示例:

frr_ip_forwarding: true
frr_ipv6_forwarding: true

要启用内核转发,此角色设置了 sysctl 变量 net.ipv4.ip_forwardnet.ipv6.conf.all.forwarding。要自定义 sysctl 配置的位置,可以使用以下变量:

frr_sysctl_file: /etc/sysctl.d/100-ansible-frr.conf

默认路由下的下一跳跟踪

通过默认路由解析下一跳; 如果 BGP 对等体仅通过默认网关可达,则此项非常有用(默认情况下禁用)。

要启用:

frr_nht_resolve_default: true

前缀列表

配置前缀列表

以下是前缀列表配置的示例:

frr_prefix_list:
  Bad_IPs:
    05 permit:
      prefix: 192.168.88.0/24
      match: ge 32
    10 permit:
      prefix: 172.16.0.0/16
      match: le 32
frr_prefix_list_v6:
  Bad_IPs:
    05 permit:
      prefix: 1234:5678::/32
      match: ge 128

访问列表

配置访问列表

以下是一个示例

frr_access_list:
  - "10 permit 10.10.10.21/32"
  - "10 permit 192.168.0.0/17"
  - "101 permit ip 10.0.0.0 0.0.0.255 any"

双向转发检测(BFD)

启用 BFD

要启用 BFD,请确保在以下设置中配置 bfdd: true

frr_daemons:
  bfdd: true
  bgpd: false
  isisd: false
  ldpd: false
  nhrpd: false
  ospf6d: false
  ospfd: false
  pimd: false
  ripd: false
  ripngd: false
  zebra: true

配置 BFD

在 BGP 对等体设置下进行 BFD 配置。当前不支持 OSPF 的 BFD。

支持的路由协议

协议 实现 备注
BGP X 仅初始配置
OSPF X 仅初始配置
静态 X 仅初始配置

BGP

启用 BGP

要启用 BGP 路由,请确保在以下设置中配置 bgpd: true

frr_daemons:
  bfdd: false
  bgpd: false
  isisd: false
  ldpd: false
  nhrpd: false
  ospf6d: false
  ospfd: false
  pimd: false
  ripd: false
  ripngd: false
  zebra: true

配置 BGP

要配置 BGP,请根据您的需求定义以下内容:

frr_bgp:
  asns:
    65000:
      log_neighbor_changes: true
      no_ebgp_requires_policy: true
      timers: '3 9'
      other:
        - "bgp bestpath as-path multipath-relax"
        - "no bgp network import-check"
      neighbors:
        group1:
          asn: 66000
          is_peer_group: true
          multihop: 255
        192.168.250.11:
          asn: 65000
          default_originate: false
          description: node1
          next_hop_self: true
          timers_connect: 5
          v6only: true
          bfd_peer: true
          bfd_peer_detect_multiplier: 3
          bfd_peer_receive_interval: 50
          bfd_peer_transmit_interval: 50
          bfd_peer_echo_interval: 50
          bfd_peer_passive_mode: true
          bfd_peer_minimum_ttl: 253
          other:
            - "capability dynamic"
        192.168.250.12:
          asn: 65000
          default_originate: false
          description: node2
          next_hop_self: true
          v4_route_reflector_client: true
          password: secret
          bfd_peer: true
          bfd_peer_transmit_interval: 2000
          bfd_peer_echo_mode: true
          other:
            - "prefix-list Bad_IPs in"
        192.168.250.12:
          peer_group: group1
          description: far_away
      listen_range:
        192.168.250.0/24: group1
      networks:
        - "{{ frr_router_id }}/32"
        - "{{ hostvars[inventory_hostname]['ansible_enp0s8']['ipv4']['address'] }}/24"
      redistribute:
        - bgp
        - connected
        - kernel
        - ospf
        - static
      redistribute_v6:
        - bgp
        - connected
        - kernel

示例 BGP

以下是 BGP 配置的示例:

frr_bgp:
  asns:
    65000:
      log_neighbor_changes: true
      af_v4:
        - "maximum-paths 2"
      af_v6:
        - "maximum-paths 2"
      af_evpn:
        - "advertise-all-vni"
        - "rd {{ frr_router_id }}:1"
      neighbors:
        192.168.250.11:
          asn: 65000
          default_originate: false
          description: node1
          next_hop_self: true
          af_v4:
            - "soft-reconfiguration inbound"
        192.168.250.12:
          asn: 65000
          default_originate: false
          description: node2
          next_hop_self: true
        "::1":
          asn: 65000
          default_originate: false
          description: node1
          next_hop_self: true
          af_v6:
            - "activate"
            - "soft-reconfiguration inbound"
        172.16.250.10:
          asn: internal
          timers_connect: 5
          description: "L2VPN EVPN neighbor"
          af_evpn:
            - "activate"
          other:
            - "capability extended-nexthop"
      networks:
        - "{{ frr_router_id }}/32"
        - "{{ hostvars[inventory_hostname]['ansible_enp0s8']['ipv4']['address'] }}/24"
        - "{{ hostvars[inventory_hostname]['ansible_enp0s9']['ipv4']['address'] }}/24"
        - "{{ hostvars[inventory_hostname]['ansible_enp0s10']['ipv4']['address'] }}/24"
        - "{{ hostvars[inventory_hostname]['ansible_enp0s16']['ipv4']['address'] }}/24"
      networks_v6:
        - "1::3/64"

以下是基于上述配置的 BGP 摘要示例:

BGP 表版本为 13,本地路由器 ID 为 1.1.1.1
状态代码:s 被抑制,d 被抑制,h 历史,* 有效,> 最佳,= 多路径,
              i 内部,r RIB 失败,S 过时,R 被移除
来源代码:i - IGP,e - EGP,? - 不完整

   网络            下一跳               指标 LocPrf 权重 路径
*> 1.1.1.1/32       0.0.0.0                  0         32768 i
*>i2.2.2.2/32       192.168.250.11           0    100      0 i
*>i3.3.3.3/32       192.168.250.12           0    100      0 i
*> 192.168.10.0     0.0.0.0                  0         32768 i
*>i192.168.11.0     192.168.250.11           0    100      0 i
*>i192.168.12.0     192.168.250.12           0    100      0 i
*> 192.168.20.0     0.0.0.0                  0         32768 i
*>i192.168.21.0     192.168.250.11           0    100      0 i
*>i192.168.22.0     192.168.250.12           0    100      0 i
*> 192.168.30.0     0.0.0.0                  0         32768 i
*>i192.168.31.0     192.168.250.11           0    100      0 i
*>i192.168.32.0     192.168.250.12           0    100      0 i
* i192.168.250.0    192.168.250.11           0    100      0 i
* i                 192.168.250.12           0    100      0 i
*>                  0.0.0.0                  0         32768 i

显示了 13 路由和 15 条总路径

OSPF

启用 OSPF

要启用 OSPF 路由,请确保在以下设置中配置 ospfd: true

frr_daemons:
  bfdd: false
  bgpd: false
  isisd: false
  ldpd: false
  nhrpd: false
  ospf6d: false
  ospfd: false
  pimd: false
  ripd: false
  ripngd: false
  zebra: true

配置 OSPF

要配置 OSPF,请根据您的需求定义以下内容:

frr_ospf:
  areas:
    0:
      networks:
        - "{{ frr_router_id }}/32"
    1:
      networks:
        - "{{ hostvars[inventory_hostname]['ansible_enp0s8']['ipv4']['address'] }}/24"
      auth: true

    2:
      networks:
        - "{{ hostvars[inventory_hostname]['ansible_enp0s9']['ipv4']['address'] }}/24"
      type: nssa

  log_adjacency_changes: true
  passive_interfaces: # 设置被动的接口列表
    - default
  redistribute: # 需要重新分发的协议列表
    - bgp
    - connected
    - kernel
    - ospf
    - static
  distribute_list:
    - name: 10
      dir: out
      protocol: connected

VRF 感知的 OSPF

每个键下的frr_ospf_vrf_enabled代表 VRF 名称:

frr_ospf_vrf_enabled:
  public:
    redistribute:
    - bgp
    - connected
    passive_interfaces:
     - lo
    log_adjacency_changes: true
    areas:
      1:
        networks:
          - "{{ hostvars[inventory_hostname]['ansible_ens3']['ipv4']['address'] }}/30"
        auth: true
  mgmt:
    redistribute:
      - kernel
    areas:
      0:
        networks:
          - 172.16.0.0/12
      2:
        networks:
          - 192.168.0.0/16
        type: nssa

静态路由

配置静态路由

要配置静态路由,请根据您的需求定义以下内容:

frr_static: # 字典,键 = 目的地,值 = 下一跳
  10.0.0.0/8: 192.168.1.1
  1.1.1.1: 192.168.1.1
  1.1.1.2: blackhole
frr_static_v6: # 字典,键 = 目的地,值 = 下一跳
  2001:0db8:85a3:8a2e::/64 2001::1

接口配置

接口

frr_interfaces: # 字典,键 = 接口名称,值 = 接口数据
  lo:
    ip: 10.0.0.0/32 # ip 可以是单个值或列表
    ipv6: 2001:0db8:85a3:8a2e::1/64 # ipv6 可以是单个值或列表
    description: loopback
  eth0:
    ip: # ip 可以是单个值或列表
      - 10.0.0.0/32
      - 172.16.0.0/32
    ipv6: # ipv6 可以是单个值或列表
      - 2001:0db8:85a3:8a2e::1/64
      - 2001:0db8:85a3:8a2e::2/64
    vrf: management # 将接口放置在 'management' VRF 中
    auth:
      id: 1
      key: supersecret
    other:
      - "no ipv6 nd suppress-ra"
      - "link-detect"

注意:设备应该在每个 VRF 感知的接口上拥有正确的 VRF 分配:

ip link set dev ${IFACE} master ${VRF}

升级/降级

注意:FRR 不能通过此角色从 6.0.2 降级。

您可以通过设置以下变量来升级或降级 FRR:

frr_version: 6.0.2frr_version: 6.0

Quagga 配置

注意:Quagga 必须从操作系统的本地仓库中安装。

您可以使用以下变量配置 quagga,而不是 FRR:

routing_type: quagga

其他 Quagga 特定的配置

frr_bgp:
  asns:
    65000:
      neighbors:
        swp1:
          **interface: true**

许可证

MIT

作者信息

Larry Smith Jr.

请我喝杯咖啡

注意:仓库是使用 https://github.com/mrlesmithjr/cookiecutter-ansible-role 作为模板创建/更新的。

关于项目

Ansible role to install/configure [FRR](https://frrouting.org/)

安装
ansible-galaxy install mrlesmithjr.frr
许可证
mit
下载
102.6k
拥有者
Doing my thang with #automation #DevOps and cloudy things! Providing hopefully valuable content for others to consume easily and also learn from.