极路由添加静态路由表

In some specific types of environments, you might find it useful to add a static route to the routing table in Windows. Here’s how to go about it.

在某些特定类型的环境中,您可能会发现将静态路由添加到Windows中的路由表很有用。 这是解决方法。

A routing table dictates where all packets go when they leave a system—whether that system is a physical router or a PC. Most routers—including the one built into your Windows PC—use some form of dynamic routing, where the router is capable of selecting the best place to forward packets based on information it gets from other routers. You can see it at work if you use the traceroute command to watch the connections a packet makes as it reaches it’s final destination.

路由表规定了所有数据包离开系统后的去向,无论该系统是物理路由器还是PC。 大多数路由器(包括Windows PC内置的路由器)都使用某种形式的动态路由,其中​​路由器能够根据从其他路由器获得的信息来选择最佳的位置来转发数据包。 如果使用traceroute命令监视数据包到达最终目的地时建立的连接,则可以在工作中看到它。

Most routers also allow you to add a static route (one that doesn’t get dynamically updated) if you want to always forward certain traffic to a specific router or gateway. Why? Well, most people using Windows in their home or small business probably won’t—but this can be useful under certain circumstances, such as:

如果您想始终将某些流量转发到特定的路由器或网关,大多数路由器还允许您添加静态路由(不会动态更新的路由)。 为什么? 好吧,大多数人可能不会在家庭或小型企业中使用Windows,但这在某些情况下可能很有用,例如:

  • You have two internet connections—maybe one for regular use and one for connecting to a work network—and you want all traffic to a certain IP address range to go out over one of those connections.您有两个Internet连接(也许一个用于常规用途,一个用于连接到工作网络),并且您希望到某个IP地址范围的所有流量都通过这些连接之一流出。
  • You have set up multiple subnets on your network and need to direct traffic to a particular subnet. Static routes can be particular useful in testing these types of environments.您已经在网络上设置了多个子网,并且需要将流量定向到特定的子网。 静态路由对于测试这些类型的环境特别有用。
  • You’re actually using a Windows PC as a router for your network and you want finer control over it.您实际上是将Windows PC用作网络的路由器,并且希望对其进行更好的控制。

If any of those apply to you, read on. You’ll need to dive into the Command Prompt to add a static route to the Windows routing table, but it’s easy and we’ll walk you through the steps.

如果有任何适合您的内容,请继续阅读。 您需要深入研究命令提示符以将静态路由添加到Windows路由表,但这很简单,我们将逐步指导您。

查看Windows路由表 (View the Windows Routing Table)

Before you get started adding routes, it may be helpful to view the routing table first. Fire up Command Prompt by hitting Windows+X and then selecting “Command Prompt (Admin)” on the Power Users menu.

在开始添加路由之前,先查看路由表可能会有所帮助。 按下Windows + X,然后在“高级用户”菜单上选择“命令提示符(Admin)”,以启动命令提示符。

Note: If you see PowerShell instead of Command Prompt on the Power Users menu, that’s a switch that came about with the Creators Update for Windows 10. It’s very easy to switch back to showing the Command Prompt on the Power Users menu if you want, or you can give PowerShell a try. You can do pretty much everything in PowerShell that you can do in Command Prompt, plus a lot of other useful things.

注意 :如果您在Power Users菜单上看到PowerShell而不是Command Prompt,那是Windows 10的Creators Update附带的开关。 如果需要,可以很容易地切换回在“高级用户”菜单上显示命令提示符 ,或者可以尝试使用PowerShell。 您可以在PowerShell中完成几乎可以在命令提示符中执行的所有操作,以及许多其他有用的操作。

At the Command Prompt, type the following command and hit Enter:

在命令提示符处,键入以下命令,然后按Enter键:

route print

You’ll see a long list of network destinations and the gateways to which packets are forwarded when they are headed to that destination. Unless you’ve already added static routes to the table, everything you see here will be dynamically generated.

您会看到一长串的网络目标,以及将数据包发送到该目标时将其转发到的网关。 除非您已经向表中添加了静态路由,否则您在此处看到的所有内容都会动态生成。

将静态路由添加到Windows路由表 (Add a Static Route to the Windows Routing Table)

To add a static route to the table, you’ll type a command using the following syntax:

