做者:stanley.wy & allens
實驗TOPO:
![200703271174990923093.jpg](http://static.javashuo.com/static/loading.gif)
實驗要求:使用ACL,route-map配合重發布,R1僅可以學習到奇數位的網絡號或是偶數位的網絡號,即192.168.x.0的x爲奇或爲偶.
實驗步驟一:配置各路由器的IP,而且確認直接接口能夠PING通.
實驗步驟二:配置RIP和OSPF的協議,同時network正確的網絡接口,而且注意passive-interface的使用
實驗步驟三:在R2上配置重發布,確認網絡是能夠經過重發布學習到全部的網絡.
題目要求分析:
R1僅可以學習到R3的奇數位的網絡號或是偶數號的網絡號.將各個子網拆成二進制觀察規律
192.168.1.0/24 |
192.168.0000 0001.0/24 |
192.168.2.0/24 |
192.168.0000 0010.0/24 |
192.168.3.0/24 |
192.168.0000 0011.0/24 |
192.168.4.0/24 |
192.168.0000 0100.0/24 |
192.168.5.0/24 |
192.168.0000 0101.0/24 |
192.168.6.0/24 |
192.168.0000 0110.0/24 |
192.168.7.0/24 |
192.168.0000 0111.0/24 |
192.168.8.0/24 |
192.168.0000 1000.0/24 |
能夠發現,只要是192.168.x.0/24的x爲
偶數,則第24位爲0,若是爲奇,則第24位爲1,所以根據此規律和ACL的0爲徹底匹配1爲忽略匹配規則,能夠寫出以下兩個acl,針對第24位進行匹配.
用於偶數位的網絡號:access-list 1 permit 192.168.0.0 0.0.254.0
192.168.
0000 000
0.0
000.000.
1111 111
0.0
用於奇數位的網絡號:access-list 2 permit 192.168.1.0 0.0.254.0
192.168.
0000 000
1.0
000.000.
1111 111
0.0
實驗實踐一:在R2上配置,測試偶數位的匹配:
access-list 1 permit 192.168.0.0 0.0.254.0
!
route-map parity-acl permit 10
match ip address 1
!
router ospf 1
redistribute rip subnets route-map parity-acl
在R1上查看路由表,發現只有偶數位的網絡號:
O E2 192.168.8.0/24 [110/20] via 172.16.1.2, 00:00:38, Serial1/1
O E2 192.168.4.0/24 [110/20] via 172.16.1.2, 00:00:38, Serial1/1
O E2 192.168.6.0/24 [110/20] via 172.16.1.2, 00:00:38, Serial1/1
O E2 192.168.2.0/24 [110/20] via 172.16.1.2, 00:00:38, Serial1/1
實驗實踐二:no掉剛纔配置的acl和route-map,在R2上配置,測試奇數位的匹配
access-list 2 permit 192.168.1.0 0.0.254.0
!
route-map parity-acl permit 10
match ip address 2
!
router ospf 1
redistribute rip subnets route-map parity-acl
在R1上查看路由表,發現只有奇數位的網絡號:
O E2 192.168.5.0/24 [110/20] via 172.16.1.2, 00:00:27, Serial1/1
O E2 192.168.7.0/24 [110/20] via 172.16.1.2, 00:00:27, Serial1/1
O E2 192.168.1.0/24 [110/20] via 172.16.1.2, 00:00:27, Serial1/1
O E2 192.168.3.0/24 [110/20] via 172.16.1.2, 00:00:27, Serial1/1
例 : access-list 10 permit 10.1.1.0 ##看清,沒有wildcard,且最後一個是0.
意義: 僅匹配10.1.1.0這一條路由條目.