直连路由和静态路由

                      直连路由和静态路由

 

 

一.简单直连路由拓扑

  上图中路由器不需要任何配置就能互相访问,因为这三个网段的网关地址都在同一个路由器的接口上,属于直连路由,路由器会自动生成路由表,不需要手动配置就可以让这三个区域互相ping通。这就是直连路由的作用!

 

二.静态路由

1.静态路由配置事实例

 

配置过程如下:

"深圳出口"配置如下:

 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  #配置静态默认路由

"武汉骨干路由"配置如下:

 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

"石家庄骨干路由"配置如下:

 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路由协议。

posted @ 2017-04-13 00:02  尹正杰  阅读(13906)  评论(0编辑  收藏  举报