Route delete all routes in windows

Route

Applies To: Windows Server 2003, Windows Vista, Windows XP, Windows Server 2008, Windows 7, Windows Server 2003 R2, Windows Server 2008 R2, Windows Server 2000, Windows Server 2012, Windows 8

Displays and modifies the entries in the local IP routing table. Used without parameters, route displays help. For examples of how this command can be used, see Examples.

Syntax

Parameters

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.

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.

Specifies the command you want to run. The following lists valid commands:

add: Adds a route.

change: Modifies an existing route.

delete: Deletes a route or routes.

print: Prints a route or routes.

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.

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.

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.

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.

Specifies the interface index for the interface over which the destination is reachable. For 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.

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).

Читайте также:  Pnp audio device драйвер windows 10

The /p parameter is only supported on the route command for WindowsВ NTВ 4.0, WindowsВ 2000, WindowsВ MillenniumВ Edition, WindowsВ XP, and Windows ServerВ 2003. 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.

Examples

To display the entire contents of the IP routing table, type:

To display the routes in the IP routing table that begin with 10, type:

To add a default route with the default gateway address of 192.168.12.1, type:

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:

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:

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:

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:

To delete the route to the destination 10.41.0.0 with the subnet mask of 255.255.0.0, type:

To delete all routes in the IP routing table that begin with 10, type:

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:

How to Add, Delete and Modify Static Route Windows 10 and Servers

Sometimes you need to create a static route to make communication with a different network that is connected via different gateway than the default gateway. A gateway is simply a network router which routes the network traffic between different networks. When you have more than one gateway (router) on your network, then you may need to implement static route technique on Windows 10, or Windows servers or even any Operating System. A static route will tell the Operating System to send network packets to the appropriate router instead of sending to the default router. This simple guide shows how to add, delete and modify a static route to the routing table on Windows 10 and Server Operating Systems.

There are a few useful commands you must know. Route delete, add and print. These commands will be handy to any user who has administrative access and know which router/gateway should be used for which network.

Why Add Static Route?

It mostly depends on the network setup. Usually, you can add these static routes on your default router (if it can support) or core switch. When you have this setup, you do not need to add a static route to each computer separately on the network. But in a few exceptional cases, you may need to implement static routes on individual computers. Here are a few examples.

  1. You have more than one internet router on the network and you need to send traffic to certain websites (based on their IP addresses) via different router than the default gateway. Let’s say, for example, all traffic to Netflix can be sent via the 2nd internet router where other website traffic can go through the 1st internet router.
  2. There are several VLANs or subnets available on the network. Before building the proper routing table on the router or core switch, adding a static route on your Windows computer will help you to test the connectivity see the traffic flow.
  3. For network security or isolation purpose, certain routes can’t be added to the default gateway device. In this case, as a network administrator, you can add the static route on a local computer to make network communication.

Route Add on Windows 10 and Windows Servers

Make sure you run below commands on command prompt (or PowerShell) which is opened as Administrator.

This is to add a static route to the routing table.

It indicates that any packets to 10.10.10.0 (in class C – 255.255.255.0) network should be forwarded to 10.10.29.1 router (gateway).

Obviously the PC/server which we run this command is in 10.10.29.0/24 network because it should communicate to gateway from the same network.

The issue with the above command is when you shut down or restart the computer, these route entries will be removed. To make it permanent and add to the Windows OS routing table, we should use –p key with the route add command. So, adding a persistent (or permanent) static route on Windows 10 command will be like this;

Route Print

Route print command is another useful command to view the routes on the Windows routing table and which routes are active at the moment. If you need to modify a route entry which is already in the routing table on Windows OS, better to confirm it before modifying. To do it, use route print command.

Читайте также:  После линукса не могу отформатировать флешку

Also, we can view the persistent routes in a Windows OS by checking the following registry path. Look for the entries in this area before or after modifying any routing table entries.

HKEY_LOCAL_MACHINE->SYSTEM->CurrentControlSet-> Services->Tcpip->Parameters->PersistentRoutes

Route Delete on Windows 10/ Windows 2016/2019 Servers

The below command is to delete an existing persistent route from a computer. Even though we added a route entry with the network, network mask and gateway, but to delete, we need to mention the network only. So, it goes like this;

That will delete the 10.10.10.0 route entry from the computer. You do not need to restart the computer to take effect, route add and delete commands work almost instantly.

How to Modify a Static Route Entry on Windows 10

Let’s say that after the recent network change, now the network 10.10.10.0 should be routed through 10.10.29.200 gateway. Obviously you have to modify the existing route for this network and change the gateway to 10.10.29.200, how to modify it?

You can’t modify an existing route entry. The simple method is to delete it and add the new route entry. So, in this case, you would perform below commands.

We hope this simple guide will be helpful in understanding the route add, delete and print commands in Windows 10 client PC and other server Operating Systems. Make sure you open the command prompt or PowerShell as Administrator to perform these commands. If you want to use cosmetic variables to identify the fast hops to reach a network, you can use the metric key as described at Microsoft site here.

Dinesh

Dinesh is the founder of Sysprobs and written more than 400 articles. Enthusiast in Microsoft and cloud technologies with more than 15 years of IT experience.

Clear all and only persistent (static) routes on Windows

Is there a simple way of doing this via a shell command / batch ? A VBScript would also be ok.

4 Answers 4

To clear all routes, use:

To clear only persistent routes, you could use but this wouldn’t remove them from the currently active routes.

Here is a cmd-script that extracts the static routes from the registry, and issues route delete commands for each of them.

This method removes them both from the stored list of persistent routes, and from the currently active routes.

It also deletes the default route if it’s found in the registry :

To prevent removing the default route, you can type this :

This can be done as a basic for-loop allowing you to clear the routes correctly for the existing and future routes.

( And without getting involved in reviewing or editing any registry items) using a simple route print piped into a find and looped into a route delete.

To delete all IPv4 persistent routes except the default route :

To delete all IPv6 persistent routes except the default route :

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Route

Applies To: Windows Server 2003, Windows Vista, Windows XP, Windows Server 2008, Windows 7, Windows Server 2003 R2, Windows Server 2008 R2, Windows Server 2000, Windows Server 2012, Windows 8

Displays and modifies the entries in the local IP routing table. Used without parameters, route displays help. For examples of how this command can be used, see Examples.

Syntax

Parameters

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.

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.

Specifies the command you want to run. The following lists valid commands:

add: Adds a route.

change: Modifies an existing route.

delete: Deletes a route or routes.

print: Prints a route or routes.

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.

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.

Читайте также:  Очистка печатающей головки windows 10

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.

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.

Specifies the interface index for the interface over which the destination is reachable. For 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.

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, WindowsВ XP, and Windows ServerВ 2003. 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.

Examples

To display the entire contents of the IP routing table, type:

To display the routes in the IP routing table that begin with 10, type:

To add a default route with the default gateway address of 192.168.12.1, type:

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:

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:

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:

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:

To delete the route to the destination 10.41.0.0 with the subnet mask of 255.255.0.0, type:

To delete all routes in the IP routing table that begin with 10, type:

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:

Оцените статью