batch-file

add & delete a new route in routing table using batch scripting


I'm using a work PC with two interfaces, mostly I add manual routes to my 10.0.0.0 network to access our internal network.

I got tired of doing this and wanted to create batch script file, but I have limited knowledge on it.

I just needed to delete and add route on the routing table of Windows, as follows:

route delete 0.0.0.0 mask 0.0.0.0 10.1.1.1
route add 10.0.0.0 mask 255.0.0.0 10.1.1.1
echo 'complete'

Solution

  • Are you sure route 0.0.0.0 even exist. Try route print and see if they exist. Moreover, run those command as admin. Once you sure those route exist and those command works separately then just wrap them all in a bat file like

    echo off
    route delete 0.0.0.0 mask 0.0.0.0 10.1.1.1
    route add 10.0.0.0 mask 255.0.0.0 10.1.1.1
    echo on
    echo 'complete'