一、实验环境
物理机:Win11
虚拟机:VMware Workstation pro 16 + Ubuntu20.04
二、实验过程
1.安装Docker
curl -sSL https://get.daocloud.io/docker | sh
看到如下图片即为安装完成。
测试Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:
sudo docker run hello-world
2.安装Containerlab
注意:安装Containerlab时需要将自己设置为root用户
Ubuntu上将自己设置为root用户的命令
sudo -i
安装Containerlab
echo "deb [trusted=yes] https://apt.fury.io/netdevops/ /" | \
sudo tee -a /etc/apt/sources.list.d/netdevops.list
apt update && apt install containerlab
3.测试 Containerlab
3.1 实验环境准备
实验拓扑如下:
文件结构:
└── frrlab
├── frrlab.yml
├── router1
│ └── daemons
├── router2
│ └── daemons
└── router3
└── daemons
首先创建一个文件夹frrlab,并且进入该文件夹路径下。
mkdir -p ~/Documents/frrlab
cd ~/Documents/frrlab
touch frrlab.yml
在frrlab.yml中输入如下内容:
name: frrlab
topology:
nodes:
router1:
kind: linux
image: frrouting/frr:v8.2.2
binds:
- router1/daemons:/etc/frr/daemons
router2:
kind: linux
image: frrouting/frr:v8.2.2
binds:
- router2/daemons:/etc/frr/daemons
router3:
kind: linux
image: frrouting/frr:v8.2.2
binds:
- router3/daemons:/etc/frr/daemons
PC1:
kind: linux
image: praqma/network-multitool:latest
PC2:
kind: linux
image: praqma/network-multitool:latest
PC3:
kind: linux
image: praqma/network-multitool:latest
links:
- endpoints: ["router1:eth1", "router2:eth1"]
- endpoints: ["router1:eth2", "router3:eth1"]
- endpoints: ["router2:eth2", "router3:eth2"]
- endpoints: ["PC1:eth1", "router1:eth3"]
- endpoints: ["PC2:eth1", "router2:eth3"]
- endpoints: ["PC3:eth1", "router3:eth3"]
解释:最上面的name是用来指定实验的名称,接下来是实验拓扑,node是节点信息(可以是路由器或者主机),links是链路信息(需要将所有链路情况提前配置好)。
创建三个路由器文件夹
mkdir router1
mkdir router2
mkdir router3
将标准 FRR 守护程序配置文件从 FRR 文档复制到 frrlab/router1 目录。
编辑文件daemons
vi router1/daemons
文件内容如下:
zebra=yes
bgpd=yes
ospfd=yes
ospf6d=no
ripd=no
ripngd=no
isisd=yes
pimd=no
ldpd=yes
nhrpd=no
eigrpd=no
babeld=no
sharpd=no
staticd=no
pbrd=no
bfdd=no
fabricd=no
vtysh_enable=yes
zebra_options=" -s 90000000 --daemon -A 127.0.0.1"
bgpd_options=" --daemon -A 127.0.0.1"
ospfd_options=" --daemon -A 127.0.0.1"
ospf6d_options=" --daemon -A ::1"
ripd_options=" --daemon -A 127.0.0.1"
ripngd_options=" --daemon -A ::1"
isisd_options=" --daemon -A 127.0.0.1"
pimd_options=" --daemon -A 127.0.0.1"
ldpd_options=" --daemon -A 127.0.0.1"
nhrpd_options=" --daemon -A 127.0.0.1"
eigrpd_options=" --daemon -A 127.0.0.1"
babeld_options=" --daemon -A 127.0.0.1"
sharpd_options=" --daemon -A 127.0.0.1"
staticd_options=" --daemon -A 127.0.0.1"
pbrd_options=" --daemon -A 127.0.0.1"
bfdd_options=" --daemon -A 127.0.0.1"
fabricd_options=" --daemon -A 127.0.0.1"
将需要的协议设置为yes,其他的无需修改。
再将此文件复制到router2和router3中。
cp router1/daemons router2/daemons
cp router1/daemons router3/daemons
3.2 开始实验
sudo clab deploy --topo frrlab.yml
第一次开始实验,会自动拉取不存在的镜像,输出结果参考如下:
ubuntu@ubuntu-virtual-machine:~/Documents/frrlab$ sudo clab deploy --topo frrlab.yml
INFO[0000] Containerlab v0.25.1 started
INFO[0000] Parsing & checking topology file: frrlab.yml
INFO[0000] Could not read docker config: open /root/.docker/config.json: no such file or directory
INFO[0000] Pulling docker.io/praqma/network-multitool:latest Docker image
INFO[0017] Done pulling docker.io/praqma/network-multitool:latest
INFO[0017] Could not read docker config: open /root/.docker/config.json: no such file or directory
INFO[0017] Pulling docker.io/frrouting/frr:v8.2.2 Docker image
INFO[0039] Done pulling docker.io/frrouting/frr:v8.2.2
WARN[0039] it appears that container host has low memory available: ~0Gi. This might lead to runtime errors. Consider freeing up more memory.
INFO[0039] Creating lab directory: /home/ubuntu/Documents/frrlab/clab-frrlab
INFO[0039] Creating docker network: Name="clab", IPv4Subnet="172.20.20.0/24", IPv6Subnet="2001:172:20:20::/64", MTU="1500"
INFO[0039] Creating container: "PC3"
INFO[0039] Creating container: "PC2"
INFO[0039] Creating container: "router1"
INFO[0039] Creating container: "router2"
INFO[0039] Creating container: "router3"
INFO[0039] Creating container: "PC1"
INFO[0042] Creating virtual wire: router1:eth2 <--> router3:eth1
INFO[0042] Creating virtual wire: PC1:eth1 <--> router1:eth3
INFO[0042] Creating virtual wire: PC3:eth1 <--> router3:eth3
INFO[0042] Creating virtual wire: router1:eth1 <--> router2:eth1
INFO[0042] Creating virtual wire: router2:eth2 <--> router3:eth2
INFO[0042] Creating virtual wire: PC2:eth1 <--> router2:eth3
INFO[0042] Adding containerlab host entries to /etc/hosts file
+---+---------------------+--------------+---------------------------------+-------+---------+----------------+----------------------+
| # | Name | Container ID | Image | Kind | State | IPv4 Address | IPv6 Address |
+---+---------------------+--------------+---------------------------------+-------+---------+----------------+----------------------+
| 1 | clab-frrlab-PC1 | d4368366a177 | praqma/network-multitool:latest | linux | running | 172.20.20.2/24 | 2001:172:20:20::2/64 |
| 2 | clab-frrlab-PC2 | 279354f71711 | praqma/network-multitool:latest | linux | running | 172.20.20.4/24 | 2001:172:20:20::4/64 |
| 3 | clab-frrlab-PC3 | c10795ed2b97 | praqma/network-multitool:latest | linux | running | 172.20.20.7/24 | 2001:172:20:20::7/64 |
| 4 | clab-frrlab-router1 | dc5812c965d0 | frrouting/frr:v8.2.2 | linux | running | 172.20.20.3/24 | 2001:172:20:20::3/64 |
| 5 | clab-frrlab-router2 | ce6c5ea09c7c | frrouting/frr:v8.2.2 | linux | running | 172.20.20.5/24 | 2001:172:20:20::5/64 |
| 6 | clab-frrlab-router3 | bddb6390cdd8 | frrouting/frr:v8.2.2 | linux | running | 172.20.20.6/24 | 2001:172:20:20::6/64 |
+---+---------------------+--------------+---------------------------------+-------+---------+----------------+----------------------+
配置网络节点的IP地址与路由信息:
PC1配置:
sudo docker exec -it clab-frrlab-PC1 /bin/ash
ip addr add 192.168.11.2/24 dev eth1
ip route add 192.168.0.0/16 via 192.168.11.1 dev eth1
ip route add 10.10.10.0/24 via 192.168.11.1 dev eth1
exit
PC2配置:
sudo docker exec -it clab-frrlab-PC2 /bin/ash
ip addr add 192.168.12.2/24 dev eth1
ip route add 192.168.0.0/16 via 192.168.12.1 dev eth1
ip route add 10.10.10.0/24 via 192.168.12.1 dev eth1
exit
PC3配置:
sudo docker exec -it clab-frrlab-PC3 /bin/ash
ip addr add 192.168.13.2/24 dev eth1
ip route add 192.168.0.0/16 via 192.168.13.1 dev eth1
ip route add 10.10.10.0/24 via 192.168.13.1 dev eth1
exit
router的配置可以通过vtysh来进行
router1的配置:
sudo docker exec -it clab-frrlab-router1 vtysh
configure terminal
service integrated-vtysh-config
interface eth1
ip address 192.168.1.1/24
exit
interface eth2
ip address 192.168.2.1/24
exit
interface eth3
ip address 192.168.11.1/24
exit
interface lo
ip address 10.10.10.1/32
exit
exit
write
exit
router2的配置:
sudo docker exec -it clab-frrlab-router2 vtysh
configure terminal
service integrated-vtysh-config
interface eth1
ip address 192.168.1.2/24
exit
interface eth2
ip address 192.168.3.1/24
exit
interface eth3
ip address 192.168.12.1/24
exit
interface lo
ip address 10.10.10.2/32
exit
exit
write
exit
router3的配置:
sudo docker exec -it clab-frrlab-router3 vtysh
configure terminal
service integrated-vtysh-config
interface eth1
ip address 192.168.2.2/24
exit
interface eth2
ip address 192.168.3.2/24
exit
interface eth3
ip address 192.168.13.1/24
exit
interface lo
ip address 10.10.10.3/32
exit
exit
write
exit
到此,我们配置好了3个PC的IP地址与路由信息,3个路由器的IP地址。
于是每个PC应该能够ping通和它相连的路由器,但是ping不通其他的PC或路由器,因为路由器之间的路由信息没有配置。(后续给大家分享路由器配置路由的相关实验)
测试ping命令如下。
sudo docker exec -it clab-frrlab-PC1 /bin/ash
ping -c1 192.168.11.1
ping -c1 192.168.13.2
到此,Containerlab的测试结束。
再给大家介绍一下Containerlab的一个小功能,自动生成拓扑:
sudo containerlab graph --topo frrlab.yml
输出结果中给出一个网址http://0.0.0.0:50080,点击该网址即可查看拓扑。
ubuntu@ubuntu-virtual-machine:~/Documents/frrlab$ sudo containerlab graph --topo frrlab.yml
INFO[0000] Parsing & checking topology file: frrlab.yml
INFO[0000] Serving static files from directory: /etc/containerlab/templates/graph/nextui/static
INFO[0000] Serving topology graph on http://0.0.0.0:50080
最后,试验结束记得摧毁拓扑。
sudo clab destroy --topo frrlab.yml