10

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

Thanks!

laconicdev
  • 221
  • 1
  • 2
  • 6

4 Answers4

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

3dinfluence
  • 12,449
  • 2
  • 28
  • 41
  • 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 Jul 07 '13 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 – THESorcerer Apr 16 '20 at 05: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".

HostBits
  • 11,796
  • 1
  • 25
  • 39
  • 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 Jul 22 '11 at 13:53
  • run `netsh interface show interface` to list the available interfaces. you can pick the right one from the list – Michael Lowman Jul 22 '11 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 Jul 22 '11 at 14:01
  • you need to use ipv4 too. See update in my answer. – HostBits Jul 22 '11 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 Jul 22 '11 at 14:37
  • This did not work for me on a 2008 R2 server, I also got the "Element not found" error. "route -p change ..." worked like a charm. – Lucky Luke Nov 29 '17 at 00:50
  • /32 ... REALLY ?!? is ONLY one ip called 0.0.0.0 ?!? – THESorcerer Apr 16 '20 at 05:42
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.

magnetik
  • 247
  • 2
  • 12
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
Olix
  • 31
  • 1