Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to write a script that will involve modifying the IPv4 configuration of an interface. The interface may or may not already have any of the following configured:

  • IP Address
  • Subnet Mask
  • Default Gateway
  • DNS Servers
  • WINS Servers

When my script is done, I want only the options that I have set to be configured. (e.g.: If I don't set a Gateway, DNS, or WINS server, then I want none to be configured.) I figure the easiest way to ensure this is to wipe out the existing configuration as much as I can and then build up just what I need.

Leaving the existing IP Address and Subnet Mask is okay, because these will definitely be overwritten every time. It looks fairly simple to delete DNS and WINS servers with netsh.

netsh interface ipv4 delete dns "LAN" all
netsh interface ipv4 delete wins "LAN" all

My problem comes with deleting the gateway. It seems that every netsh command that is used to modify the default gateway requires the current IP address as a parameter. However, this will not always be something that is known. Is there not a way to use netsh to just delete all the gateways configured for an interface, without specifying the IP?

share|improve this question
1  
What version of Windows? –  Darth Android Aug 13 '13 at 15:23
    
Are you willing to set a new IP/mask? –  Jack Aug 13 '13 at 15:29
    
Windows 7/2008. And part of the script's purpose is to set a new IP & Subnet in the first place. So, I think I just realized my answer. –  Iszi Aug 13 '13 at 15:56

2 Answers 2

Delete default gateway:

route delete -p 0.0.0.0
share|improve this answer

Leaving the existing IP Address and Subnet Mask is okay, because these will definitely be overwritten every time.

Since you're overwriting the IP and Subnet Mask anyway, just use netsh to delete the gateway in the same step. e.g.:

netsh interface ipv4 set address "Local Area Connection" static 192.168.1.100 255.255.255.0 none

Here, you place none where the Default Gateway would normally go. This specifies that no gateway will be used with this IP.

share|improve this answer
    
@lszi "Local Area Connection" - unknown interface? –  STTR Aug 13 '13 at 17:08
    
@STTR Your interface may be named differently. Use netsh interface ipv4 show interfaces to find the correct name. Also make sure to replace 192.168.1.100 and 255.255.255.0 with the actual IP Address and Subnet Mask you want to use on that interface. –  Iszi Aug 13 '13 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.