利用quagga实现动态路由

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

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

    原始作者:季亚


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


Step2 安装quagga软件包

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

Route1:

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

[plain] view plain copy
  1. [root@localhost ~]# yum install quagga  
  2. Failed to set locale, defaulting to C  
  3. Loading "downloadonly" plugin  
  4. Loading "protectbase" plugin  
  5. Loading "skip-broken" plugin  
  6. Loading "installonlyn" plugin  
  7. Loading "changelog" plugin  
  8. Loading "kmod" plugin  
  9. Loading "security" plugin  
  10. Cannot open logfile //var/log/yum.log  
  11. Setting up Install Process  
  12. Setting up repositories  
  13. Reading repository metadata in from local files  
  14. 0 packages excluded due to repository protections  
  15. Parsing package install arguments  
  16. Resolving Dependencies  
  17. --> Populating transaction set with selected packages. Please wait.  
  18. ---> Downloading header for quagga to pack into transaction set.  
  19. quagga-0.98.6-5.el5_5.2.i 100% |=========================|  20 kB    00:00       
  20. ---> Package quagga.i386 0:0.98.6-5.el5_5.2 set to be updated  
  21. --> Running transaction check  
  22.   
  23. Dependencies Resolved  
  24.   
  25. =============================================================================  
  26.  Package                 Arch       Version          Repository        Size   
  27. =============================================================================  
  28. Installing:  
  29.  quagga                  i386       0.98.6-5.el5_5.2  base              1.1 M  
  30.   
  31. Transaction Summary  
  32. =============================================================================  
  33. Install      1 Package(s)           
  34. Update       0 Package(s)           
  35. Remove       0 Package(s)           
  36.   
  37. Total download size: 1.1 M  
  38. Is this ok [y/N]: y  
  39. Downloading Packages:  
  40. (1/1): quagga-0.98.6-5.el 100% |=========================| 1.1 MB    00:00       
  41. Running Transaction Test  
  42. warning: quagga-0.98.6-5.el5_5.2: Header V3 DSA signature: NOKEY, key ID e8562897  
  43. Finished Transaction Test  
  44. Transaction Test Succeeded  
  45. Running Transaction  
  46.   Installing: quagga                       ######################### [1/1]   
  47.   
  48. Installed: quagga.i386 0:0.98.6-5.el5_5.2  
  49. Complete!  
  50. [root@localhost ~]#   

Route2:

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

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

[plain] view plain copy
  1. [root@localhost ~]# /etc/init.d/zebra restart  
  2. 启动 zebra  
  3. [确定]  
  4. [root@localhost ~]#   

Step3 配置quagga

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

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

