路由器是通信子网中的通信节点,每个路由器都计算并维护一张路由表,并据此指导数据报前往最佳路径中的下一站,这便是所谓的路由。这样,经过互联网上所有路由器的通力合作,数据报就能够沿着一条"最佳"路径到达目的地。在 GNU 软件 Zebra 的协助下,我们可以将 Linux 机器打造成一台功能完备的路由器,它能够同时支持 RIPv1、 RIPv2、RIPng、OSPFv2、OSPFv3、BGP - 4 和 BGP - 4+ 等诸多 TCP/IP 协议。现在我们首先了解一下 OSPF 和 BGP 协议的运行模式和基本原理,然后介绍 Zebra 的安装配置方法,让你的 Linux 机器变成支持 OSPF 与 BGP 的路由器。
BGP/OSPF 概述
如今,许多公司都建有多个网络,如果这些网络的类型不尽相同,则需要用路由器进行互联。路由器是与两个或两个以上的网络连接的计算机,它根据路由协议生成并维护一个路由表,并按照该路由表中的信息转发包。这些路由器对公司内部的网络结构了如指掌,知道将分组送到目的地的全部细节,但对于其他公司的网络结构并不了解。像这样"在同一机构下管理的一系列路由器和网络"被称为自治系统(AS)。由不同机构掌管的自治系统,可以采用不同的路由选择算法;但同一自治系统内的所有路由器都使用同一路由协议,以便于自治系统内部各个路由器互换路由信息来维持相互的连通性。每一个自治系统都有一个16位的"自治系统 (AS)编号"作为标志,就像 IP 地址一样,它是由专门机构来分配的。
自治系统内的路由器称为"内部网关",所用的协议称为"内部网关协议"。内部网关协议大体上分为两类,一类是距离向量协议,如 RIP,EIGRP 协议;另一类是链路状态协议如 OSPF 协议。链路状态路由协议与距离向量协议的不同之处在于,采用链路状态路由协议的路由器不是交换到达目的地的距离,而是维护一张网络拓扑结构图。然后用数据库表示该图,其中的表项对应网络的一条链路。路由器根据数据库的信息计算出"最佳路由",由此指导包的转发。当网络拓扑结构发生变化时,只需将相应纪录而非整个数据库通知其他节点。各路由器做出相应修改并重新计算路由后,就可以继续正常工作。
因为"开放式最短路径优先协议"的文档必须公开发表,所以它是"开放式的"(Open);又因为它采用"最短路径优先"(SPF)算法来计算一个节点到所有其它节点间的最短路径,故名为 OSPF。OSPF 具有支持多重度量制式和多重路径等诸多优点,因此成为因特网上推荐使用的内部网关协议,RIP 却由于自身的局限性而被打入冷宫。现在,在性能上唯一能够与 OSPF 相匹敌的内部网关协议便是 EIGRP--Cisco 的一个专有协议,但 OSPF 的"开放"本身就是一个响亮的招牌,因为谁也不想受制于某家供应商。
前面提到,自治系统内的路由器不必知道其他自治系统的内部结构细节,从而有效地节约了路由器的内存和 CPU 时间,并提高了网络带宽的利用率。但是,如果想与其他公司(自治系统)通信时该怎么办呢?很简单,我们可以在自治系统内指定一个与其他自治系统相连的路由器为"外部网关",通过它进入其他自治系统。该路由器使用的协议叫做"外部网关协议",如边界网关协议(BGP)。相邻的两个网关必须首先互换"邻机探测 "报文,协商是否愿意成为"邻机"。成为邻机则意味着两个自治系统同意中转双方的通信流。同意后,两个邻机互换"邻机可达性报文",来监督他们之间的链路的工作情况。接下来便是最重要的工作,用"网络可达性报文"来交换通过各邻机所能到达的网络的信息,从而实现自治系统之间的连通性。在外部网关的眼里只由外部网关和连接他们的链路,如此以来,自治系统内的通信由内部网关处理,自治系统之间的通信交由外部网关处理--一个分级路由的景象已经展现在我们面前,实际上,因特网正是由大量自治系统组成的。
建立一个高级路由器
许多人对路由器感到比较陌生,事实上作为一个防火墙使用的 Linux 系统已经是一个路由器了,只不过还有点"简陋"而已。然而,我们的目标是用 Linux 打造一个"高级"路由器,它必须能够利用动态路由协议(上文提到的协议皆为动态路由协议)工作。这些协议能够使路由器互换相关信息,从而共享穿越网络时所用的那些路径--路由。这一点对于大型网络(比如 Internet)而言是"异常"重要的,因为此时再用静态路由(也就是人工计算设置路由)是根本不现实的。
举例来说,即使在比较理想--即不考虑路由的变化的情况下,一个边界网关协议(BGP)路由表也至少包含 100,000 条以上的表项。这时,手工建立这样的静态路由是难以忍受的。很明显,即使我们的网络小于 Internet--比如一个大型公司网络,我们还是更加喜欢动态路由协议。
外部网关协议 BGP 通常作为 Internet 的骨干使用,而其它的协议(如 OSPF)则适于小型的互连网络。开放式最短路径优先(OSPF)协议是一个应用最广的内部网关协议(IGP)。Zebra 是一个开放源代码程序包,通过它你可以在 Linux 上运行 BGP 与 / 或 OSPF。
安装 Zebra
你既可以从 Zebra.org 网站下载 Zebra 的最新源程序,也能从 Redhat 和 Debian 中获得它,但不一定是最新版的。从源代码中进行软件安装,你就会发现使用的是一些普通的安装过程。简介如下:
./configuremakemake install配置脚本会搜索系统上已经安装的 IP 栈并且自动地设置成支持他们。当前,IP 栈很可能仅仅是指 IPv4,但是 IPv6 用户也不用担心,因为 Zebra 也会发现并且支持它。
程序安装之后,还可能必须在 /etc/services 中增加一些命令行。Zebra 的守护程序在他们自己的虚拟终端连接(VTY)下运行,所以你的系统必须知道这些虚拟终端连接。这里是你应该增加的一些连接∶
zebrasrv 2600/tcp # zebra servicezebra 2601/tcp # zebra vtyripd 2602/tcp # RIPd vtyripngd 2603/tcp # RIPngd vtyospfd 2604/tcp # OSPFd vtybgpd 2605/tcp # BGPd vtyospf6d 2606/tcp # OSPF6d vty配置 Zebra
如果你已经熟悉 Cisco IOS,那你就能在短时间内掌握 Zebra,因为你会发现两者极为相似。Zebra 的每个守护程序使用一个单独的 VTY,这些 VTY 可以通过一个远程登录会话进行动态配置。所以,如果你需要设置 OSPF,简单地远程登录到该 Linux 上 2604 端口;为了修改内核的路由表或设置路由协议间的再分发,你可以远程登录到端口 2601,该 Zebra 守护程序充当内核管理器,管理其他的守护程序和系统本身之间的通信。
现在介绍如何在一个服务器上创建和运行 OSPF 和 BGP。Zebra 的守护程序运用纯文本文件储存它们的配置。对于 OSPF/BGP 路由器,将用到三个文件∶zebra.conf、ospfd.conf 和 bgpd.conf。举例来说,zebra.conf 文件可能会是这样:
! Zebra configuration saved from vty! 2002/02/28 01:46:12!hostname LinuxRouter /*主机名为 LinuxRouter*/password zebra /*口令为 zebra*/enable password z3bRa /*进入特权模式时的口令为 z3bRa */log file /var/log/zebra/zebra.log /*日志文件的地址*/!interface eth0 /*以太接口 eth0*/ description Interface to External Network/*对接口的描述*/ ip address 10.0.0.1/24 /*该接口的 IP 地址*/!interface eth1/*以太接口 eth0*/ description Interface to Internal Network/*对接口的描述*/ ip address 192.168.66.1/24/*该接口的 IP 地址*/ 这里的感叹号充当注解标识或分隔符。尽管存在大量不同的网络接口类型(Ethernet、ISDN 等等),但只要是 Linux 内核能够辨认的网络接口类型,Zebra 都可以使用。
子网掩码都带有网络位的位数(例如/24),默认掩码则不然(比如 255.255.255.0)。注意存在两个口令,一个用于用户模式而另一个用于特权模式。这不仅有利于向非管理员提供访问权限,而且对于创建路由服务器或者路由探测镜也是非常重要的。所有 BGP 管理员都知道,这些探测镜是调试路由问题的关键,因为他们能够使你就象从一个外部 AS( AS代表自治系统)一样查看路由。 BGP 路由需要用到 AS 编号,AS 编号是一些由 ARIN (美国互联网络号码注册机构)控制的注册号码。
下一步将启动一些必要的程序。用以下命令完成∶
/usr/sbin/zebra -dk/usr/sbin/ospfd -d/usr/sbin/bgpd -d第一个命令,启动 zebra,该守护程序实际上用来更新内核的路由表。-dk 告诉该程序作为一个守护程序运行(d),它的大部分时间在后台运行。k 是另外的一个选项,告诉 Zebra 维护所有已配置的路由。它用来保证在你测试 Zebra 的时候不会意外地删除路由表。一般情况下,设置路由和接口,需要将 ifconfig 和 route 这两个命令配合使用。而 Zebra 完全可以替代这种路由管理方式,使用起来更为简洁。
设置OSPF
至此,基本的服务已经具备,现在让我们 Telnet 到本地机器的 2604 端口,开始配置 OSPF。为进入特权模式,键入 enable (正如在Cisco IOS 中一样),然后键入特权模式口令。接下来,用 configuration terminal 命令切换到配置模式。值得一提的是 Zebra 也能接受命令缩写形式,这与 Cisco 极为相似,如 configuration terminal 可以简写为 config t,这大大缩短了输入时间,使用起来更为方便。另外,如果输入 list 和 ?,它将显示一个当前可用命令的清单,并附有一些简略解释。除此之外,还可以键入 tab 用于命令的自动完成。这就是说,如果你想键入命令 clock,只要键入前两个字母 cl 然后按 tab 键,机器就会自动"补全"这条命令--前提是你键入的字符足以唯一地确定这条命令。这是一个很好的功能,尤其是当你习惯于这种用法时。
接下来,我们还需要告诉守护程序将通过 OSPF 广播哪些网络以及相关的域(area)。OSPF 的可伸缩性允许它支持多个域。键入 router ospf 开始配置 OSPF,然后键入 network 192.168.66.0/24 area 0。这告诉路由器,我们将使用 OSPF 广播一个子网掩码为 255.255.255.0 的 192.168.66.0 网络。
在本例中,我们让 eth0 接口变成一个被动(passive)接口,以便使它不能发送路由更新。这对于实验是非常重要的,因为在那个方向上的其他的路由器可能监听到发送的路由更新,将接口变成一个被动(passive)接口,从而有效的避免扰乱网络的正常运行。为此,键入命令 passive - interface eth0。如果打算将此路由器作为工作路由器使用时,就没有这个必要了。一旦你完成修改,用 end 命令从配置模式中退出,然后用 write file 命令保存。这里是一个快照:
labrat:~# telnet 0 2604 /*Telnet 到本地机器的 2604 端口*/Trying 0.0.0.0...Connected to 0.Escape character is '^]'. /*用 '^]'退出该会话*/ Hello, this is zebra (version 0.84b)Copyright 1996-2000 Kunihiro Ishiguro User Access Verification Password: /*在此键入口令,如 zebra*/ospfd> enable/*进入特权模式*/Password: /*输入特权模式口令,如 z3bRa*/ospfd# configure terminal /*从终端配置路由器*/ospfd(config)# router ospf /*配置 OSPF*/ospfd(config-router)# network 192.168.66.0/24 area 0 /*通过 OSPF 广播网络 network 192.168.66.0,/24 指出子网掩码为 24 位,area 0 指出该网络所在的域*/ospfd(config-router)# passive-interface eth0 /*将 eth0 接口设置成一个被动(passive)接口*/ospfd(config-router)# end /*退出配置模式*/ospfd# write file /*保存修改*/Configuration saved to /etc/zebra/ospfd.conf请记住,为了让 OSPF 或 BGP 在某接口上工作,那么该接口必须处于"运行"状态。为手工运行一个接口,登录到端口 2601 并且在该接口上执行 no shut 命令。
建立 BGP
BGP 与 OSPF 的配置大致相同。开始,打开一个远程登录会话到端口 2605。之后执行 configure terminal,输入 router bgp
labrat:~# telnet 0 2605Trying 0.0.0.0...Connected to 0.Escape character is '^]'. Hello, this is zebra (version 0.84b)Copyright 1996-2000 Kunihiro Ishiguro User Access Verification Password:bgpd> enablePassword:bgpd# configure terminalbgpd(config)# router bgp 65530 /*配置 BGP,65530 是自治系统编号。也就是将该系统配置成自治系统 65530 上的外部网关*/bgpd(config-router)# network 192.168.66.0/24 /*由 BGP 广播的网络*/bgpd(config-router)# neighbor 10.0.0.5 remote-as 65531 /*静态指定自治系统 65531 上 IP 地址为 10.0.0.5 的路由器为本机的邻机*/bgpd(config-router)# endbgpd# write fileConfiguration saved to /etc/zebra/bgpd.conf对于 OSPF 和 BGP,有大量选项可用,限于篇幅不能在此一一介绍。对于每个协议,我建议在实际使用之前,不妨先研究一番。为此,可以参考 GNU Zebra 文档,它会给你提供许多帮助。
结束语
在网络中,路由通信流的方法有若干种。就路由器而论,虽然有用各种硬件可用,但是费用较高--人们自然就会想到运行一个用 Linux 系统构筑的功能丰富的路由器作为代替。Zebra 路由守护程序已经使这一切变为现实。因为支持 IPv4、IPv6 和其它各式各样的协议,所以 Zebra 能够满足我们所有的路由需求。它还有一个好处就是,因为 Cisco IOS 和 Zabra 极为相似,如果你以前在 Cisco IOS 环境中工作,可以轻松的过渡到 Zebra 系统;同时,使用 Zebra 也能让你积累起丰富的类似于使用 Cisco IOS 路由器的经验和知识。


