windows下route命令详解
windows下 route命令详解
在⼀个⽹上查到的,和Linux下的route很类似,但有部分不⼀样,汗死,开始以为是linux下的route.
使⽤ Route 命令⾏⼯具查看并编辑计算机的 IP 路由表。Route 命令和语法如下所⽰:route [-f] [-p] [Command][Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]-f 清除所有⽹关⼊⼝的路由表。如果该参数与某个命令组合使⽤,路由表将在运⾏命令前清除。 -p 与 add 命令⼀起使⽤时使路由具有永久性。该参数与 add 命令⼀起使⽤时,将使路由在系统引导程序之间持久存在。默认情况下,系统重新启动时不保留路由。与 print 命令⼀起使⽤时,显⽰已注册的持久路由列表。
忽略其他所有总是影响相应持久路由的命令。Command 指定您想运⾏的命令 (Add/Change/Delete/Print)。
路由类型:
有三种路由1.主机路由从⼀台主机映射⼀条到本地⽹络上的的其他主机上command format:route add -host destination_ip local_ip -interface interfaceeg:我们想为本地主机接⼝hme0(204.12.17.1)和另⼀台在相邻才C类⽹络上的主机(204.12.16.100)之间增加⼀条路由#route add -host 204.12.16.100
204.12.17.1 -interface hme02.⽹络路由允许数据包从本地主机传输到在本地⽹络的其他主机上增加⼀个到另⼀个⽹络的的直接路由command format:route add -net destination_network_ip local_ip -netmask maskeg:如果我们要想为C类⽹掩码在本地主机(204.12.17.1)和我们上⾯指出的⽹络之间增加⼀条路由(204.12.16.0⽹络)我们可以使⽤如下的命令:#route add -net 204.12.16.0 204.12.17.1 -netmask 255.255.255.03.缺省路由将寻⼀条路由的任务传送到⼀台路由器。RIP 和RDISC守护进程都可以使⽤缺省路由。command format:route add default hostname -interface interfaceeg:增加⼀条到本地路由器(204.54.56.1)的缺省路由,通常⽤在添加⽹关并马上⽣效#route add default 204.54.56.1 -interface hme1
Destination指定该路由的⽹络⽬标。
mask Netmask 指定与⽹络⽬标相关的⽹络掩码(也被称作⼦⽹掩码)。如果没有指定,将使⽤255.255.255.255
Gateway 指定⽹络⽬标定义的地址集和⼦⽹掩码可以到达的前进或下⼀跃点 IP 地址。
metric Metric 为路由指定⼀个整数成本值标(从 1 ⾄ 9999),当在路由表(与转发的数据包⽬标地址最匹配)的多个路由中进⾏选择时可以使⽤。
if Interface 为可以访问⽬标的接⼝指定接⼝索引。就是说发往甲的数据⽤接⼝A,发往⼄的⽤接⼝B。这⼀条在⼀个⽹卡捆绑了多个同⽹段的IP时应⽤⾮常有效。⽐如你捆绑了*.1 和*.2两个地址,你可以指定某⼀条主机路由是⽤*.1发,某⼀条是⽤*.2发。不然,默认情况下,发往同⼀⼦⽹的都是⽤⼀个IP 发。
若要获得⼀个接⼝列表和它们相应的接⼝索引,使⽤ route print 命令的显⽰功能。可以使⽤⼗进制或⼗六进制值进⾏接⼝索引。 /? 在命令提⽰符处显⽰帮助。
名为 Networks 的⽹络数据库⽂件和名为 Hosts 的计算机名数据库⽂件中均引⽤全部 destination 或 gateway 使⽤的符号名称。如果命令是 print 或 delete,⽬标和⽹关还可以使⽤通配符,也可以省略⽹关参数。⽰例若要显⽰ IP 路由表的全部内容,请键⼊:route print若要显⽰以 10. 起始的 IP 路由表中的路由,请键⼊:route print 10.*若要添加带有 192.168.12.1 默认⽹关地址的默认路由,请键⼊:route add 0.0.0.0 mask 0.0.0.0 192.168.12.1若要向带有 255.255.0.0 ⼦⽹掩码和 10.27.0.1 下⼀跃点地址的 10.41.0.0 ⽬标中添加⼀个路由,请键⼊:route add 10.41.0.0 mask 255.255.0.0 10.27.0.1若要向带有 255.255.0.0⼦⽹掩码和 10.27.0.1 下⼀跃点地址的 10.41.0.0 ⽬标中添加⼀个永久路由,请键⼊:route -p add 10.41.0.0 mask
255.255.0.0 10.27.0.1若要向带有 255.255.0.0 ⼦⽹掩码、10.27.0.1 下⼀跃点地址且其成本值标为 7
的 10.41.0.0 ⽬标中添加⼀个路由,请键⼊:route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 metric 7若要向带有 255.255.0.0 ⼦⽹掩码、10.27.0.1下⼀跃点地址且使⽤ 0x3 接⼝索引的 10.41.0.0 ⽬标中添加⼀个路由,请键⼊:route add 10.41.0.0 mask 255.255.0.0
10.27.0.1 if 0x3若要删除到带有 255.255.0.0 ⼦⽹掩码的 10.41.0.0 ⽬标的路由,请键⼊:route delete 10.41.0.0 mask 255.255.0.0若要删除以 10. 起始的 IP 路由表中的所有路由,请键⼊:route delete 10.*若要将带有 10.41.0.0 ⽬标和
255.255.0.0 ⼦⽹掩码的下⼀跃点地址从 10.27.0.1 修改为 10.27.0.25,请键⼊:route change 10.41.0.0 mask 255.255.0.0 10.27.0.25
原⽂内容:
www.microsoft/resources/documentation/windows/xp/all/proddocs/en-us/route.mspx?mfr=true
Route
Displays and modifies the entries in the local IP routing table. Used without parameters, route displays help.
Syntax
route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]
Top of page
Parameters
-f : Clears the routing table of all entries that are not host routes (routes with a netmask of
255.255.255.255), the loopback network route (routes with a destination of 127.0.0.0 and a netmask of 255.0.0.0), or a multicast route (routes with a destination of 224.0.0.0 and a netmask of 240.0.0.0). If this is used in conjunction with one of the commands (such as add, change, or delete), the table is cleared prior to running the command.
-p : When used with the add command, the specified route is added to the registry and is used to initialize the IP routing table whenever the TCP/IP protocol is started. By default, added routes are not preserved when the TCP/IP protocol is started. When used with the print command, the list of persistent routes is displayed. This parameter is ignored for all other commands. Persistent routes are stored in the registry location
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes. Command : Specifies the command you want to run. The following table lists valid commands. CommandPurpose
route add命令实例add Adds a route.
change Modifies an existing route.
delete Deletes a route or routes.
print Prints a route or routes.
Destination : Specifies the network destination of the route. The destination can be an IP network address (where the host bits of the network address are set to 0), an IP address for a host route, or 0.0.0.0 for the default route.
mask Netmask : Specifies the netmask (also known as a subnet mask) associated with the network destination. The subnet mask can be the appropriate subnet mask for an IP network address,
255.255.255.255 for a host route, or 0.0.0.0 for the default route. If omitted, the subnet mask
255.255.255.255 is used. Because of the relationship between the destination and the subnet mask in defining routes, the destination cannot be more specific than its corresponding subnet mask. In other words, there cannot be a bit set to 1 in the destination if the corresponding bit in the subnet mask is a 0.
Gateway : Specifies the forwarding or next hop IP address over which the set of addresses defined by the network destination and subnet mask are reachable. For locally attached subnet routes, the gateway address is the IP address assigned to the interface that is attached to the subnet. For remote routes, available across one or more routers, the gateway address is a directly reachable IP address that is assigned to a neighboring router.
metric Metric : Specifies an integer cost metric (ranging from 1 to 9999) for the route, which is used when choosing among multiple routes in the routing table that most closely match the destination address of a packet being forwarded. The route with the lowest metric is chosen. The metric can reflect the number of hops, the speed of the path, path reliability, path throughput, or administrative properties.
if Interface : Specifies the interface index for the interface over which the destination is reachable. Fo
r a list of interfaces and their corresponding interface indexes, use the display of the route print command. You can use either decimal or hexadecimal values for the interface index. For hexadecimal values, precede the hexadecimal number with 0x. When the if parameter is omitted, the interface is
determined from the gateway address.
/? : Displays help at the command prompt.
Top of page
Remarks
•Large values in the metric column of the routing table are the result of allowing TCP/IP to automatically determine the metric for routes in the routing table based on the configuration of IP address, subnet mask, and default gateway for each LAN interface. Automatic determination of the interface metric, enabled by default, determines the speed of each interface and adjusts the metrics of routes for each interface so that the fastest interface creates the routes with the lowest metric. To remove the large metrics, disable the automatic determination of the interface metric from the advanced properties of the TCP/IP protocol for each LAN connection.
•Names can be used for Destination if an appropriate entry exists in the local Networks file stored in the systemroot\System32\Drivers\Etc folder. Names can be used for the gateway as long as they can be resolved to an IP address through standard host name resolution techniques such as Domain Name System (DNS) queries, use of the local Hosts file stored in the systemroot\system32\drivers\etc folder, and NetBIOS name resolution.
•If the command is print or delete, the Gateway parameter can be omitted and wildcards can be used for the destination and gateway. The Destination value can be a wildcard value specified by an asterisk (*). If the destination specified contains an asterisk (*) or a question mark (?), it is treated as a wildcard and only matching destination routes are printed or deleted. The asterisk matches any string, and the question mark matches any single character. For example, 10.*.1, 192.168.*, 127.*, and *224* are all valid uses of the asterisk wildcard.
•Using an invalid combination of a destination and subnet mask (netmask) value displays a "Route: bad gateway address netmask" error message. This error message appears when the destination contains one or more bits set to 1 in bit locations where the corresponding subnet mask bit is set to 0. To test this condition, express the destination and subnet mask using binary notation. The subnet mask in binary notation consists of a series of 1 bits, representing the network address portion of the
destination, and a series of 0 bits, representing the host address portion of the destination. Check to determine whether there are bits in the destination that are set to 1 for the portion of the destination that is the host address (as defined by the subnet mask).
•The -p parameter is only supported on the route command for Windows NT 4.0, Windows 2000, Windows Millennium Edition, and Windows XP. This parameter is not supported by the route command for Windows 95 or Windows 98.
•This command is available only if the Internet Protocol (TCP/IP) protocol is installed as a component in the properties of a network adapter in Network Connections
Top of page
Examples
To display the entire contents of the IP routing table, type:
route print
To display the routes in the IP routing table that begin with 10., type:
route print 10.*
To add a default route with the default gateway address of 192.168.12.1, type:
route add 0.0.0.0 mask 0.0.0.0 192.168.12.1
To add a route to the destination 10.41.0.0 with the subnet mask of 255.255.0.0 and the next hop address of 10.27.0.1, type:
route add 10.41.0.0 mask 255.255.0.0 10.27.0.1
To add a persistent route to the destination 10.41.0.0 with the subnet mask of 255.255.0.0 and the next hop address of 10.27.0.1, type:
route -p add 10.41.0.0 mask 255.255.0.0 10.27.0.1
To add a route to the destination 10.41.0.0 with the subnet mask of 255.255.0.0, the next hop address of 10.27.0.1, and the cost metric of 7, type:
route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 metric 7
To add a route to the destination 10.41.0.0 with the subnet mask of 255.255.0.0, the next hop address of 10.27.0.1, and using the interface index 0x3, type:
route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 if 0x3
To delete the route to the destination 10.41.0.0 with the subnet mask of 255.255.0.0, type:
route delete 10.41.0.0 mask 255.255.0.0
To delete all routes in the IP routing table that begin with 10., type:
route delete 10.*
To change the next hop address of the route with the destination of 10.41.0.0 and the subnet mask of 255.255.0.0 from 10.27.0.1 to 10.27.0.25, type:
route change 10.41.0.0 mask 255.255.0.0 10.27.0.25
Top of page
Formatting legend
Format Meaning
Italic Information that the user must supply
Bold Elements that the user must type exactly as
shown
Ellipsis (...)Parameter that can be repeated several times in
a command line
Between brackets ([])Optional items
Between braces ({}); choices separated by pipe (|). Example: {even|odd}Set of choices from which the user must choose only one
Courier font Code or program output Command-line reference A-Z
TCP/IP utilities and services
Top of page
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论