每天一个linux命令(53):route命令

资讯 2024-06-22 阅读:48 评论:0
Linux系统的route命令用于显示和操作IP路由表(show?/?manipulate?the?IP?routing?table)。要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或者同时位于两个网络的网关来实现。在Lin...
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

Linux系统的route命令用于显示和操作IP路由表(show?/?manipulate?the?IP?routing?table)。要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或者同时位于两个网络的网关来实现。在Linux系统中,设置路由通常是为了解决以下问题:该Linux系统在一个局域网中,局域网中有一个网关,能够让机器访问Internet,那么就需要将这台机器的IP地址设置为Linux机器的默认路由。要注意的是,直接在命令行下执行route命令来添加路由,不会永久保存,当网卡重启或者机器重启之后,该路由就失效了;可以在/etc/rc.local中添加route命令来保证该路由设置永久有效。

In Linux, the route is usually set to solve the following problems: the Linux system has a gateway in a local area network that allows the machine to access the Internet, and the IP address of the machine needs to be set as the default route for the Linux machine. It is important to note that it is executed directly under the command line to add a route, which will not be permanently preserved, when the netcard is re-opened or the machine is restarted; it is possible to add a root command in/etc/rc.local to ensure that the route is permanently effective.

1.命令格式:

1. Command format:

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

2.命令功能:

2. Command function:

Route命令是用于操作基于内核ip路由表,它的主要作用是创建一个静态路由让指定一个主机或者一个网络通过一个网络接口,如eth0。当使用"add"或者"del"参数时,路由表被修改,如果没有参数,则显示路由表当前的内容。

The Route command is used to operate a kernel-based ip route table, the main function of which is to create a static router to specify a host or network through a network interface, e.g. eth0. When using 34; add& #34; or #34; del #34; the parameter, the route chart is modified or, if there are no parameters, the current content of the route chart is shown.

3.命令参数:

3. Command parameters:

-c?显示更多信息

-C-c? Show me more information.

-n?不解析名字

Don't parse names.

-v?显示详细的处理信息

Show me the details of the process.

-F?显示发送信息

-F? Show the sender.

-C?显示路由缓存

-C? Show route caches.

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

-F? Clear the route sheets for all gateway entrances?

-p?与?add?命令一起使用时使路由具有永久性。

-P-p? To make the route permanent when used with an order?

?

add:添加一条新路由。

Add a new route.

del:删除一条路由。

del: Delete a route.

-net:目标地址是一个网络。

-net: The target address is a network.

-host:目标地址是一个主机。

Target address is a host.

netmask:当添加一个网络路由时,需要使用网络掩码。

netmask: When a network route is added, a network mask is required.

gw:路由数据包通过网关。注意,你指定的网关必须能够达到。

gw: Passes through the gateway through the data pack. Note that the gateway you specify must be accessible.

metric:设置路由跳数。

Metric: Set the number of route jumps.


Command?指定您想运行的命令?(Add/Change/Delete/Print)。?

Command? Specifies the command you want to run? (Add/Change/Delete/Print).

Destination?指定该路由的网络目标。?

Destination? A network target for the route?

mask?Netmask?指定与网络目标相关的网络掩码(也被称作子网掩码)。?

Mask?Netmask? Specifies a network mask (also known as a subnet mask) associated with a network target?

Gateway?指定网络目标定义的地址集和子网掩码可以到达的前进或下一跃点?IP?地址。?

Gateway? Specify the address set and subnet mask that you can get to, or the next jump point? IP? address?

metric?Metric?为路由指定一个整数成本值标(从?1?至?9999),当在路由表(与转发的数据包目标地址最匹配)的多个路由中进行选择时可以使用。?

Metric? Specifies an integer cost marker for routers (from?1? to?9999), which can be used when selecting multiple routes in the route sheets (the most appropriate match to the transmitted data package target address).

if?Interface?为可以访问目标的接口指定接口索引。若要获得一个接口列表和它们相应的接口索引,使用?route?print?命令的显示功能。可以使用十进制或十六进制值进行接口索引。

If? Interface? Specifies the interface index for the interface that allows access to the target. To get a list of interfaces and their corresponding interface indexes, use the display function of the?route?print? command. You can index the interface using decimal or hexadecimal values.


4.使用实例:

4. Examples of use:

