10

I am trying to find how to change the default gateway on a Windows 7 machine from the DOS prompt.

Thanks!

4 Answers 4

11

Not sure if things have changed with Windows 7 but on XP you could just do something like this.

route add 0.0.0.0 mask 0.0.0.0 192.168.0.1

2
  • 5
    You can replace "add" with "change": route change 0.0.0.0 mask 0.0.0.0 192.168.0.1. That is only active until the next DHCP lease renewal or reboot. For a permanent change you need netsh with the correct interface name.
    – mivk
    Commented Jul 7, 2013 at 14:37
  • this will NOT SET gateway, this will ADD a gateway, therefore if a gateway is already set, windows will have now two gateways, and produce confusion in a OS that is already screwd up ... GOOD (right now, and ALWAYS, nasty problems in network configuration, for example I set up gw in graphical system, then see it in details, but if I reedit settings, gateway is not set), real answer is the above comment with route change Commented Apr 16, 2020 at 5:40
9
netsh interface ipv4 set route 0.0.0.0/32 "Local Area Connection" 192.168.1.1 

The name of the network adapter is likely "Local Area Connection".

8
  • 1
    When I run this command with "Local Area Connection" used for the name, I get the error: "Element not found". Do I need to use a different name?
    – laconicdev
    Commented Jul 22, 2011 at 13:53
  • run netsh interface show interface to list the available interfaces. you can pick the right one from the list Commented Jul 22, 2011 at 13:58
  • the show interface returns the following interface names: Local Area Connection and VirtualBox Host-Only Network. If I try to use Local Area Connection instead of ipv4 I get the following error: "The following command was not found: interface "Local Area Connection" set route 0.0.0.0/32 "Local Area Connection" 192.168.1.1
    – laconicdev
    Commented Jul 22, 2011 at 14:01
  • you need to use ipv4 too. See update in my answer.
    – HostBits
    Commented Jul 22, 2011 at 14:34
  • 5
    +1 netsh is the right way - doing it with a route add will require you to re-add the route each time you reboot the OS.
    – Lewis
    Commented Jul 22, 2011 at 14:37
7

The command line given by Cheekaleak does not work for me, this one does:

netsh int ip set address "Local Area Connection" address=192.168.1.64 mask=255.255.255.0 gateway=192.168.1.1

You have to specify every field (address, mask and gateway). Otherwise they will be reset.

3

A persistent way to change the configuration:

route -p add 0.0.0.0 mask 0.0.0.0 192.168.0.1     
route -p change 0.0.0.0 mask 0.0.0.0 192.168.0.1
1
  • this is much better than netsh, thank you ! Commented Apr 16, 2020 at 5:46

You must log in to answer this question.

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