How to Add a Route in Windows Using the route add Command

Routing is essential when managing network traffic between different networks. In some cases, you may need to manually add a route to direct traffic through a specific gateway, especially in more complex network setups. This guide walks you through adding a static route in Windows using the route add command.

What is a Route?

A route is a defined path that data packets follow to reach a specific destination. When a device sends data over a network, the operating system uses routing tables to determine the best path for that data. By adding routes, you can control how traffic is directed between your machine and other devices on different networks.

When Do You Need to Add a Route?

You may need to add a route in several scenarios:

  • You have multiple network interfaces, and you want traffic to be routed through a specific one.
  • You’re working in a complex network environment with various subnets.
  • You need to access a specific subnet that is not part of your default route.

For example, if you’re trying to route traffic from 192.168.122.0/24 to go through a specific gateway 172.16.253.10, you would need to add a static route.

Steps to Add a Route in Windows

Follow these steps to add a route using the Command Prompt.

Step 1: Open Command Prompt as Administrator

Before you can add a route, you must have administrative privileges. Here’s how to open the Command Prompt as an administrator:

  1. Press Windows + X and select Command Prompt (Admin) or Windows Terminal (Admin) from the menu.
  2. If prompted by User Account Control (UAC), click Yes to allow the changes.
Step 2: Add the Route

Once the Command Prompt is open with administrative rights, you can use the route add command to add the new route.

For example, to add a route for network 192.168.122.0/24 with the gateway 172.16.253.10, use the following command:

route add 192.168.122.0 mask 255.255.255.0 172.16.253.10
  • 192.168.122.0 is the network address.
  • mask 255.255.255.0 is the subnet mask for the /24 subnet.
  • 172.16.253.10 is the gateway address that traffic will be routed through.

This command will add the route temporarily, meaning it will be lost when you restart your computer.

Step 3: Make the Route Persistent (Optional)

If you want the route to persist after a reboot, you need to add the -p flag to the command:

route -p add 192.168.122.0 mask 255.255.255.0 172.16.253.10

This tells Windows to store the route in the system’s routing table permanently. The route will remain in place even after the system reboots.

Step 4: Verify the Route

To verify that the route has been added, you can use the route print command, which shows the entire routing table:

route print

Look for your route under the appropriate section to confirm that it has been added successfully.

Additional Route Command Options

Here are some additional route command options you may find useful:

  • Delete a Route: To delete a route, use the following syntax:bashCopy coderoute delete 192.168.122.0
  • Change a Route: To modify an existing route, use the following command:bashCopy coderoute change 192.168.122.0 mask 255.255.255.0 172.16.253.11 This will change the gateway for the route to 172.16.253.11.

Conclusion

Adding a route in Windows is a straightforward process that can be done using the route add command. Whether you’re managing multiple network interfaces or setting up specific network paths, understanding how to manually add routes is an essential skill for network administration. Remember, you can always use the -p flag to make routes persistent after reboot.

With these steps, you can confidently manage routing in your Windows environment. Happy routing!