实例1:显示当前路由

Example 1: Show current route

命令:

Command:

route

route?-n

输出:

Output:


复制代码

[root@localhost?~]#?route
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?*?255.255.255.0?U?000?eth0
e192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
default?192.168.120.240?0.0.0.0?UG000?eth0
[root@localhost?~]#?route?-n
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?0.0.0.0?255.255.255.0?U?000?eth0
192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
0.0.0.0?192.168.120.240?0.0.0.0?UG000?eth0

复制代码

?

说明:

Note:

第一行表示主机所在网络的地址为192.168.120.0,若数据传送目标是在本局域网内通信,则可直接通过eth0转发数据包;

The first line indicates the address of the host network at 192.168.120.0, which can be transmitted directly through eth0 if the data transfer target is to communicate within the local area network;

第四行表示数据传送目的是访问Internet,则由接口eth0,将数据包发送到网关192.168.120.240

Line 4 indicates that the data transfer is to access the Internet, and the data package is sent to the gateway 192.168.120.240 by interface eth0

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

Of these, Flags is a route sign that marks the state of the current network node.

Flags标志说明:

The Flags logo explains:

U?Up表示此路由当前为启动状态

U?Up indicates that this path is currently starting state

H?Host,表示此网关为一主机

H? Host, indicate that this gateway is a host.

G?Gateway,表示此网关为一路由器

G? Gateway, indicate that this gateway is a router.

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

R?Reinstate? Route, use a dynamic route to re-initiate.

D?Dynamically,此路由是动态性地写入

D? Dynamically, this route is dynamically written.

M?Modified,此路由是由路由守护程序或导向器动态修改

M?Modified, this route is modified by routed daemon or guidanceer dynamics

!?表示此路由当前为关闭状态

%1 indicates that this path is currently closed


备注:

Remarks:

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

(-n? If you don't parse a name, it's faster than roote?)


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

Example 2: Add a gateway/set a gateway

命令:

Command:

route?add?-net?224.0.0.0?netmask?240.0.0.0?dev?eth0

输出:

Output:

复制代码

[root@localhost?~]#?route?add?-net?224.0.0.0?netmask?240.0.0.0?dev?eth0
[root@localhost?~]#?route
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?*?255.255.255.0?U?000?eth0
192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
224.0.0.0?*?240.0.0.0?U?000?eth0
default?192.168.120.240?0.0.0.0?UG000?eth0

复制代码

[root@localhost?~]#

说明:

Note:

增加一条?到达244.0.0.0的路由

Add a route to 244.0.0.


实例3:屏蔽一条路由

Example 3: Blocking a route

命令:

Command:

route?add?-net?224.0.0.0?netmask?240.0.0.0?reject

输出:

Output:


复制代码

[root@localhost?~]#?route?add?-net?224.0.0.0?netmask?240.0.0.0?reject
[root@localhost?~]#?route
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?*?255.255.255.0?U?000?eth0
192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
224.0.0.0?-?240.0.0.0?!?0-0?-
224.0.0.0?*?240.0.0.0?U?000?eth0
default?192.168.120.240?0.0.0.0?UG000?eth0

复制代码

?

说明:

Note:

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

Add a blocked route to the address? 224.x.x.x?


实例4:删除路由记录

Example 4: Delete route records

命令:

Command:

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

输出:

Output:


复制代码

[root@localhost?~]#?route
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?*?255.255.255.0?U?000?eth0
192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
224.0.0.0?-?240.0.0.0?!?0-0?-
224.0.0.0?*?240.0.0.0?U?000?eth0
default?192.168.120.240?0.0.0.0?UG000?eth0
[root@localhost?~]#?route?del?-net?224.0.0.0?netmask?240.0.0.0
[root@localhost?~]#?route
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?*?255.255.255.0?U?000?eth0
192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
224.0.0.0?-?240.0.0.0?!?0-0?-
default?192.168.120.240?0.0.0.0?UG000?eth0
[root@localhost?~]#?route?del?-net?224.0.0.0?netmask?240.0.0.0?reject
[root@localhost?~]#?route
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?*?255.255.255.0?U?000?eth0
192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
default?192.168.120.240?0.0.0.0?UG000?eth0
[root@localhost?~]#?

复制代码

?

说明:

Note:


实例5:删除和添加设置默认网关

