BIRD 实验 6 BGP动态路由混合EBPG、IBGP
简介
本文描述进行 一个EBPG、IBGP的BGP动态路由实验。
目标

如图所示,3个AS互联,AS65000包含arch1,AS64490包含arch2、arch3、arch4,AS64485包含arch5。实验的目的是通过BGP协议动态交换路由,在arch1上能够ping通arch5上lo1接口上的子网。
在这里:
- arch1为AS 65000。与arch2构成EBGP。
- arch2、arch3、arch4为AS 64496。三者间构成IBGP,其中arch3为Route Reflector(RR),以简化full mesh的IBGP连接。
- arch5为AS 64485。与arch4构成EBGP。
- 此案例的设计来自于 Internal BGP (Border Gateway Protocol) explained
准备
根据拓扑图,配置好网桥:
$ lxc network list
+----------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| NAME | TYPE | MANAGED | IPV4 | IPV6 | DESCRIPTION | USED BY | STATE |
+----------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| enp3s0f0 | physical | NO | | | | 0 | |
+----------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| lxdbr0 | bridge | YES | 10.215.137.1/24 | fd42:62ab:9b76:b227::1/64 | | 3 | CREATED |
+----------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| lxdbr1 | bridge | YES | 10.12.164.1/24 | fd42:7d6a:5878:6514::1/64 | | 2 | CREATED |
+----------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| lxdbr2 | bridge | YES | 10.66.245.1/24 | fd42:1416:4db6:ca04::1/64 | | 2 | CREATED |
+----------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| lxdbr3 | bridge | YES | 10.1.125.1/24 | fd42:9419:3fe0:e0f6::1/64 | | 2 | CREATED |
+----------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
配置好各主机网卡:
$ lxc list
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| arch1 | RUNNING | 192.168.101.1 (lo1) | fd42:62ab:9b76:b227:216:3eff:fe87:c55f (eth0) | CONTAINER | 0 |
| | | 10.215.137.113 (eth0) | | | |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| arch2 | RUNNING | 192.168.102.1 (lo1) | fd42:7d6a:5878:6514:216:3eff:fe0c:f935 (eth1) | CONTAINER | 0 |
| | | 10.215.137.88 (eth0) | fd42:62ab:9b76:b227:216:3eff:feed:52a9 (eth0) | | |
| | | 10.12.164.44 (eth1) | | | |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| arch3 | RUNNING | 192.168.103.1 (lo1) | fd42:7d6a:5878:6514:216:3eff:feaa:7aef (eth0) | CONTAINER | 0 |
| | | 10.66.245.82 (eth1) | fd42:1416:4db6:ca04:216:3eff:fecc:2dc6 (eth1) | | |
| | | 10.12.164.157 (eth0) | | | |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| arch4 | RUNNING | 192.168.104.1 (lo1) | fd42:9419:3fe0:e0f6:216:3eff:fe18:2b2 (eth1) | CONTAINER | 0 |
| | | 10.66.245.134 (eth0) | fd42:1416:4db6:ca04:216:3eff:fee6:bb28 (eth0) | | |
| | | 10.1.125.105 (eth1) | | | |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| arch5 | RUNNING | 192.168.105.1 (lo1) | fd42:9419:3fe0:e0f6:216:3eff:fefa:e8ef (eth0) | CONTAINER | 0 |
| | | 10.1.125.132 (eth0) | | | |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
实验
arch1机的/etc/bird.conf配置。
log syslog all;
protocol device {
}
protocol direct {
disabled; # Disable by default
ipv4; # Connect to default IPv4 table
ipv6; # ... and to default IPv6 table
}
protocol kernel {
ipv4 { # Connect protocol to IPv4 table by channel
export all; # Export to protocol. default is export none
};
}
protocol kernel {
ipv6 { export all; };
}
protocol static {
ipv4; # Again, IPv4 channel with default options
route 192.168.101.0/24 via 192.168.101.1;
}
filter rt_import
{
if bgp_path.first != 64496 then reject;
if bgp_path.len > 64 then reject;
if bgp_next_hop != from then reject;
accept;
}
protocol bgp uplink1 {
local 10.215.137.113 as 65000;
neighbor 10.215.137.88 as 64496;
hold time 90; # Default is 240
password "secret"; # Password used for MD5 authentication
ipv4 { # regular IPv4 unicast (1/1)
import filter rt_import;
export where source ~ [ RTS_STATIC, RTS_BGP ];
};
}
arch2机的/etc/bird.conf配置。
log syslog all;
protocol device {
}
protocol direct {
disabled; # Disable by default
ipv4; # Connect to default IPv4 table
ipv6; # ... and to default IPv6 table
}
protocol kernel {
ipv4 { # Connect protocol to IPv4 table by channel
export all; # Export to protocol. default is export none
};
}
protocol kernel {
ipv6 { export all; };
}
protocol static {
ipv4; # Again, IPv4 channel with default options
}
protocol ospf v2 {
area 0 {
interface "eth*" {
type broadcast; # Detected by default
cost 10; # Interface metric
hello 5; # Default hello perid 10 is too long
};
interface "lo1" {
stub; # Stub interface, just propagate it
};
};
}
filter rt_import
{
if bgp_path.first != 65000 then reject;
if bgp_path.len > 64 then reject;
if bgp_next_hop != from then reject;
accept;
}
protocol bgp uplink1 {
local 10.215.137.88 as 64496;
neighbor 10.215.137.113 as 65000;
hold time 90; # Default is 240
password "secret"; # Password used for MD5 authentication
ipv4 { # regular IPv4 unicast (1/1)
import filter rt_import;
export where source ~ [ RTS_STATIC, RTS_BGP ];
};
}
protocol bgp inner1 {
local 192.168.102.1 as 64496;
neighbor 192.168.103.1 as 64496;
ipv4 { # regular IPv4 unicast (1/1)
import all;
export where source = RTS_BGP;
};
}
arch3机的/etc/bird.conf配置。
log syslog all;
protocol device {
}
protocol direct {
disabled; # Disable by default
ipv4; # Connect to default IPv4 table
ipv6; # ... and to default IPv6 table
}
protocol kernel {
ipv4 { # Connect protocol to IPv4 table by channel
export all; # Export to protocol. default is export none
};
}
protocol kernel {
ipv6 { export all; };
}
protocol static {
ipv4; # Again, IPv4 channel with default options
}
protocol ospf v2 {
area 0 {
interface "eth*" {
type broadcast; # Detected by default
cost 10; # Interface metric
hello 5; # Default hello perid 10 is too long
};
interface "lo1" {
stub; # Stub interface, just propagate it
};
};
}
template bgp rr_clients {
local 192.168.103.1 as 64496;
neighbor as 64496;
rr client;
rr cluster id 192.168.103.1;
ipv4 {
import all;
export where source = RTS_BGP;
};
}
protocol bgp client1 from rr_clients {
neighbor 192.168.102.1;
}
protocol bgp client2 from rr_clients {
neighbor 192.168.104.1;
}
arch4机的/etc/bird.conf配置。
log syslog all;
protocol device {
}
protocol direct {
disabled; # Disable by default
ipv4; # Connect to default IPv4 table
ipv6; # ... and to default IPv6 table
}
protocol kernel {
ipv4 { # Connect protocol to IPv4 table by channel
export all; # Export to protocol. default is export none
};
}
protocol kernel {
ipv6 { export all; };
}
protocol static {
ipv4; # Again, IPv4 channel with default options
}
protocol ospf v2 {
area 0 {
interface "eth*" {
type broadcast; # Detected by default
cost 10; # Interface metric
hello 5; # Default hello perid 10 is too long
};
interface "lo1" {
stub; # Stub interface, just propagate it
};
};
}
filter rt_import
{
if bgp_path.first != 64485 then reject;
if bgp_path.len > 64 then reject;
if bgp_next_hop != from then reject;
accept;
}
protocol bgp uplink1 {
local 10.1.125.105 as 64496;
neighbor 10.1.125.132 as 64485;
hold time 90; # Default is 240
password "secret"; # Password used for MD5 authentication
ipv4 { # regular IPv4 unicast (1/1)
import filter rt_import;
export where source ~ [ RTS_STATIC, RTS_BGP ];
};
}
protocol bgp inner1 {
local 192.168.104.1 as 64496;
neighbor 192.168.103.1 as 64496;
ipv4 { # regular IPv4 unicast (1/1)
import all;
export where source = RTS_BGP;
};
}
arch5机的/etc/bird.conf配置。
log syslog all;
protocol device {
}
protocol direct {
disabled; # Disable by default
ipv4; # Connect to default IPv4 table
ipv6; # ... and to default IPv6 table
}
protocol kernel {
ipv4 { # Connect protocol to IPv4 table by channel
export all; # Export to protocol. default is export none
};
}
protocol kernel {
ipv6 { export all; };
}
protocol static {
ipv4; # Again, IPv4 channel with default options
route 192.168.105.0/24 via 192.168.105.1;
}
filter rt_import
{
if bgp_path.first != 64496 then reject;
if bgp_path.len > 64 then reject;
if bgp_next_hop != from then reject;
accept;
}
protocol bgp uplink1 {
local 10.1.125.132 as 64485;
neighbor 10.1.125.105 as 64496;
hold time 90; # Default is 240
password "secret"; # Password used for MD5 authentication
ipv4 { # regular IPv4 unicast (1/1)
import filter rt_import;
export where source ~ [ RTS_STATIC, RTS_BGP ];
};
}
实验结果,在arch1上,正常情况下
# ip route
default via 10.215.137.1 dev eth0 proto dhcp src 10.215.137.113 metric 1024
10.215.137.0/24 dev eth0 proto kernel scope link src 10.215.137.113 metric 1024
10.215.137.1 dev eth0 proto dhcp scope link src 10.215.137.113 metric 1024
192.168.101.0/24 dev lo1 proto kernel scope link src 192.168.101.1
192.168.101.0/24 via 192.168.101.1 dev lo1 proto bird metric 32
192.168.105.0/24 via 10.215.137.88 dev eth0 proto bird metric 32
# ping 192.168.105.1
PING 192.168.105.1 (192.168.105.1) 56(84) bytes of data.
64 bytes from 192.168.105.1: icmp_seq=1 ttl=63 time=0.166 ms
# birdc
bird> show route all
Table master4:
192.168.101.0/24 unicast [static1 23:26:30.972] ! (200)
via 192.168.101.1 on lo1
Type: static univ
192.168.105.0/24 unicast [uplink1 23:27:13.547] * (100) [AS64485i]
via 10.215.137.88 on eth0
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 64496 64485
BGP.next_hop: 10.215.137.88
BGP.local_pref: 100
arch2
# ip route
default via 10.12.164.1 dev eth1 proto dhcp src 10.12.164.44 metric 1024
default via 10.215.137.1 dev eth0 proto dhcp src 10.215.137.88 metric 1024
10.1.125.0/24 via 10.12.164.157 dev eth1 proto bird metric 32
10.12.164.0/24 dev eth1 proto bird scope link metric 32
10.12.164.0/24 dev eth1 proto kernel scope link src 10.12.164.44 metric 1024
10.12.164.1 dev eth1 proto dhcp scope link src 10.12.164.44 metric 1024
10.66.245.0/24 via 10.12.164.157 dev eth1 proto bird metric 32
10.215.137.0/24 dev eth0 proto bird scope link metric 32
10.215.137.0/24 dev eth0 proto kernel scope link src 10.215.137.88 metric 1024
10.215.137.1 dev eth0 proto dhcp scope link src 10.215.137.88 metric 1024
192.168.101.0/24 via 10.215.137.113 dev eth0 proto bird metric 32
192.168.102.0/24 dev lo1 proto kernel scope link src 192.168.102.1
192.168.102.0/24 dev lo1 proto bird scope link metric 32
192.168.103.0/24 via 10.12.164.157 dev eth1 proto bird metric 32
192.168.104.0/24 via 10.12.164.157 dev eth1 proto bird metric 32
192.168.105.0/24 via 10.12.164.157 dev eth1 proto bird metric 32
# birdc
bird> show route all
Table master4:
192.168.101.0/24 unicast [uplink1 23:26:35.180] * (100) [AS65000i]
via 10.215.137.113 on eth0
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 65000
BGP.next_hop: 10.215.137.113
BGP.local_pref: 100
10.215.137.0/24 unicast [ospf1 23:26:32.353] * I (150/10) [10.12.164.44]
dev eth0
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.12.164.44
10.66.245.0/24 unicast [ospf1 23:26:58.353] * I (150/20) [10.12.164.157]
via 10.12.164.157 on eth1
Type: OSPF univ
OSPF.metric1: 20
OSPF.router_id: 10.12.164.157
10.1.125.0/24 unicast [ospf1 23:27:04.354] * I (150/30) [10.1.125.105]
via 10.12.164.157 on eth1
Type: OSPF univ
OSPF.metric1: 30
OSPF.router_id: 10.1.125.105
10.12.164.0/24 unicast [ospf1 23:26:53.353] * I (150/10) [10.12.164.157]
dev eth1
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.12.164.157
192.168.102.0/24 unicast [ospf1 23:26:32.353] * I (150/10) [10.12.164.44]
dev lo1
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.12.164.44
192.168.103.0/24 unicast [ospf1 23:26:58.353] * I (150/20) [10.12.164.157]
via 10.12.164.157 on eth1
Type: OSPF univ
OSPF.metric1: 20
OSPF.router_id: 10.12.164.157
192.168.104.0/24 unicast [ospf1 23:27:04.354] * I (150/30) [10.1.125.105]
via 10.12.164.157 on eth1
Type: OSPF univ
OSPF.metric1: 30
OSPF.router_id: 10.1.125.105
192.168.105.0/24 unicast [inner1 23:27:13.547 from 192.168.103.1] * (100/30) [AS64485i]
via 10.12.164.157 on eth1
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 64485
BGP.next_hop: 10.1.125.132
BGP.local_pref: 100
BGP.originator_id: 10.1.125.105
BGP.cluster_list: 192.168.103.1
arch3
# ip route
default via 10.12.164.1 dev eth0 proto dhcp src 10.12.164.157 metric 1024
default via 10.66.245.1 dev eth1 proto dhcp src 10.66.245.82 metric 1024
10.1.125.0/24 via 10.66.245.134 dev eth1 proto bird metric 32
10.12.164.0/24 dev eth0 proto bird scope link metric 32
10.12.164.0/24 dev eth0 proto kernel scope link src 10.12.164.157 metric 1024
10.12.164.1 dev eth0 proto dhcp scope link src 10.12.164.157 metric 1024
10.66.245.0/24 dev eth1 proto bird scope link metric 32
10.66.245.0/24 dev eth1 proto kernel scope link src 10.66.245.82 metric 1024
10.66.245.1 dev eth1 proto dhcp scope link src 10.66.245.82 metric 1024
10.215.137.0/24 via 10.12.164.44 dev eth0 proto bird metric 32
192.168.101.0/24 via 10.12.164.44 dev eth0 proto bird metric 32
192.168.102.0/24 via 10.12.164.44 dev eth0 proto bird metric 32
192.168.103.0/24 dev lo1 proto kernel scope link src 192.168.103.1
192.168.103.0/24 dev lo1 proto bird scope link metric 32
192.168.104.0/24 via 10.66.245.134 dev eth1 proto bird metric 32
192.168.105.0/24 via 10.66.245.134 dev eth1 proto bird metric 32
# birdc
bird> show route all
Table master4:
192.168.101.0/24 unicast [client1 15:27:13.546 from 192.168.102.1] * (100/20) [AS65000i]
via 10.12.164.44 on eth0
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 65000
BGP.next_hop: 10.215.137.113
BGP.local_pref: 100
10.215.137.0/24 unicast [ospf1 15:26:59.009] * I (150/20) [10.12.164.44]
via 10.12.164.44 on eth0
Type: OSPF univ
OSPF.metric1: 20
OSPF.router_id: 10.12.164.44
10.66.245.0/24 unicast [ospf1 15:26:33.008] * I (150/10) [10.12.164.157]
dev eth1
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.12.164.157
10.1.125.0/24 unicast [ospf1 15:27:04.009] * I (150/20) [10.1.125.105]
via 10.66.245.134 on eth1
Type: OSPF univ
OSPF.metric1: 20
OSPF.router_id: 10.1.125.105
10.12.164.0/24 unicast [ospf1 15:26:33.008] * I (150/10) [10.12.164.157]
dev eth0
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.12.164.157
192.168.102.0/24 unicast [ospf1 15:26:59.009] * I (150/20) [10.12.164.44]
via 10.12.164.44 on eth0
Type: OSPF univ
OSPF.metric1: 20
OSPF.router_id: 10.12.164.44
192.168.103.0/24 unicast [ospf1 15:26:33.008] * I (150/10) [10.12.164.157]
dev lo1
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.12.164.157
192.168.104.0/24 unicast [ospf1 15:27:04.009] * I (150/20) [10.1.125.105]
via 10.66.245.134 on eth1
Type: OSPF univ
OSPF.metric1: 20
OSPF.router_id: 10.1.125.105
192.168.105.0/24 unicast [client2 15:27:13.547 from 192.168.104.1] * (100/20) [AS64485i]
via 10.66.245.134 on eth1
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 64485
BGP.next_hop: 10.1.125.132
BGP.local_pref: 100
arch4
# ip route
default via 10.66.245.1 dev eth0 proto dhcp src 10.66.245.134 metric 1024
default via 10.1.125.1 dev eth1 proto dhcp src 10.1.125.105 metric 1024
10.1.125.0/24 dev eth1 proto bird scope link metric 32
10.1.125.0/24 dev eth1 proto kernel scope link src 10.1.125.105 metric 1024
10.1.125.1 dev eth1 proto dhcp scope link src 10.1.125.105 metric 1024
10.12.164.0/24 via 10.66.245.82 dev eth0 proto bird metric 32
10.66.245.0/24 dev eth0 proto bird scope link metric 32
10.66.245.0/24 dev eth0 proto kernel scope link src 10.66.245.134 metric 1024
10.66.245.1 dev eth0 proto dhcp scope link src 10.66.245.134 metric 1024
10.215.137.0/24 via 10.66.245.82 dev eth0 proto bird metric 32
192.168.101.0/24 via 10.66.245.82 dev eth0 proto bird metric 32
192.168.102.0/24 via 10.66.245.82 dev eth0 proto bird metric 32
192.168.103.0/24 via 10.66.245.82 dev eth0 proto bird metric 32
192.168.104.0/24 dev lo1 proto kernel scope link src 192.168.104.1
192.168.104.0/24 dev lo1 proto bird scope link metric 32
192.168.105.0/24 via 10.1.125.132 dev eth1 proto bird metric 32
# birdc
bird> show route all
Table master4:
192.168.101.0/24 unicast [inner1 23:27:13.547 from 192.168.103.1] * (100/30) [AS65000i]
via 10.66.245.82 on eth0
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 65000
BGP.next_hop: 10.215.137.113
BGP.local_pref: 100
BGP.originator_id: 10.12.164.44
BGP.cluster_list: 192.168.103.1
10.215.137.0/24 unicast [ospf1 23:27:03.528] * I (150/30) [10.12.164.44]
via 10.66.245.82 on eth0
Type: OSPF univ
OSPF.metric1: 30
OSPF.router_id: 10.12.164.44
10.66.245.0/24 unicast [ospf1 23:26:58.529] * I (150/10) [10.12.164.157]
dev eth0
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.12.164.157
10.1.125.0/24 unicast [ospf1 23:26:33.532] * I (150/10) [10.1.125.105]
dev eth1
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.1.125.105
10.12.164.0/24 unicast [ospf1 23:26:59.531] * I (150/20) [10.12.164.157]
via 10.66.245.82 on eth0
Type: OSPF univ
OSPF.metric1: 20
OSPF.router_id: 10.12.164.157
192.168.102.0/24 unicast [ospf1 23:27:03.528] * I (150/30) [10.12.164.44]
via 10.66.245.82 on eth0
Type: OSPF univ
OSPF.metric1: 30
OSPF.router_id: 10.12.164.44
192.168.103.0/24 unicast [ospf1 23:26:59.531] * I (150/20) [10.12.164.157]
via 10.66.245.82 on eth0
Type: OSPF univ
OSPF.metric1: 20
OSPF.router_id: 10.12.164.157
192.168.104.0/24 unicast [ospf1 23:26:33.532] * I (150/10) [10.1.125.105]
dev lo1
Type: OSPF univ
OSPF.metric1: 10
OSPF.router_id: 10.1.125.105
192.168.105.0/24 unicast [uplink1 23:26:38.076] * (100) [AS64485i]
via 10.1.125.132 on eth1
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 64485
BGP.next_hop: 10.1.125.132
BGP.local_pref: 100
arch5
# ip route
default via 10.1.125.1 dev eth0 proto dhcp src 10.1.125.132 metric 1024
10.1.125.0/24 dev eth0 proto kernel scope link src 10.1.125.132 metric 1024
10.1.125.1 dev eth0 proto dhcp scope link src 10.1.125.132 metric 1024
192.168.101.0/24 via 10.1.125.105 dev eth0 proto bird metric 32
192.168.105.0/24 dev lo1 proto kernel scope link src 192.168.105.1
192.168.105.0/24 via 192.168.105.1 dev lo1 proto bird metric 32
# birdc
bird> show route all
Table master4:
192.168.101.0/24 unicast [uplink1 23:27:13.547] * (100) [AS65000i]
via 10.1.125.105 on eth0
Type: BGP univ
BGP.origin: IGP
BGP.as_path: 64496 65000
BGP.next_hop: 10.1.125.105
BGP.local_pref: 100
192.168.105.0/24 unicast [static1 23:26:33.877] ! (200)
via 192.168.105.1 on lo1
Type: static univ
# ping 192.168.101.1
PING 192.168.101.1 (192.168.101.1) 56(84) bytes of data.
64 bytes from 192.168.101.1: icmp_seq=1 ttl=63 time=0.126 ms
如上,实验成功。
总结
- 小心default那条路由,lxd自己也是路由器,别被误导了。
- arch2、arch3、arch4之间需要用OSPF协议或其他动态路由协议或静态路由进行联通,才能跑IBGP。
- arch1、arch5,学习不到AS64490内的路由,属于正常情况。因为arch2、arch4都只export了BGP路由。没有宣告自己AS内的前缀。
结束
实验结束,最后删除虚拟机。
lxc delete -f arch1
lxc delete -f arch2
lxc delete -f arch3
lxc delete -f arch4
lxc delete -f arch5
下次搭建一个BGP应用于IPsec 虚拟专用网的实验。