[plain] view plain copy
  1. [root@localhost ~]# vi /etc/quagga/zebra.conf  
  2.   
  3. hostname localhost.route1             #给这个路由器随便设置一个主机名称  
  4. password 19901012                     #设置一个密码  
  5. enable password 19901012              #使这个密码生效  
  6. log file zebra.log                    #将所有zebra产生的信息保存到日志文件中  
  7.   
  8. ~  
  9. ~  
  10. ~  
  11. ~  
  12. ~  
  13. ~  
  14. ~  
  15. ~  
  16. ~  
  17. ~  
  18. ~  
  19. ~  
  20. ~  
  21. "/etc/quagga/zebra.conf" 10L, 291C written  
  22. [root@localhost ~]# /etc/init.d/zebra restart  
  23. 关闭 zebra:[确定]  
  24. 启动 zebra:can't open logfile zebra.log  
  25. [确定]  
  26. [root@localhost ~]# netstat -tunlp  
  27. Active Internet connections (only servers)  
  28. Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name     
  29. tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      2170/hpiod            
  30. tcp        0      0 0.0.0.0:870                 0.0.0.0:*                   LISTEN      1960/rpc.statd        
  31. tcp        0      0 127.0.0.1:2601              0.0.0.0:*                   LISTEN      6004/zebra             //请注意本行,2601是zebra的侦听端口  
  32. tcp        0      0 127.0.0.1:2602              0.0.0.0:*                   LISTEN      5679/ripd             
  33. tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1931/portmap          
  34. tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      2255/vsftpd           
  35. tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      2216/cupsd            
  36. tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2278/sendmail: acce   
  37. tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      2175/python           
  38. tcp        0      0 :::22                       :::*                        LISTEN      2204/sshd             
  39. udp        0      0 0.0.0.0:32768               0.0.0.0:*                               2407/avahi-daemon:    
  40. udp        0      0 0.0.0.0:520                 0.0.0.0:*                               5679/ripd             
  41. udp        0      0 0.0.0.0:864                 0.0.0.0:*                               1960/rpc.statd        
  42. udp        0      0 0.0.0.0:867                 0.0.0.0:*                               1960/rpc.statd        
  43. udp        0      0 0.0.0.0:5353                0.0.0.0:*                               2407/avahi-daemon:    
  44. udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1931/portmap          
  45. udp        0      0 0.0.0.0:631                 0.0.0.0:*                               2216/cupsd            
  46. udp        0      0 192.168.2.254:123           0.0.0.0:*                               2242/ntpd             
  47. udp        0      0 192.168.1.250:123           0.0.0.0:*                               2242/ntpd             
  48. udp        0      0 127.0.0.1:123               0.0.0.0:*                               2242/ntpd             
  49. udp        0      0 0.0.0.0:123                 0.0.0.0:*                               2242/ntpd             
  50. udp        0      0 :::32769                    :::*                                    2407/avahi-daemon:    
  51. udp        0      0 :::5353                     :::*                                    2407/avahi-daemon:    
  52. udp        0      0 fe80::5278:4cff:fe4:123     :::*                                    2242/ntpd             
  53. udp        0      0 fe80::211:5bff:fe22:123     :::*                                    2242/ntpd             
  54. udp        0      0 ::1:123                     :::*                                    2242/ntpd             
  55. udp        0      0 :::123                      :::*                                    2242/ntpd             
  56. [root@localhost ~]#   
我们注意到,zebra它所监听的本地接口端口为2601,另外,我们在zebra.conf文件中设置用户的登录密码是有效的,可以让我们登录zebra这套软件。现在,我们来查一查2601号端口是否正确的启动:


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

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

[plain] view plain copy
  1. [root@localhost ~]# vi /etc/quagga/zebra.conf  
  2.   
  3. hostname localhost.route1  
  4. password 19901012  
  5. enable password 19901012  
  6. log file zebra.log  

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

[plain] view plain copy
  1. [root@localhost ~]# vi /etc/quagga/zebra.conf  
  2.   
  3. hostname localhost.route2  
  4. password 19901012  
  5. enable password 19901012  
  6. log file zebra.log  
  7. #ip route 192.168.1.0/24 192.168.2.254  
  8. #ip route 192.168.1.0/24 p2p1  

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

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

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

在Route1和Route2都设置妥当之后,可以登录zebra去看这两台主机的路由更新结果,操作命令如下。
Route1:
[plain] view plain copy
  1. [root@localhost ~]# telnet localhost 2601  
  2. Trying 127.0.0.1...  
  3. Connected to localhost.localdomain (127.0.0.1).  
  4. Escape character is '^]'.  
  5.   
  6. Hello, this is Quagga (version 0.98.6).  
  7. Copyright 1996-2005 Kunihiro Ishiguro, et al.  
  8.   
  9.   
  10. User Access Verification  
  11.   
  12. Password:   
  13. localhost.route1> show ip route  
  14. Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,  
  15.        I - ISIS, B - BGP, > - selected route, * - FIB route  
  16.   
  17. K>* 0.0.0.0/0 via 192.168.2.253, eth0  
  18. C>* 127.0.0.0/8 is directly connected, lo  
  19. K>* 169.254.0.0/16 is directly connected, eth1  
  20. C>* 192.168.1.0/24 is directly connected, eth1  
  21. C>* 192.168.2.0/24 is directly connected, eth0  
  22. localhost.route1>   

Route2:
[plain] view plain copy
  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网关就好了) ,详细内容请参考本人CSDN其他博文:http://blog.csdn.net/shuxiao9058/article/details/6897955

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值