linux网络运维命令--route

良许Linux

共 3549字,需浏览 8分钟

 ·

2024-07-25 07:33

          

链接:https://www.cnblogs.com/du-z/p/16332641.html

简介

  1. route - show / manipulate the IP routing table

  2. Route操作内核的IP路由表。它的主要用途是在使用ifconfig(8)程序配置后,通过接口建立到特定主机或网络的静态路由。

  3. 当使用add或del选项时,route会修改路由表。如果没有这些选项,route将显示路由表的当前内容。

  4. 要注意的是,直接在命令行下执行route命令来添加路由,不会永久保存,当网卡重启或者机器重启之后,该路由就失效了;可以在/etc/rc.local中添加route命令来保证该路由设置永久有效。

下载安装

yum install net-tools

使用用法

route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]

-c 显示更多信息
-n 不解析名字
-v 显示详细的处理信息
-F 显示发送信息
-C 显示路由缓存
-f 清除所有网关入口的路由表。
-p 与 add 命令一起使用时使路由具有永久性

add : 添加一条新路由
del : 删除一条路由
-net : 目标地址是一个网络
-host : 目标地址是一个主机
netmask : 当添加一个网络路由时,需要使用网络掩码
gw : 路由数据包通过网关。注意,你指定的网关必须能够达到
metric : 设置路由跳数

输出

[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
10.10.10.0 - 255.255.255.0 ! 0 - 0 -
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33



输出说明:
内核路由表的输出按以下列组织

Destination : 目标网络或目标主机。
Gateway :网关地址或'*',如果没有设置。
Genmask :目的网络的子网掩码;'255.255.255.255'表示主机目的地址,'0.0.0.0'表示默认路由。
Flags :
U(路线向上)
H(目标为主机)
G(使用网关)
R(恢复动态路由路由)
D(通过守护进程或重定向动态安装)
M(来自路由守护进程或重定向)
A(通过addrconf安装)
C(缓存条目)
!(拒绝)

Metric :到目标的“距离”(通常以跳数计算)。最近的内核不使用它,但是路由守护进程可能需要它
Ref :此路由的引用数。(Linux内核中不使用。)
Use :对路由的查找计数。根据-F-C的使用,这将是路由缓存未命中(-F)或命中(-C)
Iface :该路由的报文将被发送到的接口

示例

查询路由

[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33

添加路由

[root@master ~]# route add -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
10.10.10.0 192.168.209.2 255.255.255.0 UG 0 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33

删除路由

[root@master ~]# route del -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33

添加阻断路由与删除

[root@master ~]# route add -net 10.10.10.0  netmask 255.255.255.0  reject
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
10.10.10.0 - 255.255.255.0 ! 0 - 0 -
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@master ~]# route del -net 10.10.10.0 netmask 255.255.255.0 reject
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33

   



招已经开始啦,大家如果不做好充足准备的话,招很难找到好工作。


送大家一份就业大礼包,大家可以突击一下春招,找个好工作!


浏览 72
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报