要将静态路由添加到表,您将使用以下语法键入命令:

route ADD destination_network MASK subnet_mask  gateway_ip metric_cost

The subnet_mask and metric_cost components are optional to the command. If you don’t specify a subnet mask, 255.255.255.0 will be used automatically. If you don’t specify a metric cost, a cost one greater than the 0.0.0.0 destination entry will be used. The metric cost value is just a cost that is relative to other costs in the table and is used when Windows decides between multiple routes that could reach the same destination.

subnet_maskmetric_cost组件对于命令是可选的。 如果您未指定子网掩码,则会自动使用255.255.255.0。 如果未指定度量标准成本,则将使用比目标条目0.0.0.0大一个的成本。 度量成本值只是相对于表中其他成本的成本,当Windows在可能到达同一目的地的多个路由之间做出决定时使用该度量值。

So, for example, if you wanted to add a route specifying that all traffic bound for the 192.168.35.0 subnet went to a gateway at 192.168.0.2 and you just wanted to use the automatic metric cost, you would use the following command:

因此,例如,如果您想添加一条路由,以指定绑定到192.168.35.0子网的所有流量都流向了192.168.0.2的网关,而您只想使用自动度量成本,则可以使用以下命令:

route ADD 192.168.35.0 MASK 255.255.255.0 192.168.0.2

If you were to use the route print command to look at the table now, you’d see your new static route.

如果现在要使用route print命令查看该表,则会看到新的静态路由。

That’s all easy enough, but there is one extra little catch. When you add a static route, by default it only lasts until the next time you start Windows. The reason for this is that many companies use a coordinated list of static routes that gets updated fairly often. Rather than adding and updating all those routes on every machine, they just distribute a batch script file that adds the newest routes during Windows startup. This keeps the routing table relatively uncluttered.

这很容易,但是还有一点不足。 添加静态路由时,默认情况下,它仅持续到下次启动Windows时为止。 原因是许多公司使用协调的静态路由列表,该列表经常更新。 他们只是分发一个批处理脚本文件,而不是在每台计算机上添加和更新所有这些路由,而是在Windows启动期间添加最新的路由。 这使路由表相对整洁。

You could certainly use the batch script method yourself. Writing batch scripts isn’t hard. But if you’re just adding one or two static routes that you don’t expect to change often, you can instead just add the -p option to the command to make the route persistent. A persistent route stays in place even when Windows starts up. Using the same command we used earlier, you could make that route persistent with the following modification:

您当然可以自己使用批处理脚本方法。 编写批处理脚本并不难。 但是,如果您只是添加一条或两条不希望经常更改的静态路由,则可以在命令中添加-p选项以使该路由持久化。 即使Windows启动,持久的路由也会保留在原位。 使用我们之前使用的相同命令,可以通过以下修改使该路由持久化:

route -p ADD 192.168.35.0 MASK 255.255.255.0 192.168.0.2

从Windows路由表中删除静态路由 (Remove a Static Route from the Windows Routing Table)

Of course, there will come a time you might want to remove a static route from your table. All you have to do is type a command using the following syntax:

当然,有时候您可能想从表中删除静态路由。 您所要做的就是使用以下语法键入命令:

route delete destination_network

So, to delete the route we created earlier with the destination network 192.168.35.0, all we’d have to do is type this command and hit Enter:

因此,要删除我们之前使用目标网络192.168.35.0创建的路由,我们要做的就是键入以下命令并按Enter:

route delete 192.168.35.0


Yes, using static routes is a bit esoteric when it comes to managing most home and small business networks. But if you do need to do it, it’s a pretty easy process. And if you don’t need to do it right now, at least you know it’s an option in the future.

是的,在管理大多数家庭和小型企业网络时,使用静态路由有些深奥。 但是,如果您确实需要这样做,这是一个非常简单的过程。 而且,如果您现在不需要这样做,至少您知道将来它是一个选择。

翻译自: https://www.howtogeek.com/howto/windows/adding-a-tcpip-route-to-the-windows-routing-table/

极路由添加静态路由表

