路由器是通信子网中的通信节点,每个路由器都计算并维护一张路由表,并据此指导数据报前往最佳路径中的下一站,这便是所谓的路由。这样,经过互联网上所有路由器的通力合作,数据报就能够沿着一条"最佳"路径到达目的地。在 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.250.* 于 2007-01-18 18:39:53发表:
Thank you!
play casino games | poker money | uk poker | free online slots | cleopatra slots | world series of poker | online bingo games | free on line slots | free money no deposit casinos | free casinos
65.110.43.* 于 2007-01-18 18:38:57发表:
Nice site!
poker usa open | no limit holdem | video poker | flash casinos | online slots free | free casino online | best poker sites | video poker download | play free slot machine games | free joker poker
65.110.43.* 于 2007-01-18 18:37:51发表:
Thank you!
free blackjack game | free online bingo | strip black jack | monopoly slot machine | free poker | free slots casino | online gambling holdem | no download no deposit casinos | multiplayer poker | internet casino
72.232.93.* 于 2007-01-17 18:22:52发表:
Great work!
three card poker | gambling online | online texas hold em | play bingo online | free casino online | paradise poker | slots on line | card game poker | no download no deposit casinos | online slot machines
65.110.43.* 于 2007-01-17 18:22:11发表:
Well done!
full poker review tilt | on line casino | live poker rooms | poker usa open | free online strip blackjack | slots online | texas holdem poker | free slim slots | play black jack | party poker download
65.110.43.* 于 2007-01-17 18:20:52发表:
Well done!
paigow poker | poker games | free blackjack game | free slot machine | world poker tour | sims free slots | holdem poker online | free online poker game | party poker bonus | casino slots
65.110.43.* 于 2007-01-17 18:20:32发表:
Well done!
blackjack odds | poker software | monopoly online | roulette wheel | flash casino games | free slots no download | play free slot machines | free roulette games | best internet poker | free cash casinos
65.110.43.* 于 2007-01-17 18:19:50发表:
Good design!
casino games free | internet casino gambling online | online poker review room | machine games | free slots casino | free online slot games | play free slots online | free slot games online | free online casinos | play blackjack free
65.110.43.* 于 2007-01-16 16:09:51发表:
Great work!
best casinos | gambling poker machine | free online texas holdem | poker rooms | online poker tournament | no limit holdem | play free slot machine games | free roulette online | free online gambling | free poker games online
65.110.43.* 于 2007-01-16 16:09:26发表:
Well done!
crazy game of poker | online poker rating room | internet poker game | blackjack download | blackjack online | poker usa | online holdem | poker us welcome | blackjack free games | free poker downloads
65.110.43.* 于 2007-01-16 16:08:53发表:
Great work!
gambling casinos | poker for us players | play bingo online | download free poker games | free poker online | bingo cards | free casino downloads | play free slot machine game | slots free | free on line games
72.232.92.* 于 2007-01-16 16:08:04发表:
Great work!
caribbean poker | play poker usa | free poker on line | free casinos | free casino money | download poker | slot machine games | play poker game | casino bonus | play money poker
65.110.43.* 于 2007-01-16 16:07:47发表:
Thank you!
poker tournament | online gambling bonuses | keno online | download party poker | free online slots games | poker hand | free online slot games | strip black jack | holdem poker | flash casinos
72.232.250.* 于 2007-01-16 16:07:30发表:
Great work!
caribbean poker | play poker usa | free poker on line | free casinos | free casino money | download poker | slot machine games | play poker game | casino bonus | play money poker
72.232.93.* 于 2007-01-15 16:58:10发表:
Nice site!
bonus poker | no limit holdem | free bingo cards | casino on line | free slot machines games | poker accepting americans | crazy game of poker | best casino bonus | poker party | poker site us
72.232.93.* 于 2007-01-15 16:57:02发表:
Nice site!
free money casino | card poker | play free blackjack online | flash casinos | no deposit casino | best poker sites | multi hand poker | casino game online | poker sites accept us | planet poker
72.232.92.* 于 2007-01-15 16:56:24发表:
Well done!
slot machines | poker card game | download casino | free on line poker | on line casinos | black jack free | download poker games | free blackjack | free slot play | video poker
65.110.43.* 于 2007-01-15 16:55:31发表:
Good design!
sim slots | black jack games | online paigow poker | free fun slots | blackjack software | hold em poker | monopoly slots | free three card poker | slot online | playing roulette
72.232.93.* 于 2007-01-15 16:54:18发表:
Good design!
free online poker game | free online blackjack | free bonus slots | free cash casinos | texas holdem poker | no deposit online casinos | free blackjack game | online poker game | free slots casino | online roulette
72.232.250.* 于 2007-01-14 15:58:32发表:
Thank you!
roulette online | roulette game | online poker us | casino bonuses | world poker tour | poker online free | casino games | blackjack games | online slots | online texas hold em
65.110.43.* 于 2007-01-14 15:56:59发表:
Nice site!
texas holdem poker | free on line poker | sim slots | poker hands | free texas holdem poker | internet gambling | free cash casinos | full poker review tilt | free slots for fun | internet casinos
65.110.43.* 于 2007-01-14 15:55:13发表:
Good design!
poker accepting americans | poker rooms accepting usa | blackjack download | online roulette | free bingo games | online gambling casino | monopoly slot machine | free play slot machines | free roulette games | poker cards
65.110.43.* 于 2007-01-14 15:54:32发表:
Nice site!
free download poker | bingo games | noble poker | poker gambling | three card poker | draw poker | online poker accept us | free games on line | poker site | online poker
72.232.250.* 于 2007-01-14 15:53:55发表:
Thank you!
poker card | casino games online | video poker machines | no deposit casinos | internet casino gambling online | multiplayer poker | free three card poker | free slot machine games online | online poker sites | free poker downloads
65.110.43.* 于 2007-01-13 15:53:07发表:
Well done!
keno | free poker games | internet casino | poker hold em | poker games | free no deposit casinos | free online casino slots | free bingo games | free three card poker | free online slot machines
72.232.93.* 于 2007-01-13 15:53:06发表:
Well done!
keno | free poker games | internet casino | poker hold em | poker games | free no deposit casinos | free online casino slots | free bingo games | free three card poker | free online slot machines
72.232.250.* 于 2007-01-13 15:51:42发表:
Good design!
casino royale | poker downloads | pacific poker | free poker game download | online gambling holdem | online hold em | play blackjack | video poker machines | free online poker games | free texas holdem poker
72.232.93.* 于 2007-01-13 15:51:04发表:
Great work!
online black jack | poker tables | free slot play | absolute poker | poker gambling | world poker | texas hold em poker | free slot games online | texas holdem online | best internet poker
72.232.250.* 于 2007-01-13 15:50:17发表:
Thank you!
play free blackjack | poker accept us | free online bingo | poker web sites | free gambling | online poker | play poker game | free games on line | best poker sites | hold em poker
65.110.43.* 于 2007-01-13 15:49:43发表:
Great work!
free casino slot games | poker software | slot game | blackjack game | no limit holdem | casino on line | no deposit bonus casinos | strip black jack | play free slot machine game | free online poker
65.110.43.* 于 2007-01-12 15:43:49发表:
Good design!
free play slots | best online casinos | sim slots | free poker tournaments | blackjack game | free poker sites | online poker reviews | poker online | free casino bonus | free blackjack
65.110.43.* 于 2007-01-12 15:42:37发表:
Well done!
play bingo online | online casino bonus | casino portal | sims slots | free online gambling | slot online | free poker game download | roulette free | free online slot games | free black jack
72.232.250.* 于 2007-01-12 15:41:44发表:
Good design!
free play slots | best online casinos | sim slots | free poker tournaments | blackjack game | free poker sites | online poker reviews | poker online | free casino bonus | free blackjack
65.110.43.* 于 2007-01-12 15:40:09发表:
Nice site!
online poker tournament | draw poker | free poker online | free online slot machine games | online slots | online poker accept us | new casinos | no download no deposit casinos | free texas hold em | online texas hold em
72.232.250.* 于 2007-01-12 15:39:51发表:
Great work!
accept us poker players | play casino game | poker site us | free bingo | play free slot machines | poker usa | poker rooms accepting usa | poker machines | poker review | free poker websites
72.232.93.* 于 2007-01-12 15:39:51发表:
Great work!
accept us poker players | play casino game | poker site us | free bingo | play free slot machines | poker usa | poker rooms accepting usa | poker machines | poker review | free poker websites
72.232.250.* 于 2007-01-12 15:38:42发表:
Good design!
playing roulette | pacific poker | video poker download | free texas holdem | online poker rooms | gambling on line | monopoly slots | free blackjack games | keno online | best casino bonus
65.110.43.* 于 2007-01-11 16:13:35发表:
Well done!
slot machine software | free blackjack game | new online casinos | black jack free | gambling game | poker accept usa | bingo cards | poker on line | pai gow poker | new no deposit online casinos
65.110.43.* 于 2007-01-11 16:12:15发表:
Thank you!
free poker | poker hands | free online blackjack | multi player poker | free online texas hold em | free online strip blackjack | no download games | casinos online | play texas holdem | free poker on line
72.232.92.* 于 2007-01-11 16:11:22发表:
Thank you!
blackjack online free | free online poker game | free omaha poker | online holdem | casino royale | free online slot machine games | free online gambling | online texas holdem | internet casino gambling | aussie slots