FRR学习第二天

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

  1. 两个frr路由器建立邻居关系
  2. 将igp路由注入bgp
  3. bgp路由注入igp
  4. 实现两个网络通过动态路由互通

实验拓扑

FRR学习第二天_第1张图片

配置主机

主机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

主机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

将IGP路由注入到BGP

主机1

ubuntu(config-router)# network 2.2.2.0/24 

主机2

ubuntu(config-router)# network 3.3.3.0/24

查看配置结果

主机1

ubuntu# show ip route 
Codes: K - kernel route, C - connected, S - static, R - RIP,
       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP,
       F - PBR, f - OpenFabric,
       > - selected route, * - FIB route, q - queued route, r - rejected route

K>* 0.0.0.0/0 [0/100] via 192.168.217.2, ens33, 18:24:23
C>* 2.2.2.0/24 is directly connected, br1, 00:35:11
B>* 3.3.3.0/24 [20/0] via 192.168.59.129, ens34, 00:00:15
K>* 169.254.0.0/16 [0/1000] is directly connected, ens34, 18:24:23
C>* 192.168.59.0/24 is directly connected, ens34, 18:24:23
C>* 192.168.217.0/24 is directly connected, ens33, 18:24:23

主机2

ubuntu# show ip route 
Codes: K - kernel route, C - connected, S - static, R - RIP,
       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP,
       F - PBR, f - OpenFabric,
       > - selected route, * - FIB route, q - queued route, r - rejected route

K>* 0.0.0.0/0 [0/100] via 192.168.217.2, ens33, 13:16:46
B>* 2.2.2.0/24 [20/0] via 192.168.59.128, ens34, 00:45:36
C>* 3.3.3.0/24 is directly connected, br1, 01:07:35
K>* 169.254.0.0/16 [0/1000] is directly connected, ens33, 18:22:49
C>* 192.168.59.0/24 is directly connected, ens34, 18:22:49
C>* 192.168.217.0/24 is directly connected, ens33, 18:22:49
ubuntu# 

从上面可以看出,两个主机分别有了对等体发布的路由,对等体发布的路由会自动注入igp路由中。标号为B>。

测试

主机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:~$ 

你可能感兴趣的:(cc++)