How to change default gateway on windows by command line.

    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]

0 0 votes
Article Rating
9 Comments
Inline Feedbacks
View all comments
Nexus
Nexus
13 years ago

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

Thiago Suzin
Thiago Suzin
12 years ago

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

Thiago Suzin
Thiago Suzin
12 years ago

Just change “add” to “change”.

route change 0.0.0.0 mask 0.0.0.0 192.168.12.1

Att.,

Suzin

Deathcat
Deathcat
12 years ago

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

Aoddy
Admin
Aoddy(@aoddy)
12 years ago

Hi Deathcat,
You can put your commands into startup.bat. You can create by yourself please see all information at : http://aroundcny.com/technofile/texts/bklauncher98.html

😀

Arpi
Arpi
11 years ago

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?

Pinoy
10 years ago

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″

monoceros
monoceros
9 years ago

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