直連路由和靜態路由ide
一.簡單直連路由拓撲oop
上圖中路由器不須要任何配置就能互相訪問,由於這三個網段的網關地址都在同一個路由器的接口上,屬於直連路由,路由器會自動生成路由表,不須要手動配置就可讓這三個區域互相ping通。這就是直連路由的做用!學習
二.靜態路由測試
1.靜態路由配置事實例ui
配置過程以下:spa
"深圳出口"配置以下:code
1 [Huawei]sysname shenzhen 2 [R1]interface Ethernet 0/0/0 3 [R1-Ethernet0/0/0]IP address 192.168.1.254 20 4 [R1-Ethernet0/0/0]undo shutdown 5 [R1-Ethernet0/0/0]quit 6 [shenzhen]interface Ethernet 0/0/1 7 [shenzhen-Ethernet0/0/1]ip address 202.96.134.133 24 8 [shenzhen-Ethernet0/0/1]undo shutdown 9 [shenzhen-Ethernet0/0/1]quit 10 [shenzhen]ip route-static 0.0.0.0 0.0.0.0 202.96.134.134 #配置靜態默認路由
"武漢骨幹路由"配置以下:server
1 [Huawei]sysname wuhan 2 [wuhan]interface Ethernet 0/0/1 3 [wuhan-Ethernet0/0/1]ip address 202.96.134.134 24 4 [wuhan-Ethernet0/0/1]undo shutdown 5 [wuhan-Ethernet0/0/1]quit 6 [wuhan]interface Ethernet 0/0/0 7 [wuhan-Ethernet0/0/0]ip address 202.103.24.68 24 8 [wuhan-Ethernet0/0/0]undo shutdown 9 [wuhan-Ethernet0/0/0]quit 10 [wuhan]ip route-static 192.168.0.0 20 202.96.134.133 11 [wuhan]ip route-static 0.0.0.0 0.0.0.0 202.103.24.69
"石家莊骨幹路由"配置以下:blog
1 [Huawei]sysname shijiazhuang 2 [shijiazhuang]interface Ethernet 0/0/0 3 [shijiazhuang-Ethernet0/0/0]ip address 202.103.24.69 24 4 [shijiazhuang-Ethernet0/0/0]undo shutdown 5 [shijiazhuang-Ethernet0/0/0]quit 6 [shijiazhuang]interface Ethernet 0/0/1 7 [shijiazhuang-Ethernet0/0/1]ip address 218.12.41.179 24 8 [shijiazhuang-Ethernet0/0/1]undo shutdown 9 [shijiazhuang-Ethernet0/0/1]quit 10 [shijiazhuang]ip route-static 172.30.0.0 21 218.12.41.180 #配置去往172.30.0.0/21的下一條靜態路由 11 [shijiazhuang]ip route-static 192.168.0.0 20 202.103.24.68
"北京出口"配置以下:接口
1 [Huawei]sysname beijing 2 [beijing]interface Ethernet 0/0/0 3 [beijing-Ethernet0/0/0]ip address 172.30.3.254 21 4 [beijing-Ethernet0/0/0]undo shutdown 5 [beijing-Ethernet0/0/0]quit 6 [beijing]interface Ethernet 0/0/1 7 [beijing-Ethernet0/0/1]ip address 218.12.41.180 24 8 [beijing-Ethernet0/0/1]quit 9 [beijing]ip route-static 0.0.0.0 0.0.0.0 218.12.41.179
深圳開發機測試結果以下:
1 PC>ipconfig 2 3 Link local IPv6 address...........: fe80::5689:98ff:fedc:58a6 4 IPv6 address......................: :: / 128 5 IPv6 gateway......................: :: 6 IPv4 address......................: 192.168.10.1 7 Subnet mask.......................: 255.255.240.0 8 Gateway...........................: 192.168.1.254 9 Physical address..................: 54-89-98-DC-58-A6 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=124 time=109 ms 16 From 172.30.1.1: bytes=32 seq=2 ttl=124 time=140 ms 17 From 172.30.1.1: bytes=32 seq=3 ttl=124 time=109 ms 18 From 172.30.1.1: bytes=32 seq=4 ttl=124 time=125 ms 19 From 172.30.1.1: bytes=32 seq=5 ttl=124 time=109 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 = 109/118/140 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=124 time=124 ms 31 From 172.30.2.1: bytes=32 seq=2 ttl=124 time=109 ms 32 From 172.30.2.1: bytes=32 seq=3 ttl=124 time=94 ms 33 From 172.30.2.1: bytes=32 seq=4 ttl=124 time=171 ms 34 From 172.30.2.1: bytes=32 seq=5 ttl=124 time=124 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 = 94/124/171 ms 41 42 PC>ping 172.30.3.254 43 44 Ping 172.30.3.254: 32 data bytes, Press Ctrl_C to break 45 From 172.30.3.254: bytes=32 seq=1 ttl=252 time=94 ms 46 From 172.30.3.254: bytes=32 seq=2 ttl=252 time=93 ms 47 From 172.30.3.254: bytes=32 seq=3 ttl=252 time=63 ms 48 From 172.30.3.254: bytes=32 seq=4 ttl=252 time=94 ms 49 From 172.30.3.254: bytes=32 seq=5 ttl=252 time=94 ms 50 51 --- 172.30.3.254 ping statistics --- 52 5 packet(s) transmitted 53 5 packet(s) received 54 0.00% packet loss 55 round-trip min/avg/max = 63/87/94 ms 56 57 PC>ping 218.12.41.180 58 59 Ping 218.12.41.180: 32 data bytes, Press Ctrl_C to break 60 From 218.12.41.180: bytes=32 seq=1 ttl=252 time=109 ms 61 From 218.12.41.180: bytes=32 seq=2 ttl=252 time=93 ms 62 From 218.12.41.180: bytes=32 seq=3 ttl=252 time=93 ms 63 From 218.12.41.180: bytes=32 seq=4 ttl=252 time=78 ms 64 From 218.12.41.180: bytes=32 seq=5 ttl=252 time=78 ms 65 66 --- 218.12.41.180 ping statistics --- 67 5 packet(s) transmitted 68 5 packet(s) received 69 0.00% packet loss 70 round-trip min/avg/max = 78/90/109 ms 71 72 PC>ping 202.103.24.69 73 74 Ping 202.103.24.69: 32 data bytes, Press Ctrl_C to break 75 From 202.103.24.69: bytes=32 seq=1 ttl=253 time=62 ms 76 From 202.103.24.69: bytes=32 seq=2 ttl=253 time=78 ms 77 From 202.103.24.69: bytes=32 seq=3 ttl=253 time=94 ms 78 From 202.103.24.69: bytes=32 seq=4 ttl=253 time=62 ms 79 From 202.103.24.69: bytes=32 seq=5 ttl=253 time=63 ms 80 81 --- 202.103.24.69 ping statistics --- 82 5 packet(s) transmitted 83 5 packet(s) received 84 0.00% packet loss 85 round-trip min/avg/max = 62/71/94 ms 86 87 PC>ping 202.96.134.134 88 89 Ping 202.96.134.134: 32 data bytes, Press Ctrl_C to break 90 From 202.96.134.134: bytes=32 seq=1 ttl=254 time=47 ms 91 From 202.96.134.134: bytes=32 seq=2 ttl=254 time=63 ms 92 From 202.96.134.134: bytes=32 seq=3 ttl=254 time=62 ms 93 From 202.96.134.134: bytes=32 seq=4 ttl=254 time=62 ms 94 From 202.96.134.134: bytes=32 seq=5 ttl=254 time=46 ms 95 96 --- 202.96.134.134 ping statistics --- 97 5 packet(s) transmitted 98 5 packet(s) received 99 0.00% packet loss 100 round-trip min/avg/max = 46/56/63 ms 101 102 PC>ping 192.168.1.254 103 104 Ping 192.168.1.254: 32 data bytes, Press Ctrl_C to break 105 From 192.168.1.254: bytes=32 seq=1 ttl=255 time=16 ms 106 From 192.168.1.254: bytes=32 seq=2 ttl=255 time=31 ms 107 From 192.168.1.254: bytes=32 seq=3 ttl=255 time=31 ms 108 From 192.168.1.254: bytes=32 seq=4 ttl=255 time=31 ms 109 From 192.168.1.254: bytes=32 seq=5 ttl=255 time=32 ms 110 111 --- 192.168.1.254 ping statistics --- 112 5 packet(s) transmitted 113 5 packet(s) received 114 0.00% packet loss 115 round-trip min/avg/max = 16/28/32 ms 116 117 PC>
2.靜態路由實現路由備份和負載分擔
a.路由備份:
1>.到相同目的地址的下一條和優先級都不一樣;
2>.優先級高的爲主,低的爲備;
b.負載分擔:
1>.到相同目的地址的下一跳不一樣,但優先級相同;
2>.到目的地的流量均勻分佈
案例展現:
企業出口路由器是同事連接電信運營商和移動運營商,電信100M帶寬,移動20M帶寬,要求默認狀況下企業內部上網所有走電信100M,當電信100M鏈路DOWN掉,自動切換到移動20M鏈路中去。
案例分析:
1.採用靜態路由的備份技術(須要寫2條默認路由,當一個ISP端口掛掉後,可以迅速自動啓用另外的一個ISP出口。)
2.默認狀況下企業內部上網所有走電信;(須要這是默認路由的優先級);
配置過程以下:
"核心交換機"
1 "核心交換機"配置以下: 2 [Huawei]sysname core 3 [core]interface GigabitEthernet 0/0/10 4 [core-GigabitEthernet0/0/10]port link-type trunk
"公司路由"
1 "公司路由"配置以下: 2 [Huawei]sysname gongsi 3 [gongsi]interface Ethernet 0/0/0 4 [gongsi-Ethernet0/0/0]ip address 172.30.100.254 24 5 [gongsi-Ethernet0/0/0]undo shutdown 6 [gongsi-Ethernet0/0/0]quit 7 [gongsi]interface GigabitEthernet0/0/0 8 [gongsi-GigabitEthernet0/0/0]ip address 36.110.101.150 24 9 [gongsi-GigabitEthernet0/0/0]undo shutdown 10 [gongsi-GigabitEthernet0/0/0]quit 11 [gongsi]interface GigabitEthernet 0/0/1 12 [gongsi-GigabitEthernet0/0/1]ip address 223.71.241.1 24 13 [gongsi-GigabitEthernet0/0/1]undo shutdown 14 [gongsi-GigabitEthernet0/0/1]quit 15 [gongsi]ip route-static 0.0.0.0 0.0.0.0 36.110.101.151 16 [gongsi]ip route-static 0.0.0.0 0.0.0.0 223.71.241.2 17 [gongsi]display ip routing-table 18 Route Flags: R - relay, D - download to fib 19 ------------------------------------------------------------------------------ 20 Routing Tables: Public 21 Destinations : 9 Routes : 10 22 23 Destination/Mask Proto Pre Cost Flags NextHop Interface 24 25 0.0.0.0/0 Static 60 0 RD 36.110.101.151 GigabitEthernet0/0/0 #默認路由的優先級是都是60. 26 Static 60 0 RD 223.71.241.2 GigabitEthernet0/0/1 27 36.110.101.0/24 Direct 0 0 D 36.110.101.150 GigabitEthernet0/0/0 28 36.110.101.150/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 29 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 30 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 31 172.30.100.0/24 Direct 0 0 D 172.30.100.254 Ethernet0/0/0 32 172.30.100.254/32 Direct 0 0 D 127.0.0.1 Ethernet0/0/0 33 223.71.241.0/24 Direct 0 0 D 223.71.241.1 GigabitEthernet0/0/1 34 223.71.241.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 35 [gongsi] 36 37 [gongsi]ip route-static 0.0.0.0 0.0.0.0 36.110.101.151 preference 50 #修改默認管理距離爲50,默認的管理距離是60,這個數字越小,優先級就越高,越有限走這條路由! 38 [gongsi]display ip routing-table 39 Route Flags: R - relay, D - download to fib 40 ------------------------------------------------------------------------------ 41 Routing Tables: Public 42 Destinations : 9 Routes : 9 43 44 Destination/Mask Proto Pre Cost Flags NextHop Interface 45 46 0.0.0.0/0 Static 50 0 RD 36.110.101.151 GigabitEthernet0/0/0 #進入路由表是管理距離小的,由於優先級比默認配置的60要小。 47 36.110.101.0/24 Direct 0 0 D 36.110.101.150 GigabitEthernet0/0/0 48 36.110.101.150/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 49 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 50 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 51 172.30.100.0/24 Direct 0 0 D 172.30.100.254 Ethernet0/0/0 52 172.30.100.254/32 Direct 0 0 D 127.0.0.1 Ethernet0/0/0 53 223.71.241.0/24 Direct 0 0 D 223.71.241.1 GigabitEthernet0/0/1 54 223.71.241.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 55 [gongsi]
"電信ISP"
1 "電信ISP"配置以下: 2 [Huawei]sysname dianxin 3 [dianxin-GigabitEthernet0/0/1]ip address 36.110.101.151 24 4 [dianxin-GigabitEthernet0/0/1]undo shutdown 5 [dianxin-GigabitEthernet0/0/1]quit 6 [dianxin]interface LoopBack 1 7 [dianxin-LoopBack1]ip address 10.8.96.1 32 8 [dianxin-LoopBack1]quit 9 [dianxin]interface LoopBack 2 10 [dianxin-LoopBack2]ip address 10.8.96.2 32 11 [dianxin-LoopBack2]quit 12 [dianxin]interface LoopBack 3 13 [dianxin-LoopBack3]ip address 10.8.96.3 32 14 [dianxin-LoopBack3]quit 15 [dianxin]ip route-static 0.0.0.0 0.0.0.0 36.110.101.150 16 <dianxin>display ip routing-table 17 Route Flags: R - relay, D - download to fib 18 ------------------------------------------------------------------------------ 19 Routing Tables: Public 20 Destinations : 8 Routes : 8 21 22 Destination/Mask Proto Pre Cost Flags NextHop Interface 23 24 0.0.0.0/0 Static 60 0 RD 36.110.101.150 GigabitEthernet0/0/1 25 10.8.96.1/32 Direct 0 0 D 127.0.0.1 LoopBack1 26 10.8.96.2/32 Direct 0 0 D 127.0.0.1 LoopBack2 27 10.8.96.3/32 Direct 0 0 D 127.0.0.1 LoopBack3 28 36.110.101.0/24 Direct 0 0 D 36.110.101.151 GigabitEthernet0/0/1 29 36.110.101.151/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 30 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 31 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 32 33 <dianxin>
"移動ISP"
1 "移動ISP"配置以下: 2 [Huawei]sysname yidong 3 [yidong]interface GigabitEthernet 0/0/2 4 [yidong-GigabitEthernet0/0/2]ip address 223.71.241.2 24 5 [yidong-GigabitEthernet0/0/2]undo shutdown 6 [yidong-GigabitEthernet0/0/2]quit 7 [yidong]interface LoopBack 1 8 [yidong-LoopBack1]ip address 10.8.96.1 32 9 [yidong-LoopBack1]quit 10 [yidong]interface LoopBack 2 11 [yidong-LoopBack2]ip address 10.8.96.2 32 12 [yidong-LoopBack2]quit 13 [yidong]interface LoopBack 3 14 [yidong-LoopBack3]ip address 10.8.96.3 32 15 [yidong-LoopBack3]quit 16 [yidong]ip route-static 0.0.0.0 0.0.0.0 223.71.241.1 17 [yidong]display ip routing-table 18 Route Flags: R - relay, D - download to fib 19 ------------------------------------------------------------------------------ 20 Routing Tables: Public 21 Destinations : 8 Routes : 8 22 23 Destination/Mask Proto Pre Cost Flags NextHop Interface 24 25 0.0.0.0/0 Static 60 0 RD 223.71.241.1 GigabitEthernet0/0/2 26 10.8.96.1/32 Direct 0 0 D 127.0.0.1 LoopBack1 27 10.8.96.2/32 Direct 0 0 D 127.0.0.1 LoopBack2 28 10.8.96.3/32 Direct 0 0 D 127.0.0.1 LoopBack3 29 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 30 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 31 223.71.241.0/24 Direct 0 0 D 223.71.241.2 GigabitEthernet0/0/2 32 223.71.241.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2 33 [yidong]
測試結果以下:
1 PC>ipconfig 2 3 Link local IPv6 address...........: fe80::5689:98ff:fec4:4b82 4 IPv6 address......................: :: / 128 5 IPv6 gateway......................: :: 6 IPv4 address......................: 172.30.100.1 7 Subnet mask.......................: 255.255.255.0 8 Gateway...........................: 172.30.100.254 9 Physical address..................: 54-89-98-C4-4B-82 10 DNS server........................: 11 12 PC>ping 172.30.100.2 13 14 Ping 172.30.100.2: 32 data bytes, Press Ctrl_C to break 15 From 172.30.100.2: bytes=32 seq=1 ttl=128 time=31 ms 16 From 172.30.100.2: bytes=32 seq=2 ttl=128 time=15 ms 17 From 172.30.100.2: bytes=32 seq=3 ttl=128 time=16 ms 18 From 172.30.100.2: bytes=32 seq=4 ttl=128 time=16 ms 19 From 172.30.100.2: bytes=32 seq=5 ttl=128 time=15 ms 20 21 --- 172.30.100.2 ping statistics --- 22 5 packet(s) transmitted 23 5 packet(s) received 24 0.00% packet loss 25 round-trip min/avg/max = 15/18/31 ms 26 27 PC>ping 172.30.100.254 28 29 Ping 172.30.100.254: 32 data bytes, Press Ctrl_C to break 30 From 172.30.100.254: bytes=32 seq=1 ttl=255 time=47 ms 31 From 172.30.100.254: bytes=32 seq=2 ttl=255 time=31 ms 32 From 172.30.100.254: bytes=32 seq=3 ttl=255 time=32 ms 33 From 172.30.100.254: bytes=32 seq=4 ttl=255 time=32 ms 34 From 172.30.100.254: bytes=32 seq=5 ttl=255 time=31 ms 35 36 --- 172.30.100.254 ping statistics --- 37 5 packet(s) transmitted 38 5 packet(s) received 39 0.00% packet loss 40 round-trip min/avg/max = 31/34/47 ms 41 42 PC>ping 36.110.101.151 43 44 Ping 36.110.101.151: 32 data bytes, Press Ctrl_C to break 45 From 36.110.101.151: bytes=32 seq=1 ttl=254 time=63 ms 46 From 36.110.101.151: bytes=32 seq=2 ttl=254 time=47 ms 47 From 36.110.101.151: bytes=32 seq=3 ttl=254 time=47 ms 48 From 36.110.101.151: bytes=32 seq=4 ttl=254 time=46 ms 49 From 36.110.101.151: bytes=32 seq=5 ttl=254 time=47 ms 50 51 --- 36.110.101.151 ping statistics --- 52 5 packet(s) transmitted 53 5 packet(s) received 54 0.00% packet loss 55 round-trip min/avg/max = 46/50/63 ms 56 57 PC>ping 223.71.241.2 58 59 Ping 223.71.241.2: 32 data bytes, Press Ctrl_C to break 60 From 223.71.241.2: bytes=32 seq=1 ttl=254 time=47 ms 61 From 223.71.241.2: bytes=32 seq=2 ttl=254 time=63 ms 62 From 223.71.241.2: bytes=32 seq=3 ttl=254 time=47 ms 63 From 223.71.241.2: bytes=32 seq=4 ttl=254 time=63 ms 64 From 223.71.241.2: bytes=32 seq=5 ttl=254 time=62 ms 65 66 --- 223.71.241.2 ping statistics --- 67 5 packet(s) transmitted 68 5 packet(s) received 69 0.00% packet loss 70 round-trip min/avg/max = 47/56/63 ms 71 72 PC>ping 10.8.96.1 73 74 Ping 10.8.96.1: 32 data bytes, Press Ctrl_C to break 75 From 10.8.96.1: bytes=32 seq=1 ttl=254 time=47 ms 76 From 10.8.96.1: bytes=32 seq=2 ttl=254 time=78 ms 77 From 10.8.96.1: bytes=32 seq=3 ttl=254 time=47 ms 78 From 10.8.96.1: bytes=32 seq=4 ttl=254 time=47 ms 79 From 10.8.96.1: bytes=32 seq=5 ttl=254 time=78 ms 80 81 --- 10.8.96.1 ping statistics --- 82 5 packet(s) transmitted 83 5 packet(s) received 84 0.00% packet loss 85 round-trip min/avg/max = 47/59/78 ms 86 87 PC>
3.靜態黑洞路由應用
正確應用黑洞路由能夠消除環路
經過上圖中的靜態路由的配置,RTA,RTB,RTC要是想訪問RTE,則必須通過RTD,由於他們都是RTD的直連路由,所以當RTA訪問RTE的數據時,RTD須要寫一個默認路由扔個RTE,路由要有去有會,所以RTE會寫一套靜態路由扔個RTD,來回反覆的扔來扔去就會致使環路,這個時候咱們只須要在RTD中寫一個靜態路由,將RTE丟回來的數據放回回收站中不做處理便可。就不會致使環路發生。可是這麼配置非常麻煩,你以爲呢?一兩臺路由器還好,要是多了,就比較無法了,靜態路由配置比較繁瑣,可是是路由中最有意思的,也能增強咱們隊路由的理解。後期,咱們會學習RIP以及OSPF路由協議。