利用quagga实现动态路由

    版权声明:对于本博客所有原创文章,允许个人、教育和非商业目的使用,但务必保证文章的完整性且不作任何修改地以超链接形式注明原始作者、出处及本声明。

    博客地址:http://blog.csdn.net/shuxiao9058

    原始作者:季亚


Step1 按照先前搭建的网络环境进行配置。


Step2 安装quagga软件包

首先查看Route1和Route2是否都装有quagga软件包。

Route1:

由于Route1机器没有安装quagga软件包,但是又没有更新源,所以还要配置rhel更新源,详细操作参照本人博客其他博文。

[root@localhost ~]# yum install quagga
Failed to set locale, defaulting to C
Loading "downloadonly" plugin
Loading "protectbase" plugin
Loading "skip-broken" plugin
Loading "installonlyn" plugin
Loading "changelog" plugin
Loading "kmod" plugin
Loading "security" plugin
Cannot open logfile //var/log/yum.log
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
0 packages excluded due to repository protections
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for quagga to pack into transaction set.
quagga-0.98.6-5.el5_5.2.i 100% |=========================|  20 kB    00:00     
---> Package quagga.i386 0:0.98.6-5.el5_5.2 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 quagga                  i386       0.98.6-5.el5_5.2  base              1.1 M

Transaction Summary
=============================================================================
Install      1 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 1.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/1): quagga-0.98.6-5.el 100% |=========================| 1.1 MB    00:00     
Running Transaction Test
warning: quagga-0.98.6-5.el5_5.2: Header V3 DSA signature: NOKEY, key ID e8562897
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: quagga                       ######################### [1/1] 

Installed: quagga.i386 0:0.98.6-5.el5_5.2
Complete!
[root@localhost ~]# 

Route2:

[root@localhost ~]# rpm -qa quagga
quagga-0.99.20-2.fc15.i686
[root@localhost ~]# 
由此可见,Route2已经安装quagga软件包了,因此无需重复安装。

然后重新启动zebra,操作命令如下所示:

[root@localhost ~]# /etc/init.d/zebra restart
启动 zebra
[确定]
[root@localhost ~]# 

Step3 配置quagga

下面我们就开是配置了,配置过程中主要用到了两个文件/etc/quagga/zebra.conf和/etc/quagga/ripd.conf,其中zebra.conf可以增加静态路由,而ripd.conf则可以添加动态路由相关规则,本教程是参考鸟哥的Linux私房菜 服务器架设篇(第二版)进行整理的,大家可以参考本书P195-199页的内容。

我们先设置Route1,关于zebra.conf,进行如下设置:

[root@localhost ~]# vi /etc/quagga/zebra.conf

hostname localhost.route1             #给这个路由器随便设置一个主机名称
password 19901012                     #设置一个密码
enable password 19901012              #使这个密码生效
log file zebra.log                    #将所有zebra产生的信息保存到日志文件中

