热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

RunningQuaggaonLXDtotestOSPF(byquqi99)

作者:张华发表于:2022-01-28版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明

作者:张华 发表于:2022-01-28
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明
( http://blog.csdn.net/quqi99 )


前言

Quagga是一个开源的基于Zebra实现了RIP, OSPF, BGP的动态路由软件。它提供的CLI命令和Cisco IOS类似 - https://blog.csdn.net/quqi99/article/details/9264373
网络测试需要机器来运行Quagga软路由,也需要机器来运行网络测试机,用裸机太麻烦,用虚机也麻烦,容器内的网络是隔离的还是用LXD容器吧  - https://blog.csdn.net/quqi99/article/details/52131486

注意,运行此测试,根目录至少得有5.5G硬盘空间.

sudo /snap/bin/lxc storage list
$ sudo du -h /var/snap/lxd/common/lxd/storage-pools/default |tail -n1
5.5G /var/snap/lxd/common/lxd/storage-pools/default

本测试实现的OSPF网络拓扑如下图所示(也可以使用processon画图) ,两个路由器R1和R2, 两个测试机C1和C1, 三个OSPF AREA (0, 1, 2), 最终的目的得192.168.1.2可以ping通192.168.2.2
B


Install LXD

sudo snap install lxd
#all options use default values except storage backend=dir and ipv6=none
sudo /snap/bin/lxd init
ip addr show lxdbr0
sudo /snap/bin/lxc profile show default
sudo /snap/bin/lxc remote add faster https://mirrors.cloud.tencent.com/ubuntu-cloud-images/releases/server --protocol simplestreams
sudo /snap/bin/lxc launch faster:20.04 R1

Make LXC Template for Router and Client

wget https://github.com/Quagga/quagga/releases/download/quagga-1.2.4/quagga-1.2.4.tar.gz
wget https://c-ares.org/download/c-ares-1.18.1.tar.gz
/snap/bin/lxc file push ./quagga-1.2.4.tar.gz R1/root/
/snap/bin/lxc file push ./c-ares-1.18.1.tar.gz R1/root/
/snap/bin/lxc exec R1 -- /bin/bash
tar -xf quagga-1.2.4.tar.gz
tar -xf c-ares-1.18.1.tar.gz
apt install gawk libreadline8 libreadline-dev pkg-config binutils gcc make -y
cd /root/c-ares-1.18.1
./configure && make && make install
cd ../quagga-1.2.4
./configure --enable-vtysh --enable-user=root --enable-group=root --enable-vty-group=root
make && make install
cat /etc/services
cp /usr/local/etc/zebra.conf.sample /usr/local/etc/zebra.conf
cp /usr/local/etc/vtysh.conf.sample /usr/local/etc/vtysh.conf
cp /usr/local/etc/ospfd.conf.sample /usr/local/etc/ospfd.conf
cp /usr/local/lib/libzebra.so.1 /lib
cp /usr/local/lib/libospf* /lib/
groupadd quagga && useradd quagga -g quagga
zebra -d
apt install net-tools -y
exit
#sudo /snap/bin/lxc image export Quagga_Template . && sudo /snap/bin/lxd import --alias
sudo /snap/bin/lxc publish R1 --alias Quagga_Template --public --forcesudo /snap/bin/lxc launch Quagga_Template C1
sudo /snap/bin/lxc exec C1 -- /bin/bash
apt install net-tools -y
exit
sudo /snap/bin/lxc publish C1 --alias Client_Ubuntu2004 --public --forcesudo /snap/bin/lxc delete R1 --force
sudo /snap/bin/lxc delete C1 --force

Configure R1, R2, C1, C2

# Connect R1 and C1
sudo /snap/bin/lxc launch Quagga_Template R1
sudo /snap/bin/lxc launch Client_Ubuntu2004 C1
sudo /snap/bin/lxc network create C1R1 ipv6.address=none ipv4.address=192.168.1.1/24
sudo /snap/bin/lxc network attach C1R1 C1 eth0
sudo /snap/bin/lxc network attach C1R1 R1 eth1
sudo /snap/bin/lxc exec R1 -- /bin/baship addr add 192.168.1.1/24 dev eth1 && ip link set eth1 up && exit
sudo /snap/bin/lxc exec C1 -- /bin/baship addr add 192.168.1.2/24 dev eth0 && ip link set eth0 uproute add default gw 192.168.1.1ping 192.168.1.1exit# Connect R2 and C2
sudo /snap/bin/lxc launch Quagga_Template R2
sudo /snap/bin/lxc launch Client_Ubuntu2004 C2
sudo /snap/bin/lxc network create C2R2 ipv6.address=none ipv4.address=192.168.2.1/24
sudo /snap/bin/lxc network attach C2R2 C2 eth0
sudo /snap/bin/lxc network attach C2R2 R2 eth1
sudo /snap/bin/lxc exec R2 -- /bin/baship addr add 192.168.2.1/24 dev eth1 && ip link set eth1 up && exit
sudo /snap/bin/lxc exec C2 -- /bin/baship addr add 192.168.2.2/24 dev eth0 && ip link set eth0 uproute add default gw 192.168.2.1ping 192.168.2.1exit# Connect R1R2
sudo /snap/bin/lxc network create R1R2 ipv6.address=none ipv4.address=192.168.0.1/24
sudo /snap/bin/lxc network attach R1R2 R1 eth0
sudo /snap/bin/lxc network attach R1R2 R2 eth0
sudo /snap/bin/lxc exec R1 -- /bin/baship addr add 192.168.0.1/24 dev eth0 && ip link set eth0 up && exit
sudo /snap/bin/lxc exec R2 -- /bin/baship addr add 192.168.0.2/24 dev eth0 && ip link set eth0 up && exit# Configure OSPF on R1
sudo /snap/bin/lxc exec R1 -- /bin/bash
cat <! OSPF configuration file
hostname R1
password password
enable password password
router ospfospf router-id 192.168.0.1network 192.168.0.0/24 area 0network 192.168.1.0/24 area 1
debug ospf event
log file /usr/local/etc/ospfd.log
EOF
zebra -d && ospfd -d && exit# Configure OSPF on R2
sudo /snap/bin/lxc exec R2 -- /bin/bash
cat <! OSPF configuration file
hostname R2
password password
enable password password
router ospfospf router-id 192.168.0.2network 192.168.0.0/24 area 0network 192.168.2.0/24 area 2
debug ospf event
log file /usr/local/etc/ospfd.log
EOF
zebra -d && ospfd -d && exit

Test Result

# Test - C1 -> C2
$ sudo /snap/bin/lxc exec C1 -- /usr/bin/ping 192.168.2.2 -c1
PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
64 bytes from 192.168.2.2: icmp_seq&#61;1 ttl&#61;62 time&#61;0.204 ms

Some Debug Data

sudo /snap/bin/lxc exec R1 -- /bin/bash
vtysh
R1# show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface RXmtL RqstL DBsmL
192.168.0.2 1 Full/Backup 37.551s 192.168.0.2 eth0:192.168.0.1 0 0 0sudo /snap/bin/lxc exec R2 -- /bin/bash
vtysh
R2# show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface RXmtL RqstL DBsmL
192.168.0.1 1 Full/DR 36.633s 192.168.0.1 eth0:192.168.0.2 0 0 0R1# show ip ospf dataOSPF Router with ID (192.168.0.1)Router Link States (Area 0.0.0.0)
Link ID ADV Router Age Seq# CkSum Link count
192.168.0.1 192.168.0.1 815 0x80000004 0x722a 1
192.168.0.2 192.168.0.2 269 0x80000005 0x6e2a 1Net Link States (Area 0.0.0.0)
Link ID ADV Router Age Seq# CkSum
192.168.0.1 192.168.0.1 815 0x80000001 0x941bSummary Link States (Area 0.0.0.0)
Link ID ADV Router Age Seq# CkSum Route
192.168.1.0 192.168.0.1 785 0x80000002 0xfe7e 192.168.1.0/24
192.168.2.0 192.168.0.2 129 0x80000002 0xed8d 192.168.2.0/24R2# show ip ospf dataOSPF Router with ID (192.168.0.2)Router Link States (Area 0.0.0.0)
Link ID ADV Router Age Seq# CkSum Link count
192.168.0.1 192.168.0.1 881 0x80000004 0x722a 1
192.168.0.2 192.168.0.2 333 0x80000005 0x6e2a 1Net Link States (Area 0.0.0.0)
Link ID ADV Router Age Seq# CkSum
192.168.0.1 192.168.0.1 882 0x80000001 0x941bSummary Link States (Area 0.0.0.0)
Link ID ADV Router Age Seq# CkSum Route
192.168.1.0 192.168.0.1 852 0x80000002 0xfe7e 192.168.1.0/24
192.168.2.0 192.168.0.2 193 0x80000002 0xed8d 192.168.2.0/24Router Link States (Area 0.0.0.2)
Link ID ADV Router Age Seq# CkSum Link count
192.168.0.2 192.168.0.2 843 0x80000003 0x3dc6 1Summary Link States (Area 0.0.0.2)
Link ID ADV Router Age Seq# CkSum Route
192.168.0.0 192.168.0.2 293 0x80000003 0x027a 192.168.0.0/24
192.168.1.0 192.168.0.2 871 0x80000001 0x5f14 192.168.1.0/24

Reference

[1] https://blog.csdn.net/salmonwilliam/article/details/108887355


推荐阅读
author-avatar
郭亭婷892
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有