实验topo

实验说明:设置RTA和RTB彼此为邻居,测试使用network命令和redistribute命令进行路由宣告实验
实验配置
RTA
RTA# show running-config
Building configuration...
Current configuration:
!
frr version 7.1
frr defaults traditional
hostname 46d9117a0d94
log syslog informational
no ipv6 forwarding
hostname RTA
service integrated-vtysh-config
!
router bgp 65001
neighbor 10.1.1.2 remote-as external
!
line vty
!
end
RTA#
RTB
RTB# show running-config
Building configuration...
Current configuration:
!
frr version 7.1
frr defaults traditional
hostname 94f591948424
log syslog informational
no ipv6 forwarding
hostname RTB
service integrated-vtysh-config
!
router bgp 65002
neighbor 10.1.1.1 remote-as external
!
line vty
!
end
RTB#
查看邻居
RTA# show bgp neighbors 10.1.1.2
BGP neighbor is 10.1.1.2, remote AS 65002, local AS 65001, external link
Hostname: 94f591948424
BGP version 4, remote router ID 172.17.0.3, local router ID 172.17.0.2
BGP state = Established, up for 00:01:19
Last read 00:00:19, Last write 00:00:19
Hold time is 180, keepalive interval is 60 seconds
可以看到邻居已经正常建立。
使用NETWORK命令宣告路由
RTB# configure terminal
RTB(config)#
RTB(config)# interface lo
RTB(config-if)#
RTB(config-if)# ip address 6.6.6.6/24
RTB(config-if)# exit
RTB(config)# router bgp 65002
RTB(config-router)# address-family ipv4 unicast
RTB(config-router-af)# network 6.6.6.0/24
RTB# show ip bgp 6.6.6.0/24
BGP routing table entry for 6.6.6.0/24
Paths: (1 available, best #1, table default)
Advertised to non peer-group peers:
10.1.1.1
Local
0.0.0.0 from 0.0.0.0 (6.6.6.1)
Origin IGP, metric 0, weight 32768, valid, sourced, local, best
Last update: Tue Jan 14 12:36:09 2020
RTB#
RTB# 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/0] via 172.17.0.1, eth0, 00:10:25
C>* 6.6.6.0/24 is directly connected, lo, 00:01:44
C>* 6.6.6.0/30 is directly connected, lo, 00:06:36
C>* 10.1.1.0/24 is directly connected, eth1, 00:10:24
C>* 172.17.0.0/16 is directly connected, eth0, 00:10:25
RTB#
从上面可以看出,在路由表中存在6.6.6.0/24的路由,所以使用network命令可以宣告6.6.6.0/24的路由,会将其发送给其它的邻居。
RTA# show ip bgp
BGP table version is 3, local router ID is 172.17.0.2, vrf id 0
Default local pref 100, local AS 65001
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
*> 6.6.6.0/24 10.1.1.2 0 0 65002 i
Displayed 1 routes and 1 total paths
RTA#
当路由不在路由表中时,使用network进行宣告
RTB(config-router)# address-family ipv4 unicast
RTB(config-router-af)# network 9.8.7.0/24
RTB(config-router-af)#
RTB# 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/0] via 172.17.0.1, eth0, 14:53:14
C>* 10.1.1.0/24 is directly connected, eth1, 14:53:13
C>* 172.17.0.0/16 is directly connected, eth0, 14:53:14
RTB# show ip bgp
BGP table version is 9, local router ID is 6.6.6.1, vrf id 0
Default local pref 100, local AS 65002
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
*> 9.8.7.0/24 0.0.0.0 0 32768 i
Displayed 1 routes and 1 total paths
RTB#
RTA# show ip bgp
BGP table version is 9, local router ID is 172.17.0.2, vrf id 0
Default local pref 100, local AS 65001
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
*> 9.8.7.0/24 10.1.1.2 0 0 65002 i
Displayed 1 routes and 1 total paths
RTA# show ip route bgp
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
B>* 9.8.7.0/24 [20/0] via 10.1.1.2, eth1, 00:02:44
RTA#
FRR不会检查network发布的路由是否在路由表中,都会宣告给其它邻居,不会安装到路由表中。在RTA上ping9.8.7.1,能在RTB上抓到ping报文。这点与思科不一致。
RTA# ping 9.8.7.1
PING 9.8.7.1 (9.8.7.1): 56 data bytes
^C--- 9.8.7.1 ping statistics ---
3 packets transmitted, 0 packets received, 100% packet loss
RTA#
root@94f591948424:/# tcpdump -i eth1 -eennvv icmp -c 1
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
12:50:23.578541 02:42:0a:01:01:01 > 02:42:0a:01:01:02, ethertype IPv4 (0x0800), length 98: (tos 0x0, ttl 64, id 13995, offset 0, flags [DF], proto ICMP (1), length 84)
10.1.1.1 > 9.8.7.1: ICMP echo request, id 73, seq 37, length 64
1 packet captured
1 packet received by filter
0 packets dropped by kernel
root@94f591948424:/#
使用redistribute导入路由进行宣告
重分发的意思是将路由表中的其它类型(除了自己)的路由导入到BGP协议中,其它类型可以是如下类型:
RTB# configure terminal
RTB(config)# router bgp 65002
RTB(config-router)# address-family ipv4 unicast
RTB(config-router-af)# redistribute
babel eigrp kernel openfabric rip static vnc
connected isis nhrp ospf sharp table vnc-direct
RTB(config-router-af)#
比如我们想要将路由表中的直连路由重分发到bgp,可以使用如下命令:
RTB(config-router)# address-family ipv4 unicast
RTB(config-router-af)# redistribute connected metric 10
我们在如下配置下观察RTB和RTA的路由信息:
RTA
RTA# show running-config
Building configuration...
Current configuration:
!
frr version 7.1
frr defaults traditional
hostname 46d9117a0d94
log syslog informational
no ipv6 forwarding
hostname RTA
service integrated-vtysh-config
!
router bgp 65001
neighbor 10.1.1.2 remote-as external
!
line vty
!
end
RTA#
RTB
RTB# show running-config
Building configuration...
Current configuration:
!
frr version 7.1
frr defaults traditional
hostname 94f591948424
log syslog informational
no ipv6 forwarding
hostname RTB
service integrated-vtysh-config
!
interface lo
ip address 9.8.7.6/24
!
router bgp 65002
neighbor 10.1.1.1 remote-as external
!
address-family ipv4 unicast
redistribute connected metric 10
exit-address-family
!
line vty
!
end
RTB#
观察RTB的路由表
RTB# 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/0] via 172.17.0.1, eth0, 15:04:07
C>* 9.8.7.0/24 is directly connected, lo, 00:08:33
C>* 10.1.1.0/24 is directly connected, eth1, 15:04:06
C>* 172.17.0.0/16 is directly connected, eth0, 15:04:07
RTB# show ip bgp
BGP table version is 16, local router ID is 6.6.6.1, vrf id 0
Default local pref 100, local AS 65002
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
*> 9.8.7.0/24 0.0.0.0 10 32768 ?
*> 10.1.1.0/24 0.0.0.0 10 32768 ?
*> 172.17.0.0/16 0.0.0.0 10 32768 ?
Displayed 3 routes and 3 total paths
RTB#
从上面的信息可以看出,redistribute connected命令将路由表中带C标志的路由导入了bgp协议。
查看RTA的路由信息
RTA# show ip route bgp
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
B>* 9.8.7.0/24 [20/10] via 10.1.1.2, eth1, 00:02:12
B 10.1.1.0/24 [20/10] via 10.1.1.2 inactive, 00:02:12
B 172.17.0.0/16 [20/10] via 10.1.1.2, eth1, 00:02:12
RTA# show ip bgp
BGP table version is 16, local router ID is 172.17.0.2, vrf id 0
Default local pref 100, local AS 65001
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
*> 9.8.7.0/24 10.1.1.2 10 0 65002 ?
*> 10.1.1.0/24 10.1.1.2 10 0 65002 ?
*> 172.17.0.0/16 10.1.1.2 10 0 65002 ?
Displayed 3 routes and 3 total paths
RTA#
从上面的信息可以看出RTA收到了RTB发布的重分发路由。
总结
1.BGP发布路由有如下两种方式:
- 使用network命令,可以发布任何路由,不管该路由是否在路由表中,这一点有思科有所不同。
- 使用redistribute命令,可以将其它类型的二路由导入BGP,然后进行发布,该方法粒度太粗,容易将不想要的路由引入BGP表中,需要借助过滤机制进行过滤。