~
~
~
~
~
~
~
~
~
~
~
~
~
"/etc/quagga/zebra.conf" 10L, 291C written
[root@localhost ~]# /etc/init.d/zebra restart
关闭 zebra:[确定]
启动 zebra:can't open logfile zebra.log
[确定]
[root@localhost ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      2170/hpiod          
tcp        0      0 0.0.0.0:870                 0.0.0.0:*                   LISTEN      1960/rpc.statd      
tcp        0      0 127.0.0.1:2601              0.0.0.0:*                   LISTEN      6004/zebra             //请注意本行,2601是zebra的侦听端口
tcp        0      0 127.0.0.1:2602              0.0.0.0:*                   LISTEN      5679/ripd           
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1931/portmap        
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      2255/vsftpd         
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2216/cupsd          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2278/sendmail: acce 
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      2175/python         
tcp        0      0 :::22                       :::*                        LISTEN      2204/sshd           
udp        0      0 0.0.0.0:32768               0.0.0.0:*                               2407/avahi-daemon:  
udp        0      0 0.0.0.0:520                 0.0.0.0:*                               5679/ripd           
udp        0      0 0.0.0.0:864                 0.0.0.0:*                               1960/rpc.statd      
udp        0      0 0.0.0.0:867                 0.0.0.0:*                               1960/rpc.statd      
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               2407/avahi-daemon:  
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1931/portmap        
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2216/cupsd          
udp        0      0 192.168.2.254:123           0.0.0.0:*                               2242/ntpd           
udp        0      0 192.168.1.250:123           0.0.0.0:*                               2242/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               2242/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               2242/ntpd           
udp        0      0 :::32769                    :::*                                    2407/avahi-daemon:  
udp        0      0 :::5353                     :::*                                    2407/avahi-daemon:  
udp        0      0 fe80::5278:4cff:fe4:123     :::*                                    2242/ntpd           
udp        0      0 fe80::211:5bff:fe22:123     :::*                                    2242/ntpd           
udp        0      0 ::1:123                     :::*                                    2242/ntpd           
udp        0      0 :::123                      :::*                                    2242/ntpd           
[root@localhost ~]# 
我们注意到,zebra它所监听的本地接口端口为2601,另外,我们在zebra.conf文件中设置用户的登录密码是有效的,可以让我们登录zebra这套软件。现在,我们来查一查2601号端口是否正确的启动:


事实上,我们还想要增加额外的静态路由,也可以通过zebra而不必使用route命令,详细内容请参考鸟哥的Linux私房菜 服务器架设篇(第二版)相关内容。

下面是Route1->zebra.conf文件中的内容:

[root@localhost ~]# vi /etc/quagga/zebra.conf

hostname localhost.route1
password 19901012
enable password 19901012
log file zebra.log

下面是Route2->zebra.conf文件中的内容:

[root@localhost ~]# vi /etc/quagga/zebra.conf

hostname localhost.route2
password 19901012
enable password 19901012
log file zebra.log
#ip route 192.168.1.0/24 192.168.2.254
#ip route 192.168.1.0/24 p2p1

Step4 设置ripd服务

ripd服务可以在两个router之间进行路由规则的交换与沟通,当然如果网络环境里有类似Cisco或者其他有提供RIP协议的路由器的话,当然也可以通过RIP让Linux Router与其他硬件路由器相互沟通,下面来设置ripd:
Route1:
[root@localhost ~]# vi /etc/quagga/ripd.conf

hostname linux.route1
password 19901012
router rip
network 192.168.1.0/24
network 192.168.2.0/24
network 192.168.3.0/24
network eth0
network eth1
version 2
log stdout

Route2:
[root@localhost ~]# vi /etc/quagga/ripd.conf

hostname linux.route2
password 19901012
router rip
network 192.168.2.0/24
network 192.168.3.0/24
network p1p1
network p2p1
version 2
log stdout

然后分别重启下ripd服务,操作命令如下所示:
[root@localhost ~]# /etc/init.d/ripd restart
关闭 ripd:[确定]
启动 ripd:[确定]
[root@localhost ~]# 
这样,便完成了路由器的RIP动态路由协议的设置。

Step5 检查RIP协议的沟通结果(测试)

在Route1和Route2都设置妥当之后,可以登录zebra去看这两台主机的路由更新结果,操作命令如下。
Route1:
[root@localhost ~]# telnet localhost 2601
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.

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


User Access Verification

Password: 
localhost.route1> show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
       I - ISIS, B - BGP, > - selected route, * - FIB route

K>* 0.0.0.0/0 via 192.168.2.253, eth0
C>* 127.0.0.0/8 is directly connected, lo
K>* 169.254.0.0/16 is directly connected, eth1
C>* 192.168.1.0/24 is directly connected, eth1
C>* 192.168.2.0/24 is directly connected, eth0
localhost.route1> 

Route2:
~
[root@localhost ~]# telnet localhost 2601
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

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


User Access Verification

Password: 
localhost.route2> show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
       I - ISIS, B - BGP, > - selected route, * - FIB route

K>* 0.0.0.0/0 via 210.28.164.254, em1
C>* 127.0.0.0/8 is directly connected, lo
R>* 192.168.1.0/24 [120/2] via 192.168.2.254, p2p1, 00:13:14
C>* 192.168.2.0/24 is directly connected, p2p1
C>* 192.168.3.0/24 is directly connected, p1p1
C>* 192.168.10.0/24 is directly connected, p1p1
C>* 210.28.164.0/24 is directly connected, em1
localhost.route2> 

如此,看到上面的路由信息,就说明我们成功了!最左边的R代表通过RIP通信协议所设置的路由规则,这样,路由器的设置就搞定了。

备注:如果希望能够在A、B、C这三个网段能够上网,还需要其他的一些配置( 只要和外网连的那台路由器做NAT网关就好了) ,详细内容请参考本人CSDN其他博文:http://blog.csdn.net/shuxiao9058/article/details/6897955

你可能感兴趣的:(〖林纳克斯〗)