极路由添加静态路由表_如何将静态TCP / IP路由添加到Windows路由表相关推荐

  1. 《TCP/IP路由技术(第二卷)》一1.2 EGP的操作

    本节书摘来自异步社区<TCP/IP路由技术(第二卷)>一书中的第1章,第1.2节,作者[美]Jeff Doyle,CCIE #1919 , Jennifer DeHaven Carroll ...

  2. 《TCP/IP路由技术(第二卷)》一1.6 附 注

    本节书摘来自异步社区<TCP/IP路由技术(第二卷)>一书中的第1章,第1.6节,作者[美]Jeff Doyle,CCIE #1919 , Jennifer DeHaven Carroll ...

  3. node.js 静态属性_如何使用静态站点和Node.js开发和部署第一个全栈式Web应用程序

    node.js 静态属性 This tutorial will show you how to convert a static website that uses HTML, CSS and Jav ...

  4. snmp是什么层协议_计算机网络基础:TCP/IP协议相关知识笔记?

    1.TCP/IP特性 逻辑编址:每一块网卡会在出厂时由厂家分配了唯一的永久性物理地址.针对Internet,会为每台连入因特网的计算机分配一个逻辑地址也就是IP地址. 路由选择:专门用于定义路由器如何 ...

  5. Linux命令:netstat【监控TCP/IP网络,可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息】【TCP的11种状态】

    netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实际的网络连接以及每一个网络接口设备的状态信息. netstat [选项] 选项 描述 -a 显示所有网络连接和监听的所 ...

  6. aws s3 静态网站_如何将静态网站或JAMstack应用托管并部署到AWS S3和CloudFront

    aws s3 静态网站 S3 and CloudFront are AWS cloud services that make serving static assets powerful and ch ...

  7. java jsp取静态常量_获取java静态

    Android NDK开发系列教程4:对类变量进行操作 终于建了一个自己个人小站:https://huangtianyu.gitee.io,以后优先更新小站博客,欢迎进站,O(∩_∩)O~~ 通常我们 ...

  8. python中字典添加键对_关于python:如何向字典添加键、值对?

    本问题已经有最佳答案,请猛点这里访问. 如何在字典中添加键.值对?.下面我提到了以下格式? {'1_somemessage': [[3L, 1L, u'AAA', 1689544L, datetime ...

  9. python中怎么把值添加进列表_在Python中为子列表添加值

    有时我们需要为现有列表引入附加值.在本文中,我们将看到如何通过与现有列表的每个项目组合将一个或多个新值插入到现有列表中. 使用For循环 如果我们获取的列表具有相同长度的项目,则可以使用此方法在列表的 ...

最新文章

  1. 「模型解读」深度学习网络只能有一个输入吗
  2. mysql主从复制简单配置
  3. 迪桑特案例拆解:社群运营如何在高端运动服装品牌中发挥价值?
  4. 最强悍的VS插件—reSharper
  5. 【转】1.9 Asp.Net Core 轻松学-多线程之取消令牌(
  6. Linux设置串口永久权限
  7. 大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
  8. bigdicmal除法精度设置_java中BigDecimal进行加减乘除的基本用法
  9. redis 多进程_Redis 持久化
  10. bootdo增加验证码登陆
  11. Neo4j【有与无】【N6】Graph数据库内部
  12. 2022中兴捧月图像去噪赛道结果小结
  13. B站收藏夹快速导出详细步骤
  14. vue html 原始 模板,vue初始化模板套用
  15. 密钥mysql_MySQL加密和密钥管理
  16. Oracle 取余函数
  17. 待得天晴花已老,不如携手雨中看
  18. 解决java 图片压缩图片图片变色问题
  19. Hbase shell过滤操作
  20. Speedoffice(excel)如何利用SUMPRODUCT函数求和

热门文章

  1. 11月29日做题截图
  2. 谷歌浏览器崩溃设置崩溃_用浏览器崩溃
  3. Java编程之图形化设计求任意输入数的阶乘
  4. 一次微信公众号分享功能总结
  5. vue:移动端使用ckplayer
  6. 基于Unity3D的调用摄像头功能的实现
  7. android 手机短信恢复,Android短信如何恢复
  8. java在微信朋友圈中植入广告_微信朋友圈广告植入怎么做
  9. Kubernetes集群部署之二CA证书制作
  10. 跳一跳辅助源码学习(主流分辨率全适配)