路由表
路由表的形成、来源
直连路由
路由器接口上直接连接的网络(接口上配地址并且开启)
静态路由
管理员手工添加的网络
动态路由
路由器之间动态学习到的网络
直连路由
拓扑图
配置命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49[V200R003C00]
#
sysname R1
#
snmp-agent local-engineid 800007DB03000000000000
snmp-agent
#
clock timezone BJ add 08:00:00
#
portal local-server load portalpage.zip
#
drop illegal-mac alarm
#
set cpu-usage threshold 80 restore 75
#
aaa
authentication-scheme default
authorization-scheme default
accounting-scheme default
domain default
domain default_admin
local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
local-user admin service-type http
local-user wuchao password cipher %$%$C%Rk5fw{%M^+hRC,e5nMeJ$"%$%$
local-user wuchao privilege level 15
local-user wuchao service-type telnet
#
firewall zone Local
priority 15
#
interface GigabitEthernet0/0/0
ip address 192.168.100.254 255.255.255.0
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
user-interface con 0
authentication-mode password
user-interface vty 0 4
authentication-mode aaa
idle-timeout 10 0
user-interface vty 16 20
#
wlan ac
#
return路由表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19<R1>dis ip rou
<R1>dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost Flags NextHop Interface
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
# 网络路由
192.168.100.0/24 Direct 0 0 D 192.168.100.254 GigabitEthernet0/0/0
# 主机路由
192.168.100.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
# 广播路由
192.168.100.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
静态路由
拓扑图
配置
局域直连配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19<R1>sys
[R1]interface g0/0/1
[R1-GigabitEthernet0/0/1]ip add 2.0.0.1 24
[R1]dis interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
^down: standby
(e): ETHOAM down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/0 up up 0% 0% 0 0
GigabitEthernet0/0/1 up up 0% 0% 0 0
GigabitEthernet0/0/2 down down 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0R1配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]int
[R1]interface g0/0/2
[R1-GigabitEthernet0/0/2]ip add 12.0.0.1 24
[R1-GigabitEthernet0/0/2]q
[R1]dis int
[R1]dis interface br
[R1]dis interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
^down: standby
(e): ETHOAM down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/0 up up 0% 0% 0 0
GigabitEthernet0/0/1 up up 0% 0% 0 0
GigabitEthernet0/0/2 up up 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0R2配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname R2
[R2]user-int
[R2]user-interface vty 0 4
[R2-ui-vty0-4]aut
[R2-ui-vty0-4]authentication-mode aaa
[R2-ui-vty0-4]aaa
[R2-aaa]local
[R2-aaa]local-user wuchao pas
[R2-aaa]local-user wuchao password ci
[R2-aaa]local-user wuchao password cipher 110119
Info: Add a new user.
[R2-aaa]local-us
[R2-aaa]local-user wuchao pri
[R2-aaa]local-user wuchao privilege le
[R2-aaa]local-user wuchao privilege level 15
[R2-aaa]local
[R2-aaa]local-user wuchao ser
[R2-aaa]local-user wuchao service-type telnet
[R2-aaa]q
[R2]telnet ser
[R2]telnet server en
[R2]telnet server enable
[R2]int
[R2]interface g0/0/0
[R2-GigabitEthernet0/0/0]ip add
[R2-GigabitEthernet0/0/0]ip address 12.0.0.2 24
Apr 5 2021 11:37:57-08:00 R2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[R2]int
[R2]interface g0/0/1
[R2-GigabitEthernet0/0/1]ip add 4.0.0.1 24
[R2-GigabitEthernet0/0/1]q
[R2]dis int
[R2]dis interface br
[R2]dis interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
^down: standby
(e): ETHOAM down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/0 up up 0% 0% 0 0
GigabitEthernet0/0/1 up up 0% 0% 0 0
GigabitEthernet0/0/2 down down 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0静态路由配置
R1配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]ip rout
[R1]ip route-s
[R1]ip route-static 4.0.0.0 24 12.0.0.2
[R1]dis ip r
[R1]dis ip rout
[R1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.0.0.0/24 Direct 0 0 D 2.0.0.1 GigabitEthernet0/0/1
2.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
2.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
4.0.0.0/24 Static 60 0 RD 12.0.0.2 GigabitEthernet0/0/2
12.0.0.0/24 Direct 0 0 D 12.0.0.1 GigabitEthernet0/0/2
12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.100.0/24 Direct 0 0 D 192.168.100.1 GigabitEthernet0/0/0
192.168.100.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
192.168.100.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0R2配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35<R2>sys
Enter system view, return user view with Ctrl+Z.
[R2]ip rout
[R2]ip route-s
[R2]ip route-static 192.168.100.0 24 12.0.0.1
[R2]ip route-static 2.0.0.0 24 12.0.0.1
<R2>dis ip rou
<R2>dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 12 Routes : 12
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.0.0.0/24 Static 60 0 RD 12.0.0.1 GigabitEthernet
0/0/0
4.0.0.0/24 Direct 0 0 D 4.0.0.1 GigabitEthernet
0/0/1
4.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
4.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
12.0.0.0/24 Direct 0 0 D 12.0.0.2 GigabitEthernet
0/0/0
12.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.100.0/24 Static 60 0 RD 12.0.0.1 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
静态路由概述
优点:
- 配置简单,开销小
- 通过手动进行添加和威化
缺点:
- 无法根据拓扑的变化进行动态响应
- 适用于小型网络环境,如果网络规模过大,维护成本升高
大型网路中适合使用动静结合的路由策略
配置命令
1
2# 配置静态路由
ip route-static 目标网络 子网掩码(前缀) 下一跳路由接口IP地址/出接口- 如果出接口是以太网口,必须写下一跳路由接口IP地址
- 如果出接口是串口,下一跳路由接口IP地址或者出接口都可以
- 通信是双向的,不要忘记配置返回流量的路由
静态路由配置的形式
图示
负载均衡
拓扑图
命令配置
R1配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]int
[R1]interface E4/0/0
[R1-Ethernet4/0/0]ip add 34.0.0.1 24
[R1-Ethernet4/0/0]q
[R1]dis int
[R1]dis interface bri
[R1]dis interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
^down: standby
(e): ETHOAM down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
Ethernet4/0/0 up up 0% 0% 0 0
Ethernet4/0/1 down down 0% 0% 0 0
GigabitEthernet0/0/0 up up 0% 0% 0 0
GigabitEthernet0/0/1 up up 0% 0% 0 0
GigabitEthernet0/0/2 up up 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0
[R1]dis ip in
[R1]dis ip interface br
[R1]dis ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 5
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 5
The number of interface that is DOWN in Protocol is 1
Interface IP Address/Mask Physical Protocol
Ethernet4/0/0 34.0.0.1/24 up up
Ethernet4/0/1 unassigned down down
GigabitEthernet0/0/0 192.168.100.1/24 up up
GigabitEthernet0/0/1 2.0.0.1/24 up up
GigabitEthernet0/0/2 12.0.0.1/24 up up
NULL0 unassigned up up(s)
#配置第二条路由
<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]ip rout
[R1]ip route-s
[R1]ip route-static 4.0.0.0 24 34.0.0.2
[R1]dis ip rout
[R1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 17 Routes : 18
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.0.0.0/24 Direct 0 0 D 2.0.0.1 GigabitEthernet0/0/1
2.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
2.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
4.0.0.0/24 Static 60 0 RD 12.0.0.2 GigabitEthernet0/0/2
Static 60 0 RD 34.0.0.2 Ethernet4/0/0
12.0.0.0/24 Direct 0 0 D 12.0.0.1 GigabitEthernet0/0/2
12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
34.0.0.0/24 Direct 0 0 D 34.0.0.1 Ethernet4/0/0
34.0.0.1/32 Direct 0 0 D 127.0.0.1 Ethernet4/0/0
34.0.0.255/32 Direct 0 0 D 127.0.0.1 Ethernet4/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.100.0/24 Direct 0 0 D 192.168.100.1 GigabitEthernet0/0/0
192.168.100.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
192.168.100.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
+ R2配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<R2>sys
Enter system view, return user view with Ctrl+Z.
[R2]inter
[R2]interface G0/0/2
[R2-GigabitEthernet0/0/2]ip add 34.0.0.2 24
[R2-GigabitEthernet0/0/2]q
[R2]dis int
[R2]dis interface br
[R2]dis interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
^down: standby
(e): ETHOAM down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/0 up up 0% 0% 0 0
GigabitEthernet0/0/1 up up 0% 0% 0 0
GigabitEthernet0/0/2 up up 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0
[R2]dis ip int
[R2]dis ip interface br
[R2]dis ip interface brief
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 0
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 0
Interface IP Address/Mask Physical Protocol
GigabitEthernet0/0/0 12.0.0.2/24 up up
GigabitEthernet0/0/1 4.0.0.1/24 up up
GigabitEthernet0/0/2 34.0.0.2/24 up up
NULL0 unassigned up up(s)
#配置第二条路由
<R2>sys
Enter system view, return user view with Ctrl+Z.
[R2]inter
[R2]interface G0/0/2
[R2-GigabitEthernet0/0/2]ip add 34.0.0.2 24
[R2]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 15 Routes : 16
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.0.0.0/24 Static 60 0 RD 12.0.0.1 GigabitEthernet0/0/0
Static 60 0 RD 34.0.0.1 GigabitEthernet0/0/2
4.0.0.0/24 Direct 0 0 D 4.0.0.1 GigabitEthernet0/0/1
4.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
4.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
12.0.0.0/24 Direct 0 0 D 12.0.0.2 GigabitEthernet0/0/0
12.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
34.0.0.0/24 Direct 0 0 D 34.0.0.2 GigabitEthernet0/0/2
34.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
34.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.100.0/24 Static 60 0 RD 12.0.0.1 GigabitEthernet0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
+ 图示
![alt 负载均衡图示](https://i.loli.net/2021/04/05/95EJ748BIniZoWs.png)
主备备份
图示
命令实现
R1配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]ip rout
[R1]ip route-s
[R1]ip route-static 4.0.0.0 24 12.0.0.2 pre
[R1]ip route-static 4.0.0.0 24 12.0.0.2 preference 61
Info: Succeeded in modifying route.
[R1]dis ip rou
[R1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 17 Routes : 17
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.0.0.0/24 Direct 0 0 D 2.0.0.1 GigabitEthernet0/0/1
2.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
2.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1
4.0.0.0/24 Static 60 0 RD 34.0.0.2 Ethernet4/0/0
12.0.0.0/24 Direct 0 0 D 12.0.0.1 GigabitEthernet0/0/2
12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2
34.0.0.0/24 Direct 0 0 D 34.0.0.1 Ethernet4/0/0
34.0.0.1/32 Direct 0 0 D 127.0.0.1 Ethernet4/0/0
34.0.0.255/32 Direct 0 0 D 127.0.0.1 Ethernet4/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.100.0/24 Direct 0 0 D 192.168.100.1 GigabitEthernet0/0/0
192.168.100.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
192.168.100.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0R2配置
1
2
3
4
5
6<R2>sys
Enter system view, return user view with Ctrl+Z.
[R2]ip rout
[R2]ip route-s
[R2]ip route-static 2.0.0.2 24 12.0.0.1 pre
[R2]ip route-static 2.0.0.2 24 12.0.0.1 preference 61结果显示
修改优先级之后,路由走34.0.0.0/24段
关闭其中一个端口,路由走备份路由12.0.0.0/24段
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22[R2]int
[R2]interface g0/0/2
[R2-GigabitEthernet0/0/2]shut
[R2-GigabitEthernet0/0/2]shutdown
[R2-GigabitEthernet0/0/2]q
[R2]dis int
[R2]dis interface br
[R2]dis interface brief
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
^down: standby
(e): ETHOAM down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/0 up up 0% 0% 0 0
GigabitEthernet0/0/1 up up 0% 0% 0 0
GigabitEthernet0/0/2 *down down 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0
缺省路由
定义
一种特殊的路由,可以匹配所有的目标网络
配置方式
可以通过静态路由来实现
1
ip route-static 0.0.0.0 0 下一跳路由接口IP地址
可以通过动态协议实现
路由表中显示
0.0.0.0 0 下一跳地址
通常用于末梢网络
家庭上网
企业出口
loopback 回环口(逻辑、虚拟的接口)
- 模拟直连网段,用于测试
- 设备管理
- 供其他协议使用(OSPF、BGP、MPLS)
- SNMP Traps消息的源地址