首页 > 编程知识 正文

route change命令详解,路由命令 route

时间:2023-05-03 12:28:18 阅读:135980 作者:721

1 .命令格式:

route [-f ] [-p ] [ command [ destination ] [ mask net mask ] [ gateway ] [ metric metric ] [ if interface ] ]

2 .命令功能:

Route命令用于操作基于内核的ip路由表,其主要作用是创建静态路由,以允许指定的主机或网络通过网络接口(如eth0)。 使用“添加”或“删除”参数会更改路由表,如果没有参数,则会显示路由表的当前内容。

3 .命令参数:

-c显示详细信息

-n不分析名称

-v显示详细的处理信息

-F显示发送消息

-C显示路由缓存

-f清除所有网关入口的路由表。

-p与add命令一起使用时会使根永久化。

add:将添加新的路由。

del:删除路线。

-net:目标地址是网络。

-host:目标地址是主机。

添加网络路由时,netmask:必须使用网络掩码。

gw:路由分组通过网关。 请注意,你指定的网关必须能够达到。

公制:设置路由跳数。

Command指定要执行的命令(Add/Change/Delete/Print )。

Destination指定路由的网络目标。

掩码net掩码指定与网络目标相关联的网络掩码(也称为子网掩码)。

网关指定网络目标定义的地址集和子网掩码可以到达的正向或下一跳的IP地址。

metric Metric为路由分配9999的整数成本值标签。 您可以在路由表中选择与转发数据包的目标地址最匹配的多条路由。

if Interface指定可以访问目标的接口的接口索引。 要获取接口列表及其相应的接口索引,请使用route print命令的显示功能。 接口索引可以使用十进制或十六进制值。

4 .使用示例:

示例1 :显示当前路线

命令:

路径

route -n

输出:

[ root @ localhost~] # routekerneliproutingtabledestinationgatewaygenmaskflagsmetricrefuseiface 192.168.120.0 * 255.255.255.0 u 00 eth 0e 192.168.0.0192.120.1255.0 ug0 eth 010.0.0.0.0192.168.120.1255.0 ug00 eth 0 route-nkerneliproutingtabledestinationgatewaygenmaskflagsmetricrefuseiface 192.168.120.0.0.0.0.255.255.0 68

第一行表示主机所在的网络的地址是192.168.120.0,如果数据传输目的地是局域网内的通信,则可以通过eth0直接传输数据包

第四行表示数据传输的目的是接入因特网,从接口eth0向网关192.168.120.240发送分组

其中,Flags是路由标志,用于标记当前网络节点的状态。

标志说明:

U Up表示此路由当前正在启动

H Host,表示此网关是主机

表示此网关是路由器的G Gateway

R Reinstate Route,使用动态路由重新初始化的路由

D Dynamically,该路由动态写入

M Modified,该路由由根守护进程或读取器动态更改

! 表示这条路线是正当的

前为关闭状态

备注:

route -n (-n 表示不解析名字,列出速度会比route 快)

实例2:添加网关/设置网关

命令:

route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

输出:

[root@localhost ~]# route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0[root@localhost ~]# routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.120.0 * 255.255.255.0 U 0 0 0 eth0192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth010.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0224.0.0.0 * 240.0.0.0 U 0 0 0 eth0default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0

[root@localhost ~]#

说明:

增加一条 到达244.0.0.0的路由

实例3:屏蔽一条路由

命令:

route add -net 224.0.0.0 netmask 240.0.0.0 reject

输出:

[root@localhost ~]# route add -net 224.0.0.0 netmask 240.0.0.0 reject[root@localhost ~]# routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.120.0 * 255.255.255.0 U 0 0 0 eth0192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth010.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0224.0.0.0 - 240.0.0.0 ! 0 - 0 -224.0.0.0 * 240.0.0.0 U 0 0 0 eth0default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0

说明:

增加一条屏蔽的路由,目的地址为 224.x.x.x 将被拒绝

实例4:删除路由记录

命令:

route del -net 224.0.0.0 netmask 240.0.0.0

route del -net 224.0.0.0 netmask 240.0.0.0 reject

输出:

[root@localhost ~]# routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.120.0 * 255.255.255.0 U 0 0 0 eth0192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth010.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0224.0.0.0 - 240.0.0.0 ! 0 - 0 -224.0.0.0 * 240.0.0.0 U 0 0 0 eth0default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0[root@localhost ~]# route del -net 224.0.0.0 netmask 240.0.0.0[root@localhost ~]# routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.120.0 * 255.255.255.0 U 0 0 0 eth0192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth010.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0224.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 -net 224.0.0.0 netmask 240.0.0.0 reject[root@localhost ~]# routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.120.0 * 255.255.255.0 U 0 0 0 eth0192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth010.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0default 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 ~]# routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.120.0 * 255.255.255.0 U 0 0 0 eth0192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth010.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 ~]# routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.120.0 * 255.255.255.0 U 0 0 0 eth0192.168.0.0 192.168.120.1 255.255.0.0 UG 0 0 0 eth010.0.0.0 192.168.120.1 255.0.0.0 UG 0 0 0 eth0default 192.168.120.240 0.0.0.0 UG 0 0 0 eth0[root@localhost ~]#

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。