IP路由原理
一.什么是路由
路由是指導IP報文發送的路徑信息。
二.路由表的構成
路由表是路由器轉發報文的判斷依據
三.路由器單跳操作
四.路由表查找規則
1.選擇度量值小的進行轉發
2.永遠將下一跳地址指向直連路由
3.如果路由表中沒有相匹配的主機路由去匹配就會丟棄,但是如果存在默認路由的話,會默認從默認路由轉發。
五.路由的來源
1.直連路由
開銷小,配置簡單,無需人工維護。只能發現本接口所屬網段的路由
2.手工配置的靜態路由
無開銷,配置簡單,需人工維護,適合簡單拓撲結構的網絡
3.路由協議發現的動態路由
開銷大,配置復雜,無需人工維護,適合復雜拓撲結構的網絡
六.路由度量值(Metric)
1.路由度量值表示到達折條路由所指目的地址的代價。
2.通常影響路由度量值的因素:
線路演示,帶寬,線路使用率,線路可信度,跳數,最大傳輸單元
3.不同路由協議參考的因素不同
七.路由優先級
如果到相同目的地址有多個路由來源,則:
a>.以Preference(優先級)確定不同類型優先級;
b>.Preference越小,優先級越高;
c>.優先級最高的路由被添加進路由表
八.各類路由默認優先級
九.路由環路
環路產生的原因:配置錯誤或協議缺陷
十.實驗:
1.單臂路由的配置不同VLAN互通。
以上是一個簡單“單臂路由”拓撲圖:
a.實現思路:1>.在22層交換機上划分不同的vlan,並將相應的端口加入不同的 VLAN中;
2>.在路由器上配置子接口IP位各個部門員工的網關IP;
3>.不同的VLAN只要經過三層設備就能成功的訪問到其他不同的VLAN了;
b.配置過程如下:
注意:為了操作方便我將“22層核心交換機”更名為core,將“網關出口”更名為gw
22層核心交換機配置如下:
1 22層核心交換機配置 2 [Huawei]sysname core 3 [core]interface GigabitEthernet 0/0/1 4 [core-GigabitEthernet0/0/1]port link-type access #將改口配置為access口 5 [core-GigabitEthernet0/0/1]quit 6 [core]interface GigabitEthernet 0/0/2 7 [core-GigabitEthernet0/0/2]port link-type access 8 [core-GigabitEthernet0/0/2]quit 9 [core]interface GigabitEthernet 0/0/3 10 [core-GigabitEthernet0/0/3]port link-type access 11 [core-GigabitEthernet0/0/3]quit 12 [core]interface GigabitEthernet 0/0/4 13 [core-GigabitEthernet0/0/4]port link-type access 14 [core-GigabitEthernet0/0/4]quit 15 [core]interface GigabitEthernet 0/0/5 16 [core-GigabitEthernet0/0/5]port link-type access 17 [core-GigabitEthernet0/0/5]quit 18 [core]interface GigabitEthernet 0/0/10 19 [core-GigabitEthernet0/0/10]port link-type trunk #將改口配置為trunk口 20 [core-GigabitEthernet0/0/10]port trunk allow-pass vlan all 21 [core-GigabitEthernet0/0/10]undo shutdown 22 [core-GigabitEthernet0/0/10]quit 23 [core]vlan 10 24 [core-vlan10]port GigabitEthernet 0/0/1 #將端口加入該VLAN10中 25 [core-vlan10]vlan 20 26 [core-vlan20]port GigabitEthernet 0/0/2 27 [core-vlan20]vlan 30 28 [core-vlan30]port GigabitEthernet 0/0/3 29 [core-vlan30]vlan 40 30 [core-vlan40]port GigabitEthernet 0/0/4 31 [core-vlan40]vlan 50 32 [core-vlan50]port GigabitEthernet 0/0/5 33 [core-vlan50]quit 34 [core]dis vlan 10 to 50 #查看10到50所有連續的VLAN信息 35 -------------------------------------------------------------------------------- 36 U: Up; D: Down; TG: Tagged; UT: Untagged; 37 MP: Vlan-mapping; ST: Vlan-stacking; 38 #: ProtocolTransparent-vlan; *: Management-vlan; 39 -------------------------------------------------------------------------------- 40 41 VID Type Ports 42 -------------------------------------------------------------------------------- 43 10 common UT:GE0/0/1(U) 44 20 common UT:GE0/0/2(U) 45 30 common UT:GE0/0/3(U) 46 40 common UT:GE0/0/4(U) 47 50 common UT:GE0/0/5(U) 48 49 VID Status Property MAC-LRN Statistics Description 50 -------------------------------------------------------------------------------- 51 10 enable default enable disable VLAN 0010 52 20 enable default enable disable VLAN 0020 53 30 enable default enable disable VLAN 0030 54 40 enable default enable disable VLAN 0040 55 50 enable default enable disable VLAN 0050 56 [core]
網關出口配置過程如下:
1 出口網關配置 2 [Huawei]sysname gw 3 [gw]interface Ethernet 0/0/0 4 [gw-Ethernet0/0/0]undo shutdown #將物理接口配置成不關閉狀態 5 [gw-Ethernet0/0/0]quit 6 [gw]interface Ethernet 0/0/0.1 7 [gw-Ethernet0/0/0.1]vlan-type dot1q 10 #將該子接口172封裝成trunk,允許VLAN透傳。 8 [gw-Ethernet0/0/0.1]ip address 172.30.1.254 255.255.255.0 #給該虛接口配置一個地址,也是 9 10 172.30.1.0/24的網管地址 11 [gw-Ethernet0/0/0.1]undo shutdow #該接口不啟狀態 12 [gw-Ethernet0/0/0.1]quit 13 [gw]interface Ethernet 0/0/0.2 14 [gw-Ethernet0/0/0.2]vlan-type dot1q 20 15 [gw-Ethernet0/0/0.2]ip address 172.30.2.254 16 [gw-Ethernet0/0/0.2]undo shutdown 17 [gw-Ethernet0/0/0.2]quit 18 [gw]interface Ethernet 0/0/0.3 19 [gw-Ethernet0/0/0.3]vlan-type dot1q 30 20 [gw-Ethernet0/0/0.3]ip address 172.30.3.254 24 21 [gw-Ethernet0/0/0.3]undo shutdown 22 [gw-Ethernet0/0/0.3]quit 23 [gw]interface Ethernet 0/0/0.4 24 [gw-Ethernet0/0/0.4]vlan-type dot1q 40 25 [gw-Ethernet0/0/0.4]ip address 172.30.4.254 24 26 [gw-Ethernet0/0/0.4]undo shutdown 27 [gw-Ethernet0/0/0.4]quit 28 [gw]interface Ethernet 0/0/0.5 29 [gw-Ethernet0/0/0.5]vlan-type dot1q 50 30 [gw-Ethernet0/0/0.5]ip address 172.30.5.254 24 31 [gw-Ethernet0/0/0.5]undo shutdown 32 [gw-Ethernet0/0/0.5]quit 33 [gw]
運維部門電腦測試結果如下:
1 PC> 2 PC>ipconfig 3 4 Link local IPv6 address...........: fe80::5689:98ff:fea7:2066 5 IPv6 address......................: :: / 128 6 IPv6 gateway......................: :: 7 IPv4 address......................: 172.30.3.1 8 Subnet mask.......................: 255.255.255.0 9 Gateway...........................: 172.30.3.254 10 Physical address..................: 54-89-98-A7-20-66 11 DNS server........................: 12 13 PC>ping 172.30.1.1 14 15 Ping 172.30.1.1: 32 data bytes, Press Ctrl_C to break 16 From 172.30.1.1: bytes=32 seq=1 ttl=127 time=78 ms 17 From 172.30.1.1: bytes=32 seq=2 ttl=127 time=47 ms 18 From 172.30.1.1: bytes=32 seq=3 ttl=127 time=62 ms 19 From 172.30.1.1: bytes=32 seq=4 ttl=127 time=62 ms 20 From 172.30.1.1: bytes=32 seq=5 ttl=127 time=62 ms 21 22 --- 172.30.1.1 ping statistics --- 23 5 packet(s) transmitted 24 5 packet(s) received 25 0.00% packet loss 26 round-trip min/avg/max = 47/62/78 ms 27 28 PC>ping 172.30.2.1 29 30 Ping 172.30.2.1: 32 data bytes, Press Ctrl_C to break 31 From 172.30.2.1: bytes=32 seq=1 ttl=127 time=47 ms 32 From 172.30.2.1: bytes=32 seq=2 ttl=127 time=62 ms 33 From 172.30.2.1: bytes=32 seq=3 ttl=127 time=47 ms 34 From 172.30.2.1: bytes=32 seq=4 ttl=127 time=62 ms 35 From 172.30.2.1: bytes=32 seq=5 ttl=127 time=47 ms 36 37 --- 172.30.2.1 ping statistics --- 38 5 packet(s) transmitted 39 5 packet(s) received 40 0.00% packet loss 41 round-trip min/avg/max = 47/53/62 ms 42 43 PC>ping 172.30.3.1 44 45 Ping 172.30.3.1: 32 data bytes, Press Ctrl_C to break 46 From 172.30.3.1: bytes=32 seq=1 ttl=128 time<1 ms 47 From 172.30.3.1: bytes=32 seq=2 ttl=128 time<1 ms 48 From 172.30.3.1: bytes=32 seq=3 ttl=128 time<1 ms 49 From 172.30.3.1: bytes=32 seq=4 ttl=128 time<1 ms 50 From 172.30.3.1: bytes=32 seq=5 ttl=128 time<1 ms 51 52 --- 172.30.3.1 ping statistics --- 53 5 packet(s) transmitted 54 5 packet(s) received 55 0.00% packet loss 56 round-trip min/avg/max = 0/0/0 ms 57 58 PC>ping 172.30.4.1 59 60 Ping 172.30.4.1: 32 data bytes, Press Ctrl_C to break 61 From 172.30.4.1: bytes=32 seq=1 ttl=127 time=63 ms 62 From 172.30.4.1: bytes=32 seq=2 ttl=127 time=46 ms 63 From 172.30.4.1: bytes=32 seq=3 ttl=127 time=63 ms 64 From 172.30.4.1: bytes=32 seq=4 ttl=127 time=62 ms 65 From 172.30.4.1: bytes=32 seq=5 ttl=127 time=47 ms 66 67 --- 172.30.4.1 ping statistics --- 68 5 packet(s) transmitted 69 5 packet(s) received 70 0.00% packet loss 71 round-trip min/avg/max = 46/56/63 ms 72 73 PC>ping 172.30.5.1 74 75 Ping 172.30.5.1: 32 data bytes, Press Ctrl_C to break 76 From 172.30.5.1: bytes=32 seq=1 ttl=127 time=63 ms 77 From 172.30.5.1: bytes=32 seq=2 ttl=127 time=62 ms 78 From 172.30.5.1: bytes=32 seq=3 ttl=127 time=47 ms 79 From 172.30.5.1: bytes=32 seq=4 ttl=127 time=62 ms 80 From 172.30.5.1: bytes=32 seq=5 ttl=127 time=93 ms 81 82 --- 172.30.5.1 ping statistics --- 83 5 packet(s) transmitted 84 5 packet(s) received 85 0.00% packet loss 86 round-trip min/avg/max = 47/65/93 ms 87 88 PC>
c.總結單臂路由的優缺點:
優點:
1>實現了不同VLAN的互通。
2>.只需要一個物理接口能給多個VLAN配置網關,通過子接口的技術,子接口必須封裝802.1Q的trunk協議。
缺點:
1>.不同VLAN的數據每次訪問都要通過路由器進行路由查找,效率比較低;
2>.購買一個路由器設備比購買一個三層交換機要貴的多,性價比低!
2.三層交換配置不同VLAN互通。
a.三層交換機以內置的三層路由轉發引擎執行VLAN間路由功能
b.配置過程如下:
三層核心交換機配置如下:
1 [Huawei]sysname core 2 [core]interface GigabitEthernet 0/0/1 3 [core-GigabitEthernet0/0/1]port link-type access #將改口配置為access口 4 [core-GigabitEthernet0/0/1]quit 5 [core]interface GigabitEthernet 0/0/2 6 [core-GigabitEthernet0/0/2]port link-type access 7 [core-GigabitEthernet0/0/2]quit 8 [core]interface GigabitEthernet 0/0/3 9 [core-GigabitEthernet0/0/3]port link-type access 10 [core-GigabitEthernet0/0/3]quit 11 [core]interface GigabitEthernet 0/0/4 12 [core-GigabitEthernet0/0/4]port link-type access 13 [core-GigabitEthernet0/0/4]quit 14 [core]interface GigabitEthernet 0/0/5 15 [core-GigabitEthernet0/0/5]port link-type access 16 [core-GigabitEthernet0/0/5]quit 17 [core]interface GigabitEthernet 0/0/10 18 [core-GigabitEthernet0/0/10]port link-type trunk #將改口配置為trunk口 19 [core-GigabitEthernet0/0/10]port trunk allow-pass vlan all 20 [core-GigabitEthernet0/0/10]undo shutdown 21 [core-GigabitEthernet0/0/10]quit 22 [core]vlan 10 23 [core-vlan10]port GigabitEthernet 0/0/1 #將端口加入該VLAN10中 24 [core-vlan10]vlan 20 25 [core-vlan20]port GigabitEthernet 0/0/2 26 [core-vlan20]vlan 30 27 [core-vlan30]port GigabitEthernet 0/0/3 28 [core-vlan30]vlan 40 29 [core-vlan40]port GigabitEthernet 0/0/4 30 [core-vlan40]vlan 50 31 [core-vlan50]port GigabitEthernet 0/0/5 32 [core-vlan50]quit 33 [core]dis vlan 10 to 50 #查看10到50所有連續的VLAN信息 34 -------------------------------------------------------------------------------- 35 U: Up; D: Down; TG: Tagged; UT: Untagged; 36 MP: Vlan-mapping; ST: Vlan-stacking; 37 #: ProtocolTransparent-vlan; *: Management-vlan; 38 -------------------------------------------------------------------------------- 39 40 VID Type Ports 41 -------------------------------------------------------------------------------- 42 10 common UT:GE0/0/1(U) 43 20 common UT:GE0/0/2(U) 44 30 common UT:GE0/0/3(U) 45 40 common UT:GE0/0/4(U) 46 50 common UT:GE0/0/5(U) 47 48 VID Status Property MAC-LRN Statistics Description 49 -------------------------------------------------------------------------------- 50 10 enable default enable disable VLAN 0010 51 20 enable default enable disable VLAN 0020 52 30 enable default enable disable VLAN 0030 53 40 enable default enable disable VLAN 0040 54 50 enable default enable disable VLAN 0050 55 [core] 56 [core]interface Vlanif 10 #創建SVI 57 [core-Vlanif10]ip address 172.30.1.254 24 #給當前VLAN10配置一個管理地址。 58 [core-Vlanif10]undo shutdown 59 [core-Vlanif10]quit 60 [core]interface Vlanif 20 61 [core-Vlanif20]ip address 172.30.2.254 24 62 [core-Vlanif20]undo shutdown 63 [core-Vlanif20]quit 64 [core]interface Vlanif 30 65 [core-Vlanif30]ip address 172.30.3.254 24 66 [core-Vlanif30]undo shutdown 67 [core-Vlanif30]quit 68 [core]interface Vlanif 40 69 [core-Vlanif40]ip address 172.30.4.254 24 70 [core-Vlanif40]undo shutdown 71 [core-Vlanif40]quit 72 [core]interface Vlanif 50 73 [core-Vlanif50]ip address 172.30.5.254 24 74 [core-Vlanif50]undo shutdown 75 [core-Vlanif50]quit
運維部門電腦測試結果如下:
1 PC>ipconfig 2 3 Link local IPv6 address...........: fe80::5689:98ff:fea7:2066 4 IPv6 address......................: :: / 128 5 IPv6 gateway......................: :: 6 IPv4 address......................: 172.30.3.1 7 Subnet mask.......................: 255.255.255.0 8 Gateway...........................: 172.30.3.254 9 Physical address..................: 54-89-98-A7-20-66 10 DNS server........................: 11 12 PC>ping 172.30.1.1 13 14 Ping 172.30.1.1: 32 data bytes, Press Ctrl_C to break 15 From 172.30.1.1: bytes=32 seq=1 ttl=127 time=31 ms 16 From 172.30.1.1: bytes=32 seq=2 ttl=127 time=15 ms 17 From 172.30.1.1: bytes=32 seq=3 ttl=127 time<1 ms 18 From 172.30.1.1: bytes=32 seq=4 ttl=127 time=47 ms 19 From 172.30.1.1: bytes=32 seq=5 ttl=127 time=16 ms 20 21 --- 172.30.1.1 ping statistics --- 22 5 packet(s) transmitted 23 5 packet(s) received 24 0.00% packet loss 25 round-trip min/avg/max = 0/21/47 ms 26 27 PC>ping 172.30.2.1 28 29 Ping 172.30.2.1: 32 data bytes, Press Ctrl_C to break 30 From 172.30.2.1: bytes=32 seq=1 ttl=127 time=47 ms 31 From 172.30.2.1: bytes=32 seq=2 ttl=127 time<1 ms 32 From 172.30.2.1: bytes=32 seq=3 ttl=127 time<1 ms 33 From 172.30.2.1: bytes=32 seq=4 ttl=127 time=32 ms 34 From 172.30.2.1: bytes=32 seq=5 ttl=127 time=46 ms 35 36 --- 172.30.2.1 ping statistics --- 37 5 packet(s) transmitted 38 5 packet(s) received 39 0.00% packet loss 40 round-trip min/avg/max = 0/25/47 ms 41 42 PC>ping 172.30.3.1 43 44 Ping 172.30.3.1: 32 data bytes, Press Ctrl_C to break 45 From 172.30.3.1: bytes=32 seq=1 ttl=128 time<1 ms 46 From 172.30.3.1: bytes=32 seq=2 ttl=128 time<1 ms 47 From 172.30.3.1: bytes=32 seq=3 ttl=128 time<1 ms 48 From 172.30.3.1: bytes=32 seq=4 ttl=128 time<1 ms 49 From 172.30.3.1: bytes=32 seq=5 ttl=128 time<1 ms 50 51 --- 172.30.3.1 ping statistics --- 52 5 packet(s) transmitted 53 5 packet(s) received 54 0.00% packet loss 55 round-trip min/avg/max = 0/0/0 ms 56 57 PC>ping 172.30.4.1 58 59 Ping 172.30.4.1: 32 data bytes, Press Ctrl_C to break 60 From 172.30.4.1: bytes=32 seq=1 ttl=127 time=31 ms 61 From 172.30.4.1: bytes=32 seq=2 ttl=127 time=31 ms 62 From 172.30.4.1: bytes=32 seq=3 ttl=127 time=16 ms 63 From 172.30.4.1: bytes=32 seq=4 ttl=127 time=31 ms 64 From 172.30.4.1: bytes=32 seq=5 ttl=127 time=16 ms 65 66 --- 172.30.4.1 ping statistics --- 67 5 packet(s) transmitted 68 5 packet(s) received 69 0.00% packet loss 70 round-trip min/avg/max = 16/25/31 ms 71 72 PC>ping 172.30.5.1 73 74 Ping 172.30.5.1: 32 data bytes, Press Ctrl_C to break 75 From 172.30.5.1: bytes=32 seq=1 ttl=127 time=16 ms 76 From 172.30.5.1: bytes=32 seq=2 ttl=127 time=15 ms 77 From 172.30.5.1: bytes=32 seq=3 ttl=127 time=16 ms 78 From 172.30.5.1: bytes=32 seq=4 ttl=127 time<1 ms 79 From 172.30.5.1: bytes=32 seq=5 ttl=127 time=31 ms 80 81 --- 172.30.5.1 ping statistics --- 82 5 packet(s) transmitted 83 5 packet(s) received 84 0.00% packet loss 85 round-trip min/avg/max = 0/15/31 ms 86 87 PC>
c.三層交換機的優點
1>.不用路由器照樣實現不同VLAN間的互通;
2>.性價比高,功能比普通二層交換機要多的多.