Right, you can change you default gateway on windows by route command , it’s very useful. Other than , you can add route to other network by this command too. I have example for you too. ( I get from link that :))

Syntax route [-f] [-p] [Command[Destination] [mask Network] [Gateway] [metric Metric]] [if Interface]]

Example: [ad#ad-post-1]

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

route print

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

route print 10.*

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

route add 0.0.0.0 mask 0.0.0.0 192.168.12.1

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:

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1

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:

route -p add 10.41.0.0 mask 255.255.0.0 10.27.0.1

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:

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 metric 7

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: 

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 if 0x3

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

route delete 10.41.0.0 mask 255.255.0.0

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

route delete 10.*

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:

route change 10.41.0.0 mask 255.255.0.0 10.27.0.25

[ad#post-image]

How to change default gateway on windows by command line.

Comments

comments

10 thoughts on “How to change default gateway on windows by command line.

  • November 14, 2008 at 3:41 am
    Permalink

    I’m still wondering how to change the default gateway on windows by command line

  • January 15, 2009 at 6:06 pm
    Permalink

    Nexus,

    Use this command:

    route add 0.0.0.0 mask 0.0.0.0 192.168.12.1

    The route default will change to 192.168.12.1 in this case.

    []s,

    Suzin

  • January 23, 2009 at 12:19 am
    Permalink

    Just change “add” to “change”.

    route change 0.0.0.0 mask 0.0.0.0 192.168.12.1

    Att.,

    Suzin

  • August 15, 2009 at 7:54 am
    Permalink

    Is there a way to keep the default gateway change if you restart?

  • July 29, 2010 at 2:15 pm
    Permalink

    It doesn’t work on Windows XP sp3 or Windows 7. Try clearing the routing table and then put back the default route. Something like this:
    route -f
    route add -p 0.0.0.0 MASK 0.0.0.0 192.168.1.254 METRIC 10

    The routing table (route print) will look ok, but communication won’t work. You’ll have to use the graphic interface in order to enter the default gateway. First you have to change it to something else than 192.168.1.254, and then back to 192.168.1.254.
    I can’t figure out what am I missing. Or this is a bug?

  • June 1, 2011 at 2:15 am
    Permalink

    I have this routes in my routing table

    Active Routes:
    Network Destination Netmask Gateway Interface Metric
    0.0.0.0 0.0.0.0 On-link 10.157.35.187 41
    0.0.0.0 0.0.0.0 10.0.0.1 10.0.0.2 4256
    0.0.0.0 128.0.0.0 10.0.0.1 10.0.0.2 4256

    Do you know how to remove only this ” 0.0.0.0 0.0.0.0 10.0.0.1 10.0.0.2 4256″

  • April 17, 2012 at 7:24 pm
    Permalink

    Very quickly this web site will be famous amid all blogging people, due to it’s fastidious content

  • November 20, 2012 at 11:52 am
    Permalink

    Hi, is it possible to change metric that has “on-link” gateway?

  • Pingback: Windows command-line: Finding default routes and setting their metric « The Wiert Corner – irregular stream of stuff

Comments are closed.