BIRD 实验 4 OSPF动态路由3台机器
简介
本文紧接着上一个实验,描述进行BIRD 3台机器的OSPF动态路由实验。
目标

如图所示,三个路由器还是通过三个网桥直连,分别在lo1接口各挂一个子网,实验的目的是通过OSPF协议动态交换路由,在一台路由器上能够ping通另一台路由器lo1接口上的子网。断开arch1和arch3之间的连接后,能自动切换到arch1-arch2-arch3的路由。
准备
与实验3一样,配置好arch1、arch2、arch3机的基本环境。
$ lxc list
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| arch1 | RUNNING | 192.168.101.1 (lo1) | fd42:7d6a:5878:6514:216:3eff:fea6:6269 (eth1) | CONTAINER | 0 |
| | | 10.215.137.113 (eth0) | fd42:62ab:9b76:b227:216:3eff:fe87:c55f (eth0) | | |
| | | 10.12.164.147 (eth1) | | | |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| arch2 | RUNNING | 192.168.102.1 (lo1) | fd42:62ab:9b76:b227:216:3eff:feed:52a9 (eth0) | CONTAINER | 0 |
| | | 10.66.245.191 (eth1) | fd42:1416:4db6:ca04:216:3eff:fe39:1507 (eth1) | | |
| | | 10.215.137.88 (eth0) | | | |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| 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) | | | |
+-------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
实验
arch1、arch2、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
};
};
}
实验结果,在arch1上,正常情况下
# ip route
default via 10.215.137.1 dev eth0 proto dhcp src 10.215.137.113 metric 1024
default via 10.12.164.1 dev eth1 proto dhcp src 10.12.164.147 metric 1024
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.147 metric 1024
10.12.164.1 dev eth1 proto dhcp scope link src 10.12.164.147 metric 1024
10.66.245.0/24 proto bird metric 32
nexthop via 10.12.164.157 dev eth1 weight 1
nexthop via 10.215.137.88 dev eth0 weight 1
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.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 dev lo1 proto bird scope link metric 32
192.168.102.0/24 via 10.215.137.88 dev eth0 proto bird metric 32
192.168.103.0/24 via 10.12.164.157 dev eth1 proto bird metric 32
# ping 192.168.102.1
PING 192.168.102.1 (192.168.102.1) 56(84) bytes of data.
64 bytes from 192.168.102.1: icmp_seq=1 ttl=64 time=0.064 ms
# ping 192.168.103.1
PING 192.168.103.1 (192.168.103.1) 56(84) bytes of data.
64 bytes from 192.168.103.1: icmp_seq=1 ttl=64 time=0.061 ms
如上,说明arch1和arch2、arch3都是直连的。
模拟arch1和arch3间断掉
# ip link set eth1 down
再次检查
# ip route
default via 10.215.137.1 dev eth0 proto dhcp src 10.215.137.113 metric 1024
10.12.164.0/24 via 10.215.137.88 dev eth0 proto bird metric 32
10.66.245.0/24 via 10.215.137.88 dev eth0 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.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 dev lo1 proto bird scope link metric 32
192.168.102.0/24 via 10.215.137.88 dev eth0 proto bird metric 32
192.168.103.0/24 via 10.215.137.88 dev eth0 proto bird metric 32
# ping 192.168.102.1
PING 192.168.102.1 (192.168.102.1) 56(84) bytes of data.
64 bytes from 192.168.102.1: icmp_seq=1 ttl=64 time=0.057 ms
# ping 192.168.103.1
PING 192.168.103.1 (192.168.103.1) 56(84) bytes of data.
64 bytes from 192.168.103.1: icmp_seq=1 ttl=63 time=0.099 ms
如上,网络还是通的,路由变成arch1-arch2-arch3了。ping arch3的lo1所在网段时,ttl也变成63了,也说明多了一跳。实验成功。
总结
- 小心default那条路由,lxd自己也是路由器,别被误导了。
- 因为只需要ipv4,所以设置了ospf v2
- 在ospf v2中设置interface “lo1"后,就不用在static中配置lo1 的route了
结束
实验结束,最后删除虚拟机。
lxc delete -f arch1
lxc delete -f arch2
lxc delete -f arch3
下次该实验BGP了。