安装quagga

1
apt install quagga

拓扑

TOPO

配置RouterA

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# root @ routerA in / [11:37:11]
$ grep -v "^#" /etc/quagga/debian.conf
vtysh_enable=yes
zebra_options=" --daemon -A 127.0.0.1"
ospfd_options=" --daemon -A 127.0.0.1"
watchquagga_enable=yes
watchquagga_options=(--daemon)

# root @ routerA in / [11:37:21]
$ grep -v "^#" /etc/quagga/zebra.conf
hostname Router_A #各路由不一样
password testpassword
enable password testpassword

# root @ routerA in / [11:37:26]
$ grep -v "^#" /etc/quagga/ospfd.conf
hostname Router_A #跟zebra.conf一样
password testpassword
enable password testpassword
router ospf
ospf router-id 30.1.1.2 #自身的ip,连接邻居路由
network 10.2.1.0/24 area 1
network 30.1.1.0/24 area 0 #邻居相同网段 area也需要是0
debug ospf event
log file /usr/local/etc/ospfd.log

# root @ routerA in / [11:37:32]
$ grep -v "^#" /etc/quagga/daemons
zebra=yes
ospfd=yes

# root @ routerA in / [11:37:39]
$ systemctl restart quagga.service

配置RouterB

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# root @ routerB in / [11:39:11]
$ grep -v "^#" /etc/quagga/debian.conf
vtysh_enable=yes
zebra_options=" --daemon -A 127.0.0.1"
ospfd_options=" --daemon -A 127.0.0.1"
watchquagga_enable=yes
watchquagga_options=(--daemon)

# root @ routerB in / [11:39:18]
$ grep -v "^#" /etc/quagga/zebra.conf
hostname Router_B #各路由不一样
password testpassword
enable password testpassword

# root @ routerB in / [11:39:24]
$ grep -v "^#" /etc/quagga/ospfd.conf
hostname Router_B #跟zebra.conf一样
password testpassword
enable password testpassword
router ospf
ospf router-id 30.1.1.1 #自身的ip,连接邻居路由
network 10.1.1.0/24 area 1
network 30.1.1.0/24 area 0 #邻居相同网段 area也需要是0
debug ospf event
log file /usr/local/etc/ospfd.log

# root @ routerB in / [11:39:31]
$ grep -v "^#" /etc/quagga/daemons
zebra=yes
ospfd=yes

# root @ routerB in / [11:39:37]
$ systemctl restart quagga.service

调试

1
2
3
4
$ journalctl -u quagga.service
...
Sep 27 11:25:29 ubuntu watchquagga[12328]: ospfd state -> up : connect succeeded
Sep 27 11:25:29 ubuntu watchquagga[12328]: zebra state -> up : connect succeeded

查看结果

1
2
3
4
5
6
# root @ routerA in / [11:41:51]
$ ip route
10.1.1.0/24 via 30.1.1.1 dev eth1 proto zebra metric 20
10.2.1.0/24 dev eth0 proto kernel scope link src 10.2.1.1
30.1.1.0/24 dev eth1 proto kernel scope link src 30.1.1.2
192.168.255.0/24 dev eth3 proto kernel scope link src 192.168.255.1

routerA的路由表出现了 10.1.1.0/24 via 30.1.1.1 dev eth1 proto zebra metric 20

1
2
3
4
5
6
7
# root @ routerB in / [11:39:49]
$ ip route
10.1.1.0/24 dev eth0 proto kernel scope link src 10.1.1.1 linkdown
10.2.1.0/24 via 30.1.1.2 dev eth1 proto zebra metric 20
30.1.1.0/24 dev eth1 proto kernel scope link src 30.1.1.1
192.168.20.0/24 dev eth2 proto kernel scope link src 192.168.20.1 linkdown
192.168.30.0/24 dev eth3 proto kernel scope link src 192.168.30.1 linkdown

routerB的路由表出现了 10.2.1.0/24 via 30.1.1.2 dev eth1 proto zebra metric 20

测试网络通路

PC1 ping PC2

1
2
3
4
5
6
7
# zh @ li in ~ [11:44:36]
$ ping 10.1.1.2
PING 10.1.1.2 (10.1.1.2) 56(84) 字节的数据。
64 字节,来自 10.1.1.1: icmp_seq=1 ttl=64 时间=0.607 毫秒
64 字节,来自 10.1.1.1: icmp_seq=2 ttl=64 时间=0.564 毫秒
64 字节,来自 10.1.1.1: icmp_seq=3 ttl=64 时间=0.602 毫秒
^C

PC2 ping PC1

1
2
3
4
5
6
7
# zh @ li in ~ [11:44:36]
$ ping 10.2.1.2
PING 10.2.1.2 (10.2.1.2) 56(84) 字节的数据。
64 字节,来自 10.2.1.1: icmp_seq=1 ttl=64 时间=0.647 毫秒
64 字节,来自 10.2.1.1: icmp_seq=2 ttl=64 时间=0.534 毫秒
64 字节,来自 10.2.1.1: icmp_seq=3 ttl=64 时间=0.402 毫秒
^C

打开命令行配置

telnet localhost 2601 密码在/etc/quagga/zebra.conf
telnet localhost 2604 密码在/etc/quagga/ospfd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# root @ routerA in / [13:53:38] C:1
$ telnet localhost 2601
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

Hello, this is Quagga (version 0.99.24.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.


User Access Verification

Password:
Router_A> show ip ospf neighbor
...
Router_A> exit
Connection closed by foreign host.

# root @ routerA in / [13:54:03] C:1
$ telnet localhost 2604
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

Hello, this is Quagga (version 0.99.24.1).
Copyright 1996-2005 Kunihiro Ishiguro, et al.


User Access Verification

Password:
Router_A>
Router_A> exit
Connection closed by foreign host.

# root @ routerA in / [13:54:19] C:1
$