[root@localhost ~]# route
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 255.255.255.0 U 0 0 0 eth0
e192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]# route -n
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
说明
第一行表示主机所在网络的地址为192.168.120.0,若数据传送目标是在本局域网内通信,则可直接通过eth0转发数据包;
第四行表示数据传送目的是访问Inter,则由接口eth0,将数据包发送到网关192.168.120.240
其中Flags为路由标志,标记当前网络节点的状态。
Flags标志说明
U Up表示此路由当前为启动状态
H Host,表示此网关为一主机
G Gateway,表示此网关为一路由器
R Restate Route,使用动态路由重新初始化的路由
D Dynamically,此路由是动态性地写入
M Modified,此路由是由路由守护程序或导向器动态修改
! 表示此路由当前为关闭状态
备注
route -n (-n 表示不解析名字,列出速度会比route 快)
实例2添加网关/设置网关
命令 route add - 224.0.0.0 mask 240.0.0.0 dev eth0
输出
复制代码代码如下:
[root@localhost ~]# route add - 224.0.0.0 mask 240.0.0.0 dev eth0
[root@localhost ~]# route
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
224.0.0.0 240.0.0.0 U 0 0 0 eth0
default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
说明
增加一条 到达244.0.0.0的路由
实例3屏蔽一条路由
命令route add - 224.0.0.0 mask 240.0.0.0 reject
输出
复制代码代码如下:
[root@localhost ~]# route add - 224.0.0.0 mask 240.0.0.0 reject
[root@localhost ~]# route
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
224.0.0.0 - 240.0.0.0 ! 0 - 0 -
224.0.0.0 240.0.0.0 U 0 0 0 eth0
default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
说明
增加一条屏蔽的路由,目的地址为 224.x.x.x 将被拒绝
实例4删除路由记录
命令
复制代码代码如下:
route del - 224.0.0.0 mask 240.0.0.0
route del - 224.0.0.0 mask 240.0.0.0 reject
输出
复制代码代码如下:
[root@localhost ~]# route
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
224.0.0.0 - 240.0.0.0 ! 0 - 0 -
224.0.0.0 240.0.0.0 U 0 0 0 eth0
default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]# route del - 224.0.0.0 mask 240.0.0.0
[root@localhost ~]# route
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
224.0.0.0 - 240.0.0.0 ! 0 - 0 -
default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]# route del - 224.0.0.0 mask 240.0.0.0 reject
[root@localhost ~]# route
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]#
说明
实例5删除和添加设置默认网关
命令
复制代码代码如下:
route del default gw 192.168.120.240
route add default gw 192.168.120.240
输出
复制代码代码如下:
[root@localhost ~]# route del default gw 192.168.120.240
[root@localhost ~]# route
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
[root@localhost ~]# route add default gw 192.168.120.240
[root@localhost ~]# route
Kernel IP routg table
Destation Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0
default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0
[root@localhost ~]#