将centos系统变成ospf路由器
Quagga是一个开源路由软件,支持RIP、OSPF、BGP和IS-IS等主要路由协议的路由器:
这里以centos7和H3C交换机组网ospf测试:centos地址是192.168.1.106,H3C交换机地址是192.168.1.252
1、安装quagga服务,并能看到简单的配置文件
[root@RAs ~]# yum install quagga
[root@RAs ~]# cd /usr/share/doc/quagga-0.99.22.4/
[root@RAs quagga-0.99.22.4]# ls -l *.sample
-rw-r--r-- 1 root root 655 Aug 4 2013 babeld.conf.sample
-rw-r--r-- 1 root root 566 Jul 13 2012 bgpd.conf.sample
-rw-r--r-- 1 root root 789 Jul 13 2012 isisd.conf.sample
-rw-r--r-- 1 root root 1110 Jul 13 2012 ospf6d.conf.sample
-rw-r--r-- 1 root root 182 Jul 13 2012 ospfd.conf.sample
-rw-r--r-- 1 root root 406 Jul 13 2012 ripd.conf.sample
-rw-r--r-- 1 root root 390 Jul 13 2012 ripngd.conf.sample
-rw-r--r-- 1 root root 369 Jul 13 2012 zebra.conf.sample
2、完成配置ospf的配置:
将配置文件复制到指定目录下:
[root@RAs ~]# cp /usr/share/doc/quagga-0.99.22.4/ospfd.conf.sample /etc/quagga/ospfd.conf
[root@RAs ~]# chown quagga.quagga /etc/quagga/ospfd.conf #注意权限问题
[root@RAs ~]# systemctl start zebra #开启守护进程
[root@RAs ~]# systemctl start ospfd #开启ospf进程
[root@RAs ~]# vtysh #进入类似思科路由器一样的终端界面
Centos配置过程:
RAs# configure terminal
RAs(config)# interface lo
RAs(config-if)# ip address 1.1.1.1/32
RAs(config-if)# ip address 172.16.1.254/24
RAs(config-if)# ip address 172.16.2.254/24
RAs(config-if)# ip address 172.16.3.254/24
RAs(config-if)# exit
RAs(config)# exit
RAs# show interface
Interface ens33 is up, line protocol detection is disabled
index 2 metric 1 mtu 1500
flags: <UP,BROADCAST,RUNNING,MULTICAST>
HWaddr: 00:0c:29:6a:27:a7
inet 192.168.1.106/24 broadcast 192.168.1.255
inet6 fe80::ba12:9bfa:b522:add7/64
Interface lo is up, line protocol detection is disabled
index 1 metric 1 mtu 65536
flags: <UP,LOOPBACK,RUNNING>
inet 1.1.1.1/32
inet 127.0.0.1/8
inet 172.16.1.254/24 broadcast 172.16.1.255
inet 172.16.2.254/24 broadcast 172.16.2.255
inet 172.16.3.254/24 broadcast 172.16.3.255
inet6 ::1/128
RAs# configure terminal
RAs(config)# router ospf
RAs(config-router)# router-id 1.1.1.1
RAs(config-router)# network 192.168.1.106/24 area 0
RAs(config-router)# network 172.16.1.254/24 area 0
RAs(config-router)# network 172.16.2.254/24 area 0
RAs(config-router)# network 172.16.3.254/24 area 0
RAs(config-router)# exit
RAs(config)# exit
RAs# write
Building Configuration...
Configuration saved to /etc/quagga/zebra.conf
Configuration saved to /etc/quagga/ospfd.conf
[OK]
RAs#
[root@RAs ~]# systemctl restart ospfd
H3C交换机配置过程:
[H3C]interface LoopBack 0
[H3C-LoopBack0]ip address 2.2.2.2 32
[H3C-LoopBack0]interface LoopBack 1
[H3C-LoopBack1]ip address 192.168.11.254 24
[H3C-LoopBack1]interface LoopBack 2
[H3C-LoopBack2]ip address 192.168.12.254 24
[H3C-LoopBack2]interface LoopBack 3
[H3C-LoopBack3]ip address 192.168.13.254 24
[H3C-LoopBack3]quit
[H3C]
[H3C]ospf 1 router-id 2.2.2.2
[H3C-ospf-1]area 0
[H3C-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[H3C-ospf-1-area-0.0.0.0]network 192.168.1.252 0.0.0.0
[H3C-ospf-1-area-0.0.0.0]network 192.168.11.254 0.0.0.0
[H3C-ospf-1-area-0.0.0.0]network 192.168.12.254 0.0.0.0
[H3C-ospf-1-area-0.0.0.0]network 192.168.13.254 0.0.0.0
[H3C-ospf-1-area-0.0.0.0]quit
[H3C-ospf-1]quit
3、检查两端的路由:
RAs# show ip route ospf
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, A - Babel,
> - selected route, * - FIB route
O 1.1.1.1/32 [110/10] is directly connected, lo, 00:01:24
O>* 2.2.2.2/32 [110/10] via 192.168.1.252, ens33, 00:01:07
O>* 172.16.1.254/32 [110/10] is directly connected, lo, 00:01:24
O>* 172.16.2.254/32 [110/10] is directly connected, lo, 00:01:24
O>* 172.16.3.254/32 [110/10] is directly connected, lo, 00:01:24
O 192.168.1.0/24 [110/10] is directly connected, ens33, 00:01:24
O>* 192.168.11.254/32 [110/10] via 192.168.1.252, ens33, 00:01:07
O>* 192.168.12.254/32 [110/10] via 192.168.1.252, ens33, 00:01:07
O>* 192.168.13.254/32 [110/10] via 192.168.1.252, ens33, 00:01:07
[H3C]display ip routing-table protocol ospf
Summary count : 9
OSPF Routing table status : <Active>
Summary count : 4
Destination/Mask Proto Pre Cost NextHop Interface
1.1.1.1/32 O_INTRA 10 11 192.168.1.106 Vlan1
172.16.1.254/32 O_INTRA 10 11 192.168.1.106 Vlan1
172.16.2.254/32 O_INTRA 10 11 192.168.1.106 Vlan1
172.16.3.254/32 O_INTRA 10 11 192.168.1.106 Vlan1
OSPF Routing table status : <Inactive>
Summary count : 5
Destination/Mask Proto Pre Cost NextHop Interface
2.2.2.2/32 O_INTRA 10 0 0.0.0.0 Loop0
192.168.1.0/24 O_INTRA 10 1 0.0.0.0 Vlan1
192.168.11.254/32 O_INTRA 10 0 0.0.0.0 Loop1
192.168.12.254/32 O_INTRA 10 0 0.0.0.0 Loop2
192.168.13.254/32 O_INTRA 10 0 0.0.0.0 Loop3
[H3C]
[H3C]ping 172.16.1.254
Ping 172.16.1.254 (172.16.1.254): 56 data bytes, press CTRL_C to break
56 bytes from 172.16.1.254: icmp_seq=0 ttl=64 time=1.795 ms
56 bytes from 172.16.1.254: icmp_seq=1 ttl=64 time=1.517 ms
56 bytes from 172.16.1.254: icmp_seq=2 ttl=64 time=1.646 ms
56 bytes from 172.16.1.254: icmp_seq=3 ttl=64 time=1.579 ms
56 bytes from 172.16.1.254: icmp_seq=4 ttl=64 time=1.689 ms
--- Ping statistics for 172.16.1.254 ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/std-dev = 1.517/1.645/1.795/0.095 ms
[H3C]%Jan 1 02:58:30:507 2013 H3C PING/6/PING_STATISTICS: Ping statistics for 172.16.1.254: 5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss, round-trip min/avg/max/std-dev = 1.517/1.645/1.795/0.095 ms.
[H3C]