该方法是基于第一种方式的路由技术,只不过路由信息不需要自己手动添加,而是自动学习。可以使用docker机器众多的情况下。Quagga可以配置很多种企业级的动态路由协议。这里只介绍rip与ospf协议,协议的具体知识这里不细讲。
环境配置:
两台centos7机器,且安装docker,实验前清理干净上个实验的配置。以免干扰实验结果。
docker1:192.168.0.124
docker2:192.168.0.121
搭建:
1、搭建前需要注意,docker的网段不能一样,需要手动设置。可以直接使用docker pull route下载运行就可以使用。这里使用原始的方法。
安装quagga.
yum install
ftp://rpmfind.net/linux/centos/7.4.1708/os/x86_64/Packages/quagga-0.99.22.4-4.el7.x86_64.rpm
上面的包有时及其难下载,可以评论找我发你。
2、配置quagga。
提供配置文件。
[root@localhost ~]# cp /usr/share/doc/quagga-0.99.22.4/ospfd.conf.sample /etc/quagga/ospfd.conf
3、启动服务。
[root@localhost ~]# systemctl restart ospfd
4、配置ospf
[root@localhost ~]# vtysh
Hello, this is Quagga (version 0.99.22.4).
Copyright 1996-2005 Kunihiro Ishiguro, et al.
localhost.localdomain# conf t
localhost.localdomain(config)# router ospf
localhost.localdomain(config-router)# network 0.0.0.0/0 area 0.0.0.0
localhost.localdomain(config-router)# end
localhost.localdomain# wr
Building Configuration...
Configuration saved to /etc/quagga/zebra.conf
Can't backup old configuration file /etc/quagga/ospfd.conf.sav.
[OK]
上述操作两端相同操作。
5、查看路由表
localhost.localdomain# sh ip route
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, A - Babel,
> - selected route, * - FIB route
K>* 0.0.0.0/0 via 192.168.0.254, ens33
C>* 127.0.0.0/8 is directly connected, lo
O>* 127.0.0.1/32 [110/10] is directly connected, lo, 00:05:04
O 172.17.0.0/16 [110/10] is directly connected, docker0, 00:01:18
C>* 172.17.0.0/16 is directly connected, docker0
O>* 172.20.0.0/16 [110/20] via 192.168.0.121, ens33, 00:00:19
O 192.168.0.0/24 [110/10] is directly connected,
6、两端出现对方的IP段时,启动容器进行测试
/ # ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2): 56 data bytes
64 bytes from 172.17.0.2: seq=0 ttl=62 time=1.038 ms
64 bytes from 172.17.0.2: seq=1 ttl=62 time=0.460 ms
52: eth0@if53: mtu 1500 qdisc noqueue
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
valid_lft forever preferred_lft forever
/ # ping 172.20.0.2
PING 172.20.0.2 (172.20.0.2): 56 data bytes
64 bytes from 172.20.0.2: seq=0 ttl=62 time=0.666 ms
64 bytes from 172.20.0.2: seq=1 ttl=62 time=0.346 ms
7、同理,再配置一个rip协议,关闭ospf服务。重新配置
[root@localhost ~]# cp /usr/share/doc/quagga-0.99.22.4/ripd.conf.sample /etc/quagga/ripd.conf
8、启动rip服务,并配置
localhost.localdomain# conf t
localhost.localdomain(config)# router rip
localhost.localdomain(config-router)# version 2
localhost.localdomain(config-router)# network 192.168.0.0/24
localhost.localdomain(config-router)# network 172.17.0.0/16
There is a same network configuration 172.17.0.0/16
localhost.localdomain(config-router)# end
localhost.localdomain# wr
localhost.localdomain# sh ip route
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, A - Babel,
> - selected route, * - FIB route
K>* 0.0.0.0/0 via 192.168.0.254, ens33
C>* 127.0.0.0/8 is directly connected, lo
C>* 172.17.0.0/16 is directly connected, docker0
R>* 172.20.0.0/16 [120/2] via 192.168.0.121, ens33, 00:01:31
C>* 192.168.0.0/24 is directly connected, ens33
9、测试。