FRR学习第4天路由聚合

29次阅读

共计 3214 个字符,预计需要花费 9 分钟才能阅读完成。

今天学习使用 frr 搭建一个 bgp 网络环境,练习如下功能:

  1. 两个 frr 路由器建立邻居关系
  2. 进行路由聚合
  3. 实现两个网络通过动态路由互通

实验拓扑

配置主机

主机 1

#bgp 配置
router bgp 7675
 bgp router-id 192.168.59.128
 neighbor 192.168.59.129 remote-as 7676
 !
!
#配置一个 host
sudo ip netns add ns1 
sudo ip link add veth1 type veth peer name eth0 netns ns1
sudo ip netns exec ns1 ip link set eth0 up
sudo ip netns exec ns1 ip link set lo up
sudo ip netns exec ns1 ip addr add 2.2.2.2/24 dev eth0
sudo ip netns exec ns1 ip route add default via 2.2.2.254 dev eth0
sudo ip link set veth1 up
sudo ip link add br1 type bridge
sudo ip link set br1 up
sudo ip link set veth1 master br1
sudo ip addr add 2.2.2.254/24 dev br1
#打开转发开关
ubuntu@ubuntu:~$ sudo -i
root@ubuntu:~# echo 1 > /proc/sys/net/ipv4/ip_forward

#添加几个其它网段的路由
ubuntu@ubuntu:~$ sudo ip route add 2.2.3.0/24 via 192.168.59.129 dev ens34    
ubuntu@ubuntu:~$ sudo ip route add 2.2.4.0/24 via 192.168.59.129 dev ens34 
ubuntu@ubuntu:~$ sudo ip route add 2.2.5.0/24 via 192.168.59.129 dev ens34 
ubuntu@ubuntu:~$ sudo ip route add 2.2.6.0/24 via 192.168.59.129 dev ens34 

主机 2

#bgp 配置
router bgp 7676
 bgp router-id 192.168.59.129
 neighbor 192.168.59.128 remote-as 7675
 !
!
#配置一个 host
sudo ip netns add ns1 
sudo ip link add veth1 type veth peer name eth0 netns ns1
sudo ip netns exec ns1 ip link set eth0 up
sudo ip netns exec ns1 ip link set lo up
sudo ip netns exec ns1 ip addr add 3.3.3.3/24 dev eth0
sudo ip netns exec ns1 ip route add default via 3.3.3.254 dev eth0
sudo ip link set veth1 up
sudo ip link add br1 type bridge
sudo ip link set br1 up
sudo ip link set veth1 master br1
sudo ip addr add 3.3.3.254/24 dev br1
#打开转发开关
ubuntu@ubuntu:~$ sudo -i
root@ubuntu:~# echo 1 > /proc/sys/net/ipv4/ip_forward

聚合携带 summary-only 选项,该选项只会宣告聚合地址,不会宣告更具体的地址

主机 1:通过配置聚合进行发布

ubuntu(config-router)# aggregate-address 2.2.0.0/16 summary-only
ubuntu(config-router)# network 2.2.3.0/24

主机 2

ubuntu(config-router)# network 3.3.3.0/24

查看配置结果

主机 1

ubuntu# show ip bgp
BGP table version is 25, local router ID is 192.168.59.128, vrf id 0
Default local pref 100, local AS 7675
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.0.0/16       0.0.0.0                            32768 i
s> 2.2.3.0/24       0.0.0.0                  0         32768 i
*> 3.3.3.0/24       192.168.59.129           0             0 7676 i

Displayed  3 routes and 3 total paths
ubuntu# 
#可以看到 2.2.3.0/24 前面有个 s 字母,表示更加具体的路由被抑制了。

主机 2

ubuntu# show ip bgp 
BGP table version is 24, local router ID is 192.168.59.129, vrf id 0
Default local pref 100, local AS 7676
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.0.0/16       192.168.59.128                         0 7675 i
*> 3.3.3.0/24       0.0.0.0                  0         32768 i

Displayed  2 routes and 2 total paths
ubuntu# 
#只收到对等体的聚合路由 

从上面可以看出,summary-only 选项,该选项只会宣告聚合地址,不会宣告更具体的地址。具体路由会被抑制,标号为 s >。

测试

主机 1

ubuntu@ubuntu:~$ sudo ip netns exec ns1 ping 3.3.3.3 -c 2
PING 3.3.3.3 (3.3.3.3) 56(84) bytes of data.
64 bytes from 3.3.3.3: icmp_seq=1 ttl=62 time=0.372 ms
64 bytes from 3.3.3.3: icmp_seq=2 ttl=62 time=0.339 ms

--- 3.3.3.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 32ms
rtt min/avg/max/mdev = 0.339/0.355/0.372/0.025 ms
ubuntu@ubuntu:~$ 

主机 2

ubuntu@ubuntu:~$ sudo ip netns exec ns1 ping 2.2.2.2 -c 2
PING 2.2.2.2 (2.2.2.2) 56(84) bytes of data.
64 bytes from 2.2.2.2: icmp_seq=1 ttl=62 time=0.564 ms
64 bytes from 2.2.2.2: icmp_seq=2 ttl=62 time=0.359 ms

--- 2.2.2.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 0.359/0.461/0.564/0.104 ms
ubuntu@ubuntu:~$ 

正文完
 0