This commit is contained in:
fofolee
2019-04-08 23:22:26 +08:00
commit 7ca94f1141
5960 changed files with 530244 additions and 0 deletions

65
docs/linux/route.html Normal file
View File

@@ -0,0 +1,65 @@
<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>route(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code>-A设置地址类型
-C打印将Linux核心的路由缓存
-v详细信息模式
-n不执行DNS反向查找直接显示数字形式的IP地址
-enetstat格式显示路由表
-net到一个网络的路由表
-host到一个主机的路由表。</code></pre>
<h3 id="参数">参数</h3>
<pre><code>Add增加指定的路由记录
Del删除指定的路由记录
Target目的网络或目的主机
gw设置默认网关
mss设置TCP的最大区块长度MSS单位MB
window指定通过路由表的TCP连接的TCP窗口大小
dev路由记录所表示的网络接口。</code></pre>
<h3 id="实例">实例</h3>
<p><strong>显示当前路由:</strong></p>
<pre><code>[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>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>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>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>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/ -->