mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-08 15:04:05 +08:00
66 lines
4.6 KiB
HTML
66 lines
4.6 KiB
HTML
<h1 id="route">route</h1>
|
||
<p>显示并设置Linux中静态路由表</p>
|
||
<h2 id="补充说明">补充说明</h2>
|
||
<p><strong>route命令</strong> 用来显示并设置Linux内核中的网络路由表,route命令设置的路由主要是静态路由。要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或者同时位于两个网络的网关来实现。</p>
|
||
<p>在Linux系统中设置路由通常是为了解决以下问题:该Linux系统在一个局域网中,局域网中有一个网关,能够让机器访问Internet,那么就需要将这台机器的ip地址设置为Linux机器的默认路由。要注意的是,直接在命令行下执行route命令来添加路由,不会永久保存,当网卡重启或者机器重启之后,该路由就失效了;可以在<code>/etc/rc.local</code>中添加route命令来保证该路由设置永久有效。</p>
|
||
<h3 id="语法">语法</h3>
|
||
<pre><code class="language-bash">route(选项)(参数)</code></pre>
|
||
<h3 id="选项">选项</h3>
|
||
<pre><code class="language-bash">-A:设置地址类型;
|
||
-C:打印将Linux核心的路由缓存;
|
||
-v:详细信息模式;
|
||
-n:不执行DNS反向查找,直接显示数字形式的IP地址;
|
||
-e:netstat格式显示路由表;
|
||
-net:到一个网络的路由表;
|
||
-host:到一个主机的路由表。</code></pre>
|
||
<h3 id="参数">参数</h3>
|
||
<pre><code class="language-bash">Add:增加指定的路由记录;
|
||
Del:删除指定的路由记录;
|
||
Target:目的网络或目的主机;
|
||
gw:设置默认网关;
|
||
mss:设置TCP的最大区块长度(MSS),单位MB;
|
||
window:指定通过路由表的TCP连接的TCP窗口大小;
|
||
dev:路由记录所表示的网络接口。</code></pre>
|
||
<h3 id="实例">实例</h3>
|
||
<p><strong>显示当前路由:</strong></p>
|
||
<pre><code class="language-bash">[root@localhost ~]# route
|
||
Kernel IP routing table
|
||
Destination Gateway Genmask Flags Metric Ref Use Iface
|
||
112.124.12.0 * 255.255.252.0 U 0 0 0 eth1
|
||
10.160.0.0 * 255.255.240.0 U 0 0 0 eth0
|
||
192.168.0.0 10.160.15.247 255.255.0.0 UG 0 0 0 eth0
|
||
172.16.0.0 10.160.15.247 255.240.0.0 UG 0 0 0 eth0
|
||
10.0.0.0 10.160.15.247 255.0.0.0 UG 0 0 0 eth0
|
||
default 112.124.15.247 0.0.0.0 UG 0 0 0 eth1
|
||
|
||
[root@localhost ~]# route -n
|
||
Kernel IP routing table
|
||
Destination Gateway Genmask Flags Metric Ref Use Iface
|
||
112.124.12.0 0.0.0.0 255.255.252.0 U 0 0 0 eth1
|
||
10.160.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
|
||
192.168.0.0 10.160.15.247 255.255.0.0 UG 0 0 0 eth0
|
||
172.16.0.0 10.160.15.247 255.240.0.0 UG 0 0 0 eth0
|
||
10.0.0.0 10.160.15.247 255.0.0.0 UG 0 0 0 eth0
|
||
0.0.0.0 112.124.15.247 0.0.0.0 UG 0 0 0 eth1</code></pre>
|
||
<p>其中Flags为路由标志,标记当前网络节点的状态,Flags标志说明:</p>
|
||
<ul>
|
||
<li>U Up表示此路由当前为启动状态。</li>
|
||
<li>H Host,表示此网关为一主机。</li>
|
||
<li>G Gateway,表示此网关为一路由器。</li>
|
||
<li>R Reinstate Route,使用动态路由重新初始化的路由。</li>
|
||
<li>D Dynamically,此路由是动态性地写入。</li>
|
||
<li>M Modified,此路由是由路由守护程序或导向器动态修改。</li>
|
||
<li>! 表示此路由当前为关闭状态。</li>
|
||
</ul>
|
||
<p><strong>添加网关/设置网关:</strong></p>
|
||
<pre><code class="language-bash">route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 #增加一条到达244.0.0.0的路由。</code></pre>
|
||
<p><strong>屏蔽一条路由:</strong></p>
|
||
<pre><code class="language-bash">route add -net 224.0.0.0 netmask 240.0.0.0 reject #增加一条屏蔽的路由,目的地址为224.x.x.x将被拒绝。</code></pre>
|
||
<p><strong>删除路由记录:</strong></p>
|
||
<pre><code class="language-bash">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</code></pre>
|
||
<p><strong>删除和添加设置默认网关:</strong></p>
|
||
<pre><code class="language-bash">route del default gw 192.168.120.240
|
||
route add default gw 192.168.120.240</code></pre>
|
||
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->
|