72.232.63.* 于 2007-02-12 05:53:39发表:
Well done!
poker web sites | free money casino | poker free | slot games free | 3 card poker | blackjack online | free texas hold em | casino slots | free three card poker | online video slots
66.235.162.* 于 2007-02-11 06:48:28发表:
Nice site!
no deposit casino bonus | free poker | free poker games | free casino bonus | free video poker | poker free | free slot | free bingo | free online poker games | free strip blackjack
66.235.161.* 于 2007-02-11 06:48:00发表:
Nice site!
free video | free texas hold em | internet gambling | no deposit casino | no limit texas hold em | flash casinos | free online slot machine | on line gambling | slots of fun | poker
66.36.241.* 于 2007-02-11 06:47:41发表:
Well done!
bonus poker | no download free slots | play free slots online | online blackjack free | noble poker | play bingo online | free online video slots | free fun slots | play roulette for free | play free slots
72.232.63.* 于 2007-02-11 06:47:20发表:
Great work!
texas holdem poker | texas hold em online | play texas holdem online | omaha poker | no deposit bingo | black jack games | slot machines | online holdem | download poker | online poker free
72.232.63.* 于 2007-02-11 06:46:49发表:
Great work!
free online strip blackjack | russian roulette game | free slot games no download | new casinos | casino bonus | slot machine games free | on line poker | planet poker | free online slots games | free casino money
65.110.43.* 于 2007-02-10 08:02:21发表:
Well done!
poker online free | free texas hold em | black jack strip | play money poker | free online slot machine | absolute poker | no deposit casino bonuses | video slot machines | strip blackjack games | download party poker
72.232.63.* 于 2007-02-10 08:00:52发表:
Thank you!
free games online | free 3 card poker | video poker download | free online poker games | free sim slots | free online slot machines | online free roulette | blackjack free games | free online casinos | russian roulette games
65.110.43.* 于 2007-02-10 07:59:47发表:
Well done!
texas holdem free online | free online slot games | free slots on line | casino free games | poker free download | online bingo games | bonus poker | aussie slots | free casino online | online poker free
65.110.43.* 于 2007-02-10 07:59:06发表:
Great work!
video slots free | play bingo online | casino bonuses | casino bonus | free black jack | fun slots | new online casinos | gambling online | free casino downloads | video poker
65.110.43.* 于 2007-02-10 07:58:50发表:
Good design!
no deposit bingo | no deposit bonus casinos | planet poker | monopoly online | blackjack games | free cleopatra slots | free online blackjack | online casino games | poker stars download | free online poker game
72.232.63.* 于 2007-02-09 07:00:01发表:
Well done!
casino poker | online roulette | blackjack free games | free poker download | free poker money | no deposit bingo | free no deposit casino | world series poker | slot games | online free slots
72.232.63.* 于 2007-02-09 06:59:08发表:
Thank you!
free money no deposit casinos | slim slots | free strip black jack | blackjack free | play texas hold em | download free poker game | strip blackjack game | free multi line slots | best poker sites | play roulette online
72.232.63.* 于 2007-02-09 06:58:00发表:
Thank you!
online slots free | casino slot games | free online slot machine | play free slots online | flash casino games | online casino bonus | no deposit casino | casino bonus | poker free download | no limit texas hold em
72.232.63.* 于 2007-02-09 06:56:47发表:
Good design!
strip blackjack | free three card poker | black jack strip | texas holdem poker | free online poker | on line gambling | play bingo | free monopoly slots | monopoly online | us poker sites
65.110.43.* 于 2007-02-09 06:55:45发表:
Nice site!
slot machines games | roulette free | russian roulette game | casino on net | free slot games | free casino bonus | download party poker | casino slots | casino download | free blackjack game
65.110.43.* 于 2007-02-08 07:18:37发表:
Well done!
gambling sites | free joker poker | online video slots | play free slots | caribbean poker | no deposit bonuses | play bingo | free online bingo games | computer poker | strip blackjack game
72.232.250.* 于 2007-02-08 07:17:20发表:
Good design!
virtual poker | games on line | free slot machine games online | free video poker | play blackjack | free online poker games | free slots for fun | texas hold em | free roulette online | online poker game
72.232.63.* 于 2007-02-08 07:16:13发表:
Well done!
strip black jack | online poker games | free slots games | video slots | play online poker | poker websites | free games online | casino bonus | games online | holdem poker
65.110.43.* 于 2007-02-08 07:15:57发表:
Nice site!
casino game | free online poker game | roulette free | poker for fun | free online strip blackjack | free fun slots | free bingo online | download party poker | free cleopatra slots | free poker online
65.110.43.* 于 2007-02-08 07:15:21发表:
Well done!
gambling sites | free joker poker | online video slots | play free slots | caribbean poker | no deposit bonuses | play bingo | free online bingo games | computer poker | strip blackjack game
65.110.43.* 于 2007-02-08 07:13:54发表:
Nice site!
free online slots games | slim slots free | online casino bonus | texas hold em | free poker money | texas holdem | free money casino | poker game online | free blackjack | free casino games online
72.232.250.* 于 2007-02-07 06:25:05发表:
Good design!
free online slot machine games | online slot machines | slot machine game | free slots game | star poker | download slots | no download slots | free poker | play bingo | free online slot games
72.232.63.* 于 2007-02-07 06:24:47发表:
Nice site!
free online casino | roulette download | sims slots | no deposit online casino | online slots | online bingo | online blackjack free | casino game | poker free | slot games free
65.110.43.* 于 2007-02-07 06:24:40发表:
Great work!
online casinos | black jack online | gambling games | on line gambling | poker free download | free poker game | free slot downloads | texas holdem free | play blackjack | online blackjack
72.232.63.* 于 2007-02-07 06:23:18发表:
Good design!
free bingo online | free slot machine games online | play texas holdem free | video slots | free poker game download | free texas hold em | empire poker | internet poker | blackjack online | free online slots
65.110.43.* 于 2007-02-07 06:22:38发表:
Thank you!
play blackjack free | free black jack | online poker | roulette game | play roulette online | free online slots no downloads | free poker downloads | virtual poker | keno online | texas poker
72.232.63.* 于 2007-02-06 05:22:56发表:
Great work!
free polyphonic ringtones | downloads free nextel ringtone | 50 cent ringtones | free nokia ringtones | sprint sanyo free ringtones | free motorola polyphonic ringtones | download free nextel ringtones | i730 free nextel ringtones | free bollywood ringtones | mp3 to ringtone converter
65.110.43.* 于 2007-02-06 05:22:01发表:
Great work!
ringtone jukebox ringtone jukebox | free tracfone ringtones | motorola razr v3 ringtones | ctu ringtone | download free mp3 ringtones | keypress ringtones for samsung | free ringtone for motorola | free mobile polyphonic ringtones | download mp3 music ringtone | motorola cell phone ringtones
72.232.250.* 于 2007-02-06 05:21:26发表:
Nice site!
free polyphonic motorola ringtones | music ringtones | free nextel i730 ringtones | free tmobile ringtones | 24 ringtones | free ringtones alltel | cellular one ringtones | free nokia poly ringtone | bollywood ringtones | blackberry ringtones
65.110.43.* 于 2007-02-06 05:21:20发表:
Great work!
mp3 ringtones | cingular wireless ringtones | free samsung t100 ringtones | ringtones sprint pcs sanyo | i730 nextel ringtone | voice ringtones | free country ringtones | free siemens ringtones | free ringtone creator | free sprint sanyo ringtones
65.110.43.* 于 2007-02-06 05:20:35发表:
Well done!
cingular phone free ringtones | funny ringtone mp3 | us cellular ringtones | free i730 nextel ringtones | free lg ringtones | free ringtones verizon | downloads free mp3 ringtone | ringtone downloads | ctu ringtones | ctu ringtone ctu ringtone
72.232.250.* 于 2007-02-05 06:24:04发表:
Nice site!
flash casinos | free online slot machine | poker free | free video poker | online blackjack | strip blackjack games | new free money online casinos | free slot game | free slot machines | play texas hold em
72.232.250.* 于 2007-02-05 06:23:28发表:
Great work!
slot machine game | free online bingo | free casino games online | poker for fun | free slots no downloads | play black jack | poker stars | free poker software | play casino games | play slots for free
65.110.43.* 于 2007-02-05 06:23:17发表:
Nice site!
gambling sites | texas hold em | casino slot games | cleopatra slot | download casino games | free bonus slots | free poker game download | free poker downloads | online free roulette | blackjack download
72.232.63.* 于 2007-02-05 06:22:22发表:
Nice site!
sims slots | poker free download | free online casino | no deposit casino | poker for free | poker game download | free monopoly online | roulette game | play poker | blackjack games
72.232.250.* 于 2007-02-05 06:21:52发表:
Nice site!
poker usa | slots download | free play slots | free casino online | free blackjack | aussie slots | slots games | internet poker | party poker download | no limit texas hold em
72.232.250.* 于 2007-02-04 08:44:20发表:
Good design!
free online slot machine | free no deposit casino | free download poker | free roulette | free poker game | games slots | joker poker | video slots | free slots on line | no limit texas hold em
65.110.43.* 于 2007-02-04 08:43:57发表:
Thank you!
online texas hold em | blackjack free | play roulette for free | online casino bonus | monopoly online | blackjack online | slots games | party poker | free online texas hold em | omaha poker
65.110.43.* 于 2007-02-04 08:43:36发表:
Great work!
casino game | free casino slot games | free video slots | internet poker | poker usa | internet bingo | strip blackjack games | free slot games online | online poker game | poker downloads