0

This is route print output:

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      192.168.1.1     192.168.1.50     55
          0.0.0.0        128.0.0.0   192.168.10.252    192.168.10.96    257
        128.0.0.0        128.0.0.0   192.168.10.252    192.168.10.96    257
          1.1.1.1    255.255.255.0      192.168.1.1     192.168.1.50    56
      185.1.1.1.1  255.255.255.255      192.168.1.1     192.168.1.50    311
     192.168.10.0    255.255.255.0         On-link     192.168.10.96    257
    192.168.10.96  255.255.255.255         On-link     192.168.10.96    257
   192.168.10.255  255.255.255.255         On-link     192.168.10.96    257
===========================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
     1.1.1.1         255.255.255.0      192.168.1.1       1
===========================================================================

As you see, 1.1.1.1/24 is added in routing table.

I want to delete a subnet (like /32 or bigger) from this but I get error:

route delete -p 1.1.1.10/32 192.168.1.1
route delete -p 1.1.1.0/25 192.168.1.1

Error:

The route deletion failed: Element not found.

I know I can remove the whole /24 subnet and then use a Python script to generate the desired subnets, but my question is whether it's possible to remove a smaller subnet in routing table.

Windows 10, PowerShell version is 5.1 (18200).

1 Answer 1

4

Rather than delete a subnet from an existing route (which you can't; you can only delete a route that exists), you probably want to create a new route for that subnet. Routes are fundamentally layered, which makes sense as the lowest priority route is generally for 0.0.0.0/0 (all IP addresses) and described as the "default" route.

I believe that more specific (smaller number of IP addresses) routes are preferred over more general, so you can probably just do that, copying the interface / gateway from one of the other encompasing routes for the new one. Regardless, the example uses a smaller metric (higher priority) than any other route, so it should be preferred.

An example: route add /p 1.1.1.0 mask 255.255.255.128 192.168.10.252 metric 54

Unsolicited advice: Don't create a network smaller than a /30.

Best of luck.

2
  • Thanks. The actual routing table has much more, and I wanted to know if it's possible, which is not based your answer. Regarding metric, I just ran route add -p 1.1.1.0/24 192.168.1.1 and I think metric value is set by Windows not me.
    – Saeed
    Commented Jun 1, 2022 at 19:33
  • 1
    You could construct the effect of deleting a route, but it would be ugly. You'd effectively break one route into a bunch of other routes surrounding the gap that you are talking about because of how routes and subnet masks work. In other words, you'd greatly amplify the number of routes the computer has to evaluate when making routing decisions, which is exactly the opposite of what you want to do for such a critical part of networking decisions. Instead of looking at two routes in priority order, it would have to look at 10s of routes to find the matching one. Commented Jun 1, 2022 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .