Enable/Disable TCP/IP from Command Prompt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 666
Joined: 28 Jun 2010 03:46

Enable/Disable TCP/IP from Command Prompt

#1 Post by miskox » 08 Mar 2012 06:57

Hi all,

is there a way (using pure DOS commands and/or other* tools (vbs, power shell etc.) to achieve this:

I would like to be able to Enable/Disable TCP/IP from DOS prompt, the same as doing this via GUI:

- Network Connections -> select your LAN connection -> scroll down to Internet Protocol (TCP/IP) and select/deselect check box on the left (enable/disable). Of corse when disabling there is a warning that some other components will be disabled. Of course I click Yes.


Is this possible from a command prompt?
Thanks,
Saso

* other tools: standalone .exe or something (.vbs, .cmd...) - no installation required.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Enable/Disable TCP/IP from Command Prompt

#2 Post by foxidrive » 08 Mar 2012 09:02

This should disconnect the connection:

ipconfig /release


This should renew the connection:

ipconfig /renew




I don't know if Windows will automatically try to renew the connection after a while or not. You can specify the adapter with ipconfig too.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Enable/Disable TCP/IP from Command Prompt

#3 Post by Squashman » 08 Mar 2012 09:45

netsh interface set interface "Interface name" DISABLED

miskox
Posts: 666
Joined: 28 Jun 2010 03:46

Re: Enable/Disable TCP/IP from Command Prompt

#4 Post by miskox » 08 Mar 2012 13:26

@foxidrive: I will try this later (to avoid IP conflicts I cannot do it now).

@Squashman: this will probably disable the whole interface. I need only TCP/IP enable/disable option - all other protocols must be active.

Thank you both.
Saso

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Enable/Disable TCP/IP from Command Prompt

#5 Post by Squashman » 08 Mar 2012 14:08

Well you could use Netsh to change the IP address to some non routable IP address on your network and then change it back to whatever when needed.
http://www.petri.co.il/configure_tcp_ip_from_cmd.htm

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Enable/Disable TCP/IP from Command Prompt

#6 Post by Squashman » 08 Mar 2012 14:18

Give this a try.
netsh int ipv4 uninstall
netsh int ipv4 install

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Enable/Disable TCP/IP from Command Prompt

#7 Post by foxidrive » 08 Mar 2012 15:07

Squashman wrote:Give this a try.
netsh int ipv4 uninstall
netsh int ipv4 install



I think that while this should work ipv4, any TCP/IP configuration changes will be lost like RWIN factors etc, if it sets TCP/IP back to default values.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Enable/Disable TCP/IP from Command Prompt

#8 Post by foxidrive » 08 Mar 2012 15:12

foxidrive wrote:This should disconnect the connection:
ipconfig /release

This should renew the connection:
ipconfig /renew



If the network adapter has a fixed IP address this may not work - I think it only works for DHCP negotiated connections.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Enable/Disable TCP/IP from Command Prompt

#9 Post by Ed Dyreen » 08 Mar 2012 16:36

foxidrive wrote:If the network adapter has a fixed IP address this may not work - I think it only works for DHCP negotiated connections.
Yes, it works with fixed IP address (and much faster).

miskox
Posts: 666
Joined: 28 Jun 2010 03:46

Re: Enable/Disable TCP/IP from Command Prompt

#10 Post by miskox » 20 Mar 2012 15:08

I still have to do/try this. Will do in the near future.

Thanks,
Saso

Post Reply