route - View and Edit the Routing Table
Table of Contents
The route command displays and edits the routing table, the table of paths your computer uses for network traffic.
When your PC sends traffic, it consults the routing table to decide which gateway (exit) to use for a given destination. With route, you can inspect that table, or send traffic for a specific network through a different router.
Basic Syntax of the route Command
route [-f] [-p] [-4|-6] <command> [<destination>] [mask <netmask>] [<gateway>] [metric <metric>] [if <interface>]
Specify one of the following four commands as <command>.
| Command | Description |
|---|---|
print | Display the routing table |
add | Add a route |
delete | Delete a route |
change | Modify an existing route |
Option Quick Reference
| Option | Description |
|---|---|
-f | Clear all routes that have a gateway from the routing table |
-p | Used with add to make the route persist across reboots |
-4 | Target IPv4 only |
-6 | Target IPv6 only |
print works in a regular Command Prompt, but adding, deleting, or changing routes requires administrator privileges. Without them, the operation is denied. See the related article for how to start as an administrator.
Display the Routing Table (print)
route print
Labels and contents vary depending on your Windows display language and network configuration. The output above is an example to show the format.
The IPv4 route table consists of the following five columns.
| Column | Description |
|---|---|
| Network Destination | Address of the destination network |
| Netmask | Subnet mask that defines the range of the destination network |
| Gateway | Address of the next device to forward traffic to (On-link if on the same network) |
| Interface | IP address of the network adapter used to send the traffic |
| Metric | Priority of the route. Lower values take precedence |
The row with destination 0.0.0.0 and netmask 0.0.0.0 is the default route (default gateway). Any traffic that matches no other route is sent here.
Filter the Output
Specify a destination after print to show only matching routes. You can also use *.
route print 192.168.*
To show only IPv4 or only IPv6, add -4 or -6.
route -4 print
route -6 print
Add a Route (add)
For example, to send only traffic for 10.0.0.0/255.0.0.0 through the router 192.168.1.254:
route add 10.0.0.0 mask 255.0.0.0 192.168.1.254
To specify a metric, add metric.
route add 10.0.0.0 mask 255.0.0.0 192.168.1.254 metric 5
If you have multiple network adapters, specify the interface number with if (you can find it in the interface list shown by route print).
route add 10.0.0.0 mask 255.0.0.0 192.168.1.254 if 12
Specify an IPv6 destination with a prefix length, such as 2001:db8::/32.
Keep the Route After a Reboot (-p)
By default, a route added with add disappears after a reboot. To keep it, add -p.
route -p add 10.0.0.0 mask 255.0.0.0 192.168.1.254
Persistent routes are listed in the “Persistent Routes” section at the end of the route print output.
Delete a Route (delete)
route delete 10.0.0.0
If you specify only the destination, the routes matching that destination are deleted. When several routes might match, also specify mask and the gateway to narrow down the target.
route delete 10.0.0.0 mask 255.0.0.0 192.168.1.254
Modify a Route (change)
Change the gateway or metric of an existing route.
route change 10.0.0.0 mask 255.0.0.0 192.168.1.253
change cannot modify the destination or netmask itself. To change them, remove the route with delete and add it again with add.
Clear the Routing Table (-f)
route -f
You can also combine -f with another command. In that case, the table is cleared before the command runs.
Running -f removes every route that has a gateway, including the default route (default gateway), and you may lose access to the internet or your corporate network. If you are working remotely, you may be disconnected and unable to recover. To tidy up routes, it is safer to remove only the routes you need to with delete.
Practical Examples
Check the Current Default Gateway
Filter the output by specifying 0.0.0.0 as the destination to find the default route.
route print -4 0.0.0.0
ipconfig also shows the default gateway, but route print gives more detail when multiple routes exist.
Check Routes While on a VPN
Connecting to a VPN may add routes to the routing table. Save the route print output before and after connecting, then compare them with fc to see what changed.
route print > before.txt
rem Connect to the VPN, then
route print > after.txt
fc before.txt after.txt
Use a Different Router for One Network Only
This example sends only traffic for the internal network 10.1.0.0/16 through the dedicated router 192.168.1.254.
@echo off
route -p add 10.1.0.0 mask 255.255.0.0 192.168.1.254
if errorlevel 1 (
echo Failed to add the route. Run this as an administrator.
exit /b 1
)
echo Route added.
Summary
| Goal | Command |
|---|---|
| Display the routing table | route print |
| Display IPv4 only | route -4 print |
| Add a route | route add 10.0.0.0 mask 255.0.0.0 192.168.1.254 |
| Add a route that survives reboots | route -p add 10.0.0.0 mask 255.0.0.0 192.168.1.254 |
| Delete a route | route delete 10.0.0.0 |
| Change a route’s gateway | route change 10.0.0.0 mask 255.0.0.0 192.168.1.253 |