Example 5: Delete and add default gateways

命令:

Command:

route?del?default?gw?192.168.120.240

route?add?default?gw?192.168.120.240

输出:

Output:


复制代码

[root@localhost?~]#?route?del?default?gw?192.168.120.240
[root@localhost?~]#?route
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?*?255.255.255.0?U?000?eth0
192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
[root@localhost?~]#?route?add?default?gw?192.168.120.240
[root@localhost?~]#?route
Kernel?IP?routing?table
Destination?Gateway?Genmask?Flags?Metric?RefUse?Iface
192.168.120.0?*?255.255.255.0?U?000?eth0
192.168.0.0?192.168.120.1?255.255.0.0?UG000?eth0
10.0.0.0192.168.120.1?255.0.0.0?UG000?eth0
default?192.168.120.240?0.0.0.0?UG000?eth0
[root@localhost?~]#?


美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
热门文章
  • DDO在新加坡上市真假,欧意交易所能交易数字期权吗?

    DDO在新加坡上市真假,欧意交易所能交易数字期权吗?
    然而,对于DDO在新加坡的列名是否真实存在争议。 据报道,有人质疑DDO的数字选项是否真的上市,其背景是否经过了彻底调查。 首先,有报告说,DDO数字选项清单仅仅是一种宣传手段,没有找到DDO交易的平台,这就对DDO的真正清单提出了疑问。 其次,一些媒体调查了DDO数字选项的背景。 报告显示DDO数字选项发行人声称其数字选项是国家赞助的,但实际上,根据中国人民银行,虚拟货币相关业务是非法金融活动。 此外,DDO数字选项在视频号码等平台上广为传播,吸引了许多信徒的注意,然...
  • Griffin Gaming Partners计划为其第三支基金筹集5亿美元

    Griffin Gaming Partners计划为其第三支基金筹集5亿美元
    Pitchbook引用的6月8日《快链头条新闻》作为监管文件, 指出游戏风险投资公司Griffin赌博伙伴计划为其第三个旗舰基金筹集5亿美元, 比第二个基金少33%。 2021年,格里芬赌博伙伴从Web3游戏开发者Forte获得A回合资金1.85亿美元,并于2022年筹集了第二个旗舰基金,金额达7.5亿美元,此时风险资本家对Web3和加密游戏的热情达到顶峰。...
  • 加密货币之王重回王位:比特币飙升至 71,000 美元,还能再涨多少?

    加密货币之王重回王位:比特币飙升至 71,000 美元,还能再涨多少?
    比特币是市场上最大的加密货币,它再次打破了重要的7万美元门槛。 在短短的四舍五入(67,000美元到69,000美元之间)之后,价格在这一水平上遇到了强烈的抵制。 然而,势头的不断增强表明,比特币可能形成一个超过70 000美元的板块,为重新测试下一个抵抗阵地71 300美元和3月份可能攀升到历史最高点73 700美元铺平了道路。 问题仍然是:比特币能否维持预期的上升趋势并继续大幅上升?    分析家预计比特币价格将上升到74,400美元。 加密货币分析师Ali M...
  • 比过山车还狠!比特币价格再次暴跌

    比过山车还狠!比特币价格再次暴跌
      上周日,比特币的价格创造了3000美元的历史新高,随后就开始各种高台跳水了。Last Sunday, the price of Bitcoin created a record high of $3,000, and then began to dive on all the high platforms.   据外媒报道,本周一,比特币价格一度下跌到2526.4美元,最高跌幅高达14.5%,这创造了2015年1月以来最大跌幅。According to external...
  • 几张图看懂区块链技术到底是什么?https://www.cnblogs.com/behindman/p/8873191.html

    几张图看懂区块链技术到底是什么?https://www.cnblogs.com/behindman/p/8873191.html
    “区块链”的概念可以说是异常火爆,好像互联网金融峰会上没人谈一谈区块链技术就out了,BAT以及各大银行还有什么金融机构都在开始自己的区块链研究工作,就连IBM最近也成立了自己的区块链研究实验室,但其实区块链到底是什么?大家或许并不清楚,停留在雾里看花的状态。从今天开始,就让我们一起走进区块链,揭开区块链的神秘面纱吧!The concept of a block chain can be described as an unusually hot one, as if no...
标签列表