FRR配置实例
环境:centos 7.6.1810
版本:FRR 7.3
服务器: 1台
Namespace配置实例
FRR的vrf功能支持同一个进程在不同ns内创建bgp对等体。首先需要配置zebra支持backend方式为ns
[root@k8s-master ~]# cat /usr/local/frr/etc/daemons |grep zebra
# The watchfrr and zebra daemons are always started.
zebra_options=" -A 127.0.0.1 -s 90000000 -n"
拓扑网络
我们在一台服务器上创建ns1和ns2,并创建veth pair分别绑定到ns1和ns2,使得两者的网络直连,然后使用vrf功能在ns1和ns2上创建对等体关系,并分别向对方通告虚拟路由。

网络设置
ip netns add ns1
ip netns add ns2
ip link add veth_ns2 type veth peer name veth_ns1
#去掉ARP限制
echo 1 > /proc/sys/net/ipv4/conf/veth_ns1/accept_local
echo 1 > /proc/sys/net/ipv4/conf/veth_ns2/accept_local
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/veth_ns2/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/veth_ns1/rp_filter
ip link set veth_ns1 netns ns1
ip netns exec ns1 ip link set veth_ns1 up
ip netns exec ns1 ip addr add 10.10.1.2/24 dev veth_ns1
ip link set veth_ns2 netns ns2
ip netns exec ns2 ip link set veth_ns2 up
ip netns exec ns2 ip addr add 10.10.1.4/24 dev veth_ns2
测试网络连通性:
[root ~]# ip netns exec ns1 ping 10.10.1.4
PING 10.10.1.4 (10.10.1.4) 56(84) bytes of data.
64 bytes from 10.10.1.4: icmp_seq=1 ttl=64 time=0.275 ms
64 bytes from 10.10.1.4: icmp_seq=2 ttl=64 time=0.091 ms
64 bytes from 10.10.1.4: icmp_seq=3 ttl=64 time=0.057 ms
64 bytes from 10.10.1.4: icmp_seq=4 ttl=64 time=0.093 ms
BGP设置
[root ]# cat /usr/local/frr/etc/bgpd.conf
hostname bgpd
password zebra
router bgp 100 vrf ns1
bgp router-id 10.10.1.2
network 100.10.1.0/24
neighbor 10.10.1.4 remote-as 200
neighbor 10.10.1.4 ebgp-multihop
address-family ipv4 unicast
exit-address-family
router bgp 200 vrf ns2
bgp router-id 10.10.1.4
neighbor 10.10.1.2 remote-as 100
neighbor 10.10.1.2 ebgp-multihop 255
network 200.10.1.0/24
address-family ipv4 unicast
exit-address-family
debug bgp neighbor-events
debug bgp updates
debug bgp keepalives
debug bgp zebra
log file /usr/local/frr/var/log/bgpd.log
结果
vtysh查看当前状态show bgp vrf ns1 neighbors
[root ]# /usr/local/frr/bin/vtysh
Hello, this is FRRouting (version 7.3).
Copyright 1996-2005 Kunihiro Ishiguro, et al.
AS100# show bgp vrf ns1 neighbors
BGP neighbor is 10.10.1.4, remote AS 200, local AS 100, external link
Hostname: bgpd
BGP version 4, remote router ID 10.10.1.4, local router ID 10.10.1.2
BGP state = Established, up for 00:05:17
......
vtysh查看当前状态show bgp vrf ns1 ipv4,可以看到AS200通告的路由200.10.1.0/24;
同样,show bgp vrf ns2 ipv4,可以看到AS100通告的路由200.10.1.0/24;