利用quagga实现动态路由

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

Step2 安装quagga软件包
首先查看Route1和Route2是否都装有quagga软件包。
Route1:
由于Route1机器没有安装quagga软件包,但是又没有更新源,所以还要配置rhel更新源,详细操作参照本人博客其他博文。
[root@localhost ~]# yum install quagga  
 
Route2:
1.     [root@localhost ~]# rpm -qa quagga  
2.     quagga-0.99.20-2.fc15.i686  
3.     [root@localhost ~]#   
由此可见,Route2已经安装quagga软件包了,因此无需重复安装。
然后重新启动zebra,操作命令如下所示:
 
[root@localhost ~]# /etc/init.d/zebra restart  
1.     启动 zebra  
2.     [确定]  
3.     [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  
1.       
2.     hostname localhost.route1             #给这个路由器随便设置一个主机名称  
3.     password 19901012                     #设置一个密码  
4.     enable password 19901012              #使这个密码生效  
5.     log file zebra.log                    #将所有zebra产生的信息保存到日志文件中  
6.       
7.     "/etc/quagga/zebra.conf" 10L, 291C written  
8.     [root@localhost ~]# /etc/init.d/zebra restart  
9.     关闭 zebra:[确定]  
10.启动 zebra:can't open logfile zebra.log  
11.[确定]  
12.[root@localhost ~]# netstat -tunlp  
13.Active Internet connections (only servers)  
14.Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name     
15.tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      2170/hpiod            
16.tcp        0      0 0.0.0.0:870                 0.0.0.0:*                   LISTEN      1960/rpc.statd        
17.tcp        0      0 127.0.0.1:2601              0.0.0.0:*                   LISTEN      6004/zebra             // 请注意本行,2601是zebra的侦听端口  
18.tcp        0      0 127.0.0.1:2602              0.0.0.0:*                   LISTEN      5679/ripd             
19.tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1931/portmap          
20.tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      2255/vsftpd           
21.tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2216/cupsd            
22.tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2278/sendmail: acce   
23.tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      2175/python           
24.tcp        0      0 :::22                       :::*                        LISTEN      2204/sshd             
25.udp        0      0 0.0.0.0:32768               0.0.0.0:*                               2407/avahi-daemon:    
26.udp        0      0 0.0.0.0:520                 0.0.0.0:*                               5679/ripd             
27.udp        0      0 0.0.0.0:864                 0.0.0.0:*                               1960/rpc.statd        
28.udp        0      0 0.0.0.0:867                 0.0.0.0:*                               1960/rpc.statd        
29.udp        0      0 0.0.0.0:5353                0.0.0.0:*                               2407/avahi-daemon:    
30.udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1931/portmap          
31.udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2216/cupsd            
32.udp        0      0 192.168.2.254:123           0.0.0.0:*                               2242/ntpd             
33.udp        0      0 192.168.1.250:123           0.0.0.0:*                               2242/ntpd             
34.udp        0      0 127.0.0.1:123               0.0.0.0:*                               2242/ntpd             
35.udp        0      0 0.0.0.0:123                 0.0.0.0:*                               2242/ntpd             
36.udp        0      0 :::32769                    :::*                                    2407/avahi-daemon:    
37.udp        0      0 :::5353                     :::*                                    2407/avahi-daemon:    
38.udp        0      0 fe80::5278:4cff:fe4:123     :::*                                    2242/ntpd             
39.udp        0      0 fe80::211:5bff:fe22:123     :::*                                    2242/ntpd             
40.udp        0      0 ::1:123                     :::*                                    2242/ntpd             
41.udp        0      0 :::123                      :::*                                    2242/ntpd             
42.[root@localhost ~]#   
我们注意到,zebra它所监听的本地接口端口为2601,另外,我们在zebra.conf文件中设置用户的登录密码是有效的,可以让我们登录zebra这套软件。现在,我们来查一查2601号端口是否正确的启动:
 
事实上,我们还想要增加额外的静态路由,也可以通过zebra而不必使用route命令,详细内容请参考鸟哥的Linux私房菜 服务器架设篇(第二版)相关内容。
下面是Route1->zebra.conf文件中的内容:
 
[root@localhost ~]# vi /etc/quagga/zebra.conf  
1.       
2.     hostname localhost.route1  
3.     password 19901012  
4.     enable password 19901012  
5.     log file zebra.log  
下面是Route2->zebra.conf文件中的内容:
[root@localhost ~]# vi /etc/quagga/zebra.conf  
1.       
2.     hostname localhost.route2  
3.     password 19901012  
4.     enable password 19901012  
5.     log file zebra.log  
6.     #ip route 192.168.1.0/24 192.168.2.254  
7.     #ip route 192.168.1.0/24 p2p1  

Step4 设置ripd服务
ripd服务可以在两个router之间进行路由规则的交换与沟通,当然如果网络环境里有类似Cisco或者其他有提供RIP协议的路由器的话,当然也可以通过RIP让Linux Router与其他硬件路由器相互沟通,下面来设置ripd:
Route1:
1.     [root@localhost ~]# vi /etc/quagga/ripd.conf  
2.       
3.     hostname linux.route1  
4.     password 19901012  
5.     router rip  
6.     network 192.168.1.0/24  
7.     network 192.168.2.0/24  
8.     network 192.168.3.0/24  
9.     network eth0  
10.network eth1  
11.version 2  
12.log stdout  

Route2:
[root@localhost ~]# vi /etc/quagga/ripd.conf  
1.       
2.     hostname linux.route2  
3.     password 19901012  
4.     router rip  
5.     network 192.168.2.0/24  
6.     network 192.168.3.0/24  
7.     network p1p1  
8.     network p2p1  
9.     version 2  
10.log stdout  

然后分别重启下ripd服务,操作命令如下所示:
 
1.     [root@localhost ~]# /etc/init.d/ripd restart  
2.     关闭 ripd:[确定]  
3.     启动 ripd:[确定]  
4.     [root@localhost ~]#   
这样,便完成了路由器的RIP动态路由协议的设置。
 
Step5 检查RIP协议的沟通结果(测试)
在Route1和Route2都设置妥当之后,可以登录zebra去看这两台主机的路由更新结果,操作命令如下。
Route1:
 
[root@localhost ~]# telnet localhost 2601  
1.     Trying 127.0.0.1...  
2.     Connected to localhost.localdomain (127.0.0.1).  
3.     Escape character is '^]'.  
4.       
5.     Hello, this is Quagga (version 0.98.6).  
6.     Copyright 1996-2005 Kunihiro Ishiguro, et al.  
7.       
8.       
9.     User Access Verification  
10.  
11.Password:   
12.localhost.route1> show ip route  
13.Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,  
14.       I - ISIS, B - BGP, > - selected route, * - FIB route  
15.  
16.K>* 0.0.0.0/0 via 192.168.2.253, eth0  
17.C>* 127.0.0.0/8 is directly connected, lo  
18.K>* 169.254.0.0/16 is directly connected, eth1  
19.C>* 192.168.1.0/24 is directly connected, eth1  
20.C>* 192.168.2.0/24 is directly connected, eth0  
21.localhost.route1>   
 
Route2:
 
1.     ~  
2.     [root@localhost ~]# telnet localhost 2601  
3.     Trying ::1...  
4.     telnet: connect to address ::1: Connection refused  
5.     Trying 127.0.0.1...  
6.     Connected to localhost.  
7.     Escape character is '^]'.  
8.       
9.     Hello, this is Quagga (version 0.99.20).  
10.Copyright 1996-2005 Kunihiro Ishiguro, et al.  
11.  
12.  
13.User Access Verification  
14.  
15.Password:   
16.localhost.route2> show ip route  
17.Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,  
18.       I - ISIS, B - BGP, > - selected route, * - FIB route  
19.  
20.K>* 0.0.0.0/0 via 210.28.164.254, em1  
21.C>* 127.0.0.0/8 is directly connected, lo  
22.R>* 192.168.1.0/24 [120/2] via 192.168.2.254, p2p1, 00:13:14  
23.C>* 192.168.2.0/24 is directly connected, p2p1  
24.C>* 192.168.3.0/24 is directly connected, p1p1  
25.C>* 192.168.10.0/24 is directly connected, p1p1  
26.C>* 210.28.164.0/24 is directly connected, em1  
27.localhost.route2>   
如此,看到上面的路由信息,就说明我们成功了!最左边的R代表通过RIP通信协议所设置的路由规则,这样,路由器的设置就搞定了。
 
备注:如果希望能够在A、B、C这三个网段能够上网,还需要其他的一些配置(只要和外网连的那台路由器做NAT网关就好了),
 
 
 

你可能感兴趣的:(quagga,实现动态路由)