Cisco基于策略路由的配置實例
更新時間:2007年09月19日 10:21:55 作者:
問題描述
您可以定義自己的規(guī)則來進行數(shù)據(jù)包的路由而不僅僅由目的地地址所決定。在這里
您可以學(xué)到怎么使用基于策略路由的辦法來解決這一問題。
在具體的應(yīng)用中,基于策略的路由有:
☆ 基于源IP地址的策略路由
☆ 基于數(shù)據(jù)包大小的策略路由
☆ 基于應(yīng)用的策略路由
☆ 通過缺省路由平衡負載
這里,講述了第一種情況的路由策略。
舉例
在這個例子中,防火墻的作用是:把10.0.0.0/8內(nèi)部網(wǎng)地址翻譯成可路由的172.16
.255.0/24子網(wǎng)地址。
下面的防火墻配置是為了完整性而加進去的,它不是策略路由配置所必需的。在這
里的防火墻可以被其它類似的產(chǎn)品代替,如PIX或其它類似防火墻設(shè)備。這里的防火墻的
配置如下:
!
ip nat pool net-10 172.16.255.1 172.16.255.254 prefix-length 24
ip nat inside source list 1 pool net-10
!
interface Ethernet0
ip address 172.16.20.2 255.255.255.0
ip nat outside
!
interface Ethernet1
ip address 172.16.39.2 255.255.255.0
ip nat inside
!
router eigrp 1
redistribute static
network 172.16.0.0
default-metric 10000 100 255 1 1500
!
ip route 172.16.255.0 255.255.255.0 Null0
access-list 1 permit 10.0.0.0 0.255.255.255
!
end
在我們的例子中,Cisco WAN路由器上運行策略路由來保證從10.0.0.0/8網(wǎng)絡(luò)來的I
P數(shù)據(jù)包被發(fā)送到防火墻去。配置中定義了兩條net-10策略規(guī)則。第一條策略就定義了從
10.0.0.0/8網(wǎng)絡(luò)來的IP數(shù)據(jù)包被發(fā)送到防火墻去(我們很快會看到這里的配置有問題)
。而第二條規(guī)則允許所有的其它數(shù)據(jù)包能按正常路由。這里的Cisco WAN路由器的配置如
下:
!
interface Ethernet0/0
ip address 172.16.187.3 255.255.255.0
no ip directed-broadcast
!
interface Ethernet0/1
ip address 172.16.39.3 255.255.255.0
no ip directed-broadcast
!
interface Ethernet3/0
ip address 172.16.79.3 255.255.255.0
no ip directed-broadcast
ip policy route-map net-10
!
router eigrp 1
network 172.16.0.0
!
access-list 110 permit ip 10.0.0.0 0.255.255.255 172.16.36.0 0.0.0.255
access-list 111 permit ip 10.0.0.0 0.255.255.255 any
!
route-map net-10 permit 10
match ip address 111
set interface Ethernet0/1
!
route-map net-10 permit 20
!
end
我們可以這樣測試我們所做的配置。在名為Cisco-1的路由器10.1.1.1上發(fā)送ping命
令到Internet上的一個主機(這里就是192.1.1.1主機)。要查看名為Internet Router
的路由器上的情況,我們在特權(quán)命令模式下執(zhí)行debug ip packet 101 detail命令。(
其中,在此路由器上有access-list 101 permit icmp any any配置命令)。下面是輸出
結(jié)果:
Results of ping from Cisco-1 to 192.1.1.1/internet taken from Internet_R
outer:
Pakcet never makes it to Internet_Router
正如您所看到的:數(shù)據(jù)包沒有到達Internet_Router路由器。下面的在Cisco WAN路
由器上的debug命令給出了原因:
Debug commands run from Cisco_WAN_Router:
"debug ip policy"
2d15h: IP: s=10.1.1.1 (Ethernet3/0), d=192.1.1.1, len 100, policy match
2d15h: IP: route map net-10, item 10, permit
2d15h: IP: s=10.1.1.1 (Ethernet3/0), d=192.1.1.1 (Ethernet0/1), len 100,
policy routed
2d15h: IP: Ethernet3/0 to Ethernet0/1 192.1.1.1
這里,數(shù)據(jù)包確實匹配了net-10策略圖中的第一條規(guī)則。但為什么還是沒有達到預(yù)
期的目的呢?用"debug arp"來看一下。
"debug arp"
2d15h: IP ARP: sent req src 172.16.39.3 0010.7bcf.5b02,
dst 192.1.1.1 0000.0000.0000 Ethernet0/1
2d15h: IP ARP rep filtered src 192.1.1.1 00e0.b064.243d, dst 172.16.39.3
0010.7bcf.5b02
wrong cable, interface Ethernet0/1
debug arp的輸出給出了原因。路由器努力完成它被指示要做的動作,而且試圖把數(shù)
據(jù)包發(fā)向Ethernet0/1接口,但失敗了。這要求路由器為目的地址192.1.1.1執(zhí)行地址解
析協(xié)議操作,當執(zhí)行該任務(wù)時,路由器知道了目的地址不處于該接口。接下來,路由器
發(fā)生封裝錯誤。所以,最后數(shù)據(jù)包不能到達192.1.1.1。
我們怎樣避免這個問題呢?修改路由圖使防火墻地址為下一跳。
Config changed on Cisco_WAN_Router:
!
route-map net-10 permit 10
match ip address 111
set ip next-hop 172.16.39.2
!
修改后,在Internet Router上運行同樣的命令:debug ip packet 101 detail。這時,
數(shù)據(jù)包可以按配置前進。我們也能看到數(shù)據(jù)包被防火墻翻譯成了172.16.255.1。192.1.
1.1主機的回應(yīng):
Results of ping from Cisco_1 to 192.1.1.1/internet taken from Internet_R
outer:
2d15h: IP: s=172.16.255.1 (Ethernet1), d=192.1.1.1 (Serial0), g=192.1.1.
1, len 100, forward
2d15h: ICMP type=8, code=0
2d15h:
2d15h: IP: s=192.1.1.1 (Serial0), d=172.16.255.1 (Ethernet1), g=172.16.2
0.2, len 100, forward
2d15h: ICMP type=0, code=0
2d15h:
在Cisco WAN路由器上執(zhí)行debug ip policy命令后,我們可以看到數(shù)據(jù)包被傳遞到
了防火墻,172.16.39.2:
Debug commands run from Cisco_WAN_Router:
"debug ip policy"
2d15h: IP: s=10.1.1.1 (Ethernet3/0), d=192.1.1.1, len 100, policy match
2d15h: IP: route map net-10, item 20, permit
2d15h: IP: s=10.1.1.1 (Ethernet3/0), d=192.1.1.1 (Ethernet0/1), len 100,
policy routed
2d15h: IP: Ethernet3/0 to Ethernet0/1 172.16.39.2
文章錄入:csh 責任編輯:csh
您可以定義自己的規(guī)則來進行數(shù)據(jù)包的路由而不僅僅由目的地地址所決定。在這里
您可以學(xué)到怎么使用基于策略路由的辦法來解決這一問題。
在具體的應(yīng)用中,基于策略的路由有:
☆ 基于源IP地址的策略路由
☆ 基于數(shù)據(jù)包大小的策略路由
☆ 基于應(yīng)用的策略路由
☆ 通過缺省路由平衡負載
這里,講述了第一種情況的路由策略。
舉例
在這個例子中,防火墻的作用是:把10.0.0.0/8內(nèi)部網(wǎng)地址翻譯成可路由的172.16
.255.0/24子網(wǎng)地址。
下面的防火墻配置是為了完整性而加進去的,它不是策略路由配置所必需的。在這
里的防火墻可以被其它類似的產(chǎn)品代替,如PIX或其它類似防火墻設(shè)備。這里的防火墻的
配置如下:
!
ip nat pool net-10 172.16.255.1 172.16.255.254 prefix-length 24
ip nat inside source list 1 pool net-10
!
interface Ethernet0
ip address 172.16.20.2 255.255.255.0
ip nat outside
!
interface Ethernet1
ip address 172.16.39.2 255.255.255.0
ip nat inside
!
router eigrp 1
redistribute static
network 172.16.0.0
default-metric 10000 100 255 1 1500
!
ip route 172.16.255.0 255.255.255.0 Null0
access-list 1 permit 10.0.0.0 0.255.255.255
!
end
在我們的例子中,Cisco WAN路由器上運行策略路由來保證從10.0.0.0/8網(wǎng)絡(luò)來的I
P數(shù)據(jù)包被發(fā)送到防火墻去。配置中定義了兩條net-10策略規(guī)則。第一條策略就定義了從
10.0.0.0/8網(wǎng)絡(luò)來的IP數(shù)據(jù)包被發(fā)送到防火墻去(我們很快會看到這里的配置有問題)
。而第二條規(guī)則允許所有的其它數(shù)據(jù)包能按正常路由。這里的Cisco WAN路由器的配置如
下:
!
interface Ethernet0/0
ip address 172.16.187.3 255.255.255.0
no ip directed-broadcast
!
interface Ethernet0/1
ip address 172.16.39.3 255.255.255.0
no ip directed-broadcast
!
interface Ethernet3/0
ip address 172.16.79.3 255.255.255.0
no ip directed-broadcast
ip policy route-map net-10
!
router eigrp 1
network 172.16.0.0
!
access-list 110 permit ip 10.0.0.0 0.255.255.255 172.16.36.0 0.0.0.255
access-list 111 permit ip 10.0.0.0 0.255.255.255 any
!
route-map net-10 permit 10
match ip address 111
set interface Ethernet0/1
!
route-map net-10 permit 20
!
end
我們可以這樣測試我們所做的配置。在名為Cisco-1的路由器10.1.1.1上發(fā)送ping命
令到Internet上的一個主機(這里就是192.1.1.1主機)。要查看名為Internet Router
的路由器上的情況,我們在特權(quán)命令模式下執(zhí)行debug ip packet 101 detail命令。(
其中,在此路由器上有access-list 101 permit icmp any any配置命令)。下面是輸出
結(jié)果:
Results of ping from Cisco-1 to 192.1.1.1/internet taken from Internet_R
outer:
Pakcet never makes it to Internet_Router
正如您所看到的:數(shù)據(jù)包沒有到達Internet_Router路由器。下面的在Cisco WAN路
由器上的debug命令給出了原因:
Debug commands run from Cisco_WAN_Router:
"debug ip policy"
2d15h: IP: s=10.1.1.1 (Ethernet3/0), d=192.1.1.1, len 100, policy match
2d15h: IP: route map net-10, item 10, permit
2d15h: IP: s=10.1.1.1 (Ethernet3/0), d=192.1.1.1 (Ethernet0/1), len 100,
policy routed
2d15h: IP: Ethernet3/0 to Ethernet0/1 192.1.1.1
這里,數(shù)據(jù)包確實匹配了net-10策略圖中的第一條規(guī)則。但為什么還是沒有達到預(yù)
期的目的呢?用"debug arp"來看一下。
"debug arp"
2d15h: IP ARP: sent req src 172.16.39.3 0010.7bcf.5b02,
dst 192.1.1.1 0000.0000.0000 Ethernet0/1
2d15h: IP ARP rep filtered src 192.1.1.1 00e0.b064.243d, dst 172.16.39.3
0010.7bcf.5b02
wrong cable, interface Ethernet0/1
debug arp的輸出給出了原因。路由器努力完成它被指示要做的動作,而且試圖把數(shù)
據(jù)包發(fā)向Ethernet0/1接口,但失敗了。這要求路由器為目的地址192.1.1.1執(zhí)行地址解
析協(xié)議操作,當執(zhí)行該任務(wù)時,路由器知道了目的地址不處于該接口。接下來,路由器
發(fā)生封裝錯誤。所以,最后數(shù)據(jù)包不能到達192.1.1.1。
我們怎樣避免這個問題呢?修改路由圖使防火墻地址為下一跳。
Config changed on Cisco_WAN_Router:
!
route-map net-10 permit 10
match ip address 111
set ip next-hop 172.16.39.2
!
修改后,在Internet Router上運行同樣的命令:debug ip packet 101 detail。這時,
數(shù)據(jù)包可以按配置前進。我們也能看到數(shù)據(jù)包被防火墻翻譯成了172.16.255.1。192.1.
1.1主機的回應(yīng):
Results of ping from Cisco_1 to 192.1.1.1/internet taken from Internet_R
outer:
2d15h: IP: s=172.16.255.1 (Ethernet1), d=192.1.1.1 (Serial0), g=192.1.1.
1, len 100, forward
2d15h: ICMP type=8, code=0
2d15h:
2d15h: IP: s=192.1.1.1 (Serial0), d=172.16.255.1 (Ethernet1), g=172.16.2
0.2, len 100, forward
2d15h: ICMP type=0, code=0
2d15h:
在Cisco WAN路由器上執(zhí)行debug ip policy命令后,我們可以看到數(shù)據(jù)包被傳遞到
了防火墻,172.16.39.2:
Debug commands run from Cisco_WAN_Router:
"debug ip policy"
2d15h: IP: s=10.1.1.1 (Ethernet3/0), d=192.1.1.1, len 100, policy match
2d15h: IP: route map net-10, item 20, permit
2d15h: IP: s=10.1.1.1 (Ethernet3/0), d=192.1.1.1 (Ethernet0/1), len 100,
policy routed
2d15h: IP: Ethernet3/0 to Ethernet0/1 172.16.39.2
文章錄入:csh 責任編輯:csh
相關(guān)文章
華為公司三層以太網(wǎng)交換機基本原理及轉(zhuǎn)發(fā)流程
華為公司三層以太網(wǎng)交換機基本原理及轉(zhuǎn)發(fā)流程...2007-09-09