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

资讯 2024-06-22 阅读:109 评论: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

  官网
热门文章
  • usdt钱包开发,比特币协议 Omni 层协议 USDT

    usdt钱包开发,比特币协议 Omni 层协议 USDT
    usdt钱包开发Usdt Wallet Development 比特币协议 -> Omni 层协议 -> USDTBitcoin -> Omni Layer -> USDT USDT是基于比特币omni协议的一种代币: https://omniexplorer.info/asset/31 ID是31USDT is a token based on the Bitcomni agreement:   ˂a href="ht...
  • ?基于区块链的数字货币,下一代货币等价物

    ?基于区块链的数字货币,下一代货币等价物
    文 | 诗与星空Psalms and stars. 10月25日晚间,一则关于区块链的消息引爆了市场,虽然A股已经关门歇业,但是大洋彼岸的美股却喧嚣起来,号称使用了区块链技术的迅雷股价暴涨107%。On the evening of 25 October, a news about the block chain detonated the market. Although the A share was closed, the United States shares...
  • LikeCoin 2022 年度回顧

    LikeCoin 2022 年度回顧
    2022 即將過去,今年是風高浪急的一年,LikeCoin 社群繼續於驚濤中為實踐分散式出版而前進,感謝各位的同行。讓我們趁機回顧一下今年發生過的大小事。 2022 Towards the end of the year, this year is a year of great turmoil, and the community of ˂a href=https://like.co/"target="_blank" data-type="link" data-i...
  • 一个“币”卖出6930多万美元,它是何来头

    一个“币”卖出6930多万美元,它是何来头
    这是一个新的投机性市场,有许多未知的风险——包括100%损失的风险於兴中当我们看到有人花了近百万美元在网络上的虚拟空间里买了一块地,可能会觉得不可思议。但是,比这更不可思议的是,在上个月的佳士得拍卖会上,一个不可替换代币(NFT)卖出了令人瞠目结舌的6930多万美元。这个代币所代表的便是目前人们热议的数字艺术家毕朋(Beeple)的作品《日复一日:最初的5000天(2021)》。不仅如此,不可替换代币市场正在被大张旗鼓地建构。篮球视频集锦的不可替换代币在美国职业...
  • 以太坊质押挖矿收益率

    以太坊质押挖矿收益率
    展开全部 52%左右。根据跟踪公司StakingRewards的数据,质押的以太坊将产生回报,预计在合并后将达到52%左右。再加上预计在升级更新后不久以太坊供应量的净减少,这应该会使该币对投资者更具吸引力。According to the tracking company StakingRewards, the pledge will yield returns that are expected to reach about 52% after the merg...
标签列表