route:静态路由管理


Centos7 路由管理

跟踪路由

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

[root@nauru-084 ~]# traceroute www.baidu.com
traceroute to www.baidu.com (180.101.49.11), 30 hops max, 60 byte packets
1 gateway (172.18.1.254) 0.299 ms 0.236 ms 0.209 ms
2 172.16.200.12 (172.16.200.12) 0.303 ms 0.243 ms 0.307 ms
3 36.110.61.81 (36.110.61.81) 1.813 ms 4.255 ms 1.630 ms
4 9.235.120.106.static.bjtelecom.net (106.120.235.9) 2.082 ms 1.695 ms *
5 bj141-152-69.bjtelecom.net (219.141.152.69) 2.983 ms 3.016 ms 2.987 ms
6 202.97.97.254 (202.97.97.254) 24.578 ms 202.97.33.30 (202.97.33.30) 29.937 ms 202.97.98.146 (202.97.98.146) 18.506 ms
7 58.213.94.82 (58.213.94.82) 28.225 ms 58.213.95.2 (58.213.95.2) 20.308 ms 58.213.95.106 (58.213.95.106) 19.223 ms
8 * * *
9 58.213.96.110 (58.213.96.110) 21.148 ms 58.213.96.62 (58.213.96.62) 18.620 ms 58.213.96.126 (58.213.96.126) 28.067 ms
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *

查看路由

1
[root@nauru-084 ~]# route -n


添加路由

1
route add -host 10.10.87.38 gw 172.18.1.89

删除路由

1
route del 10.10.87.38

帮助文档

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
[root@localhost ~]# man route

NAME
route - show / manipulate the IP routing table

SYNOPSIS
route [-CFvnNee] [-A family |-4|-6]

route [-v] [-A family |-4|-6] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I] [reject] [mod] [dyn] [reinstate] [[dev] If]

route [-v] [-A family |-4|-6] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If]

route [-V] [--version] [-h] [--help]

EXAMPLES
route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
adds the normal loopback entry, using netmask 255.0.0.0 and associated with the "lo" device (assuming this device was previously set up correctly with ifconfig(8)).

route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0
adds a route to the local network 192.56.76.x via "eth0". The word "dev" can be omitted here.

route del default
deletes the current default route, which is labeled "default" or 0.0.0.0 in the destination field of the current routing table.

route add default gw mango-gw
adds a default route (which will be used if no other route matches). All packets using this route will be gatewayed through "mango-gw". The device which will actually be
used for that route depends on how we can reach "mango-gw" - the static route to "mango-gw" will have to be set up before.

route add ipx4 sl0
Adds the route to the "ipx4" host via the SLIP interface (assuming that "ipx4" is the SLIP host).

route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4
This command adds the net "192.57.66.x" to be gatewayed through the former route to the SLIP interface.

route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
This is an obscure one documented so people know how to do it. This sets all of the class D (multicast) IP routes to go via "eth0". This is the correct normal configuration
line with a multicasting kernel.

route add -net 10.0.0.0 netmask 255.0.0.0 reject
This installs a rejecting route for the private network "10.x.x.x."

Windows 路由管理

跟踪路由

1
2
3
4
5
6
7
8
9
10
11
12
C:\Users\ThinKPad>tracert 10.1.53.2

通过最多 30 个跃点跟踪
到 ThinKPad-PC [10.1.53.2] 的路由:

1 17 ms 13 ms 11 ms ThinKPad-PC [10.202.0.1]
2 10 ms 9 ms 9 ms bogon [172.23.128.12]
3 22 ms 13 ms 14 ms bogon [172.23.180.113]
4 21 ms 12 ms 14 ms bogon [192.168.111.111]
5 13 ms 13 ms 12 ms ThinKPad-PC [10.1.53.2]

跟踪完成。

查看路由

1
route print -4

添加路由

1
2
route add -p 目标IP mask 网段  网关
route add -p 10.1.53.79 mask 255.255.255.255 10.10.113.81

删除路由

1
route delete 10.1.53.79

帮助文档

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
C:\Users\ThinKPad>route \help

操作网络路由表。

ROUTE [-f] [-p] [-4|-6] command [destination]
[MASK netmask] [gateway] [METRIC metric] [IF interface]

-f 清除所有网关项的路由表。如果与某个
命令结合使用,在运行该命令前,
应清除路由表。

-p 与 ADD 命令结合使用时,将路由设置为
在系统引导期间保持不变。默认情况下,重新启动系统时,
不保存路由。忽略所有其他命令,
这始终会影响相应的永久路由。Windows 95
不支持此选项。

-4 强制使用 IPv4。

-6 强制使用 IPv6。

command 其中之一:
PRINT 打印路由
ADD 添加路由
DELETE 删除路由
CHANGE 修改现有路由
destination 指定主机。
MASK 指定下一个参数为“网络掩码”值。
netmask 指定此路由项的子网掩码值。
如果未指定,其默认设置为 255.255.255.255。
gateway 指定网关。
interface 指定路由的接口号码。
METRIC 指定跃点数,例如目标的成本。

用于目标的所有符号名都可以在网络数据库
文件 NETWORKS 中进行查找。用于网关的符号名称都可以在主机名称
数据库文件 HOSTS 中进行查找。

如果命令为 PRINT 或 DELETE。目标或网关可以为通配符,
(通配符指定为星号“*”),否则可能会忽略网关参数。

如果 Dest 包含一个 * 或 ?,则会将其视为 Shell 模式,并且只
打印匹配目标路由。“*”匹配任意字符串,
而“?”匹配任意一个字符。示例: 157.*.1、157.*、127.*、*224*。

只有在 PRINT 命令中才允许模式匹配。
诊断信息注释:
无效的 MASK 产生错误,即当 (DEST & MASK) != DEST 时。
示例: > route ADD 157.0.0.0 MASK 155.0.0.0 157.55.80.1 IF 1
路由添加失败: 指定的掩码参数无效。
(Destination & Mask) != Destination。

示例:

> route PRINT
> route PRINT -4
> route PRINT -6
> route PRINT 157* .... 只打印那些匹配 157* 的项

> route ADD 157.0.0.0 MASK 255.0.0.0 157.55.80.1 METRIC 3 IF 2
destination^ ^mask ^gateway metric^ ^
Interface^
如果未给出 IF,它将尝试查找给定网关的最佳
接口。
> route ADD 3ffe::/32 3ffe::1

> route CHANGE 157.0.0.0 MASK 255.0.0.0 157.55.80.5 METRIC 2 IF 2

CHANGE 只用于修改网关和/或跃点数。

> route DELETE 157.0.0.0
> route DELETE 3ffe::/32