9

Is a batch file the only way to release and renew an IP in one step?

ipconfig /release
ipconfig /renew

I unfortunately have to admin some Windows servers using Remote Desktop. Obviously if I type ipconfig /release, then I'll loose my connection and won't be able to ipconfig /renew. Obviously this can be done with .bat files, but I wanted to ask the pros just to see if there were any other tricks to doing it in the Windows server world.

1
  • The 'pros' would look to have an out-of-band remote management solution such as HP Integrated Lights Out or Dell's DRAC system in place. It then doesn't matter if the main network interfaces are functional with a correct IP address or not, you can still remote control the server to get them changed and working again. Jun 25, 2010 at 11:33

6 Answers 6

6

Most people I think just either use static IP addresses for servers, or fixed DHCP assignments, and don't change IP addresses outside of scheduled reboots (Changing endpoints on running servers=bad). A bat file seems the simplest solution, but honestly even a straight up release should autorenew an IP address before the remote desktop session times out.

5
  • in agreement, sounds odd to have renew the ip address of a server- it is generally not recommended.
    – redknight
    Jun 24, 2010 at 17:57
  • 1
    +1 DHCP on a server is not recommended at all, but I'd go with a right-click Repair on the NIC properties in the systray; that should work too and on a remote workstation I just tried, my RDP session persisted without issue.
    – gravyface
    Jun 24, 2010 at 17:58
  • 1
    I'm in the process of switching the server from a fixed address to a static DHCP lease on a new DHCP server. That's why I need to release/renew it, so it picks up its static lease from the new DHCP server. Jun 24, 2010 at 17:58
  • When you set it to DHCP it should auto renew? It certainly shouldn't need to release (what would it even be bound to?).
    – yasth
    Jun 24, 2010 at 18:01
  • Agreed that this, in general, is not something you would want to do... but when setting up the machine to use a static IP in the first place, while remoted in? It just saved my bacon.
    – mmc
    Feb 3, 2013 at 20:55
34

Combine the two commands into one

ipconfig /release && ipconfig /renew

Microsoft > Docs > PowerShell > Scripting > What's New > What's new in Powershell 7.x > What's new in Powershell 7.0 > Pipeline chain operators

The && operator executes the right-hand pipeline, if the left-hand pipeline succeeded.

2
  • 9
    +1 for answering what they asked instead of touting best practices at them! Although, in my trials here, you might need to stop the RDP session and re-establish (even if it's by name, not IP) as mine seems to just be trying to reconnect to the old IP still. Don't forget to ipconfig /flushdns after renewing the IP and giving it time to check in and before trying to find the hostname again!
    – PsychoData
    Apr 15, 2015 at 21:17
  • 1
    Thank you, the most useless answers on any stack site are ones where they ignore the question. Sure, the OP may be in the wrong, but these question show up in search results for those for whom it is correct and useful. I am working remotely on a workstation that has a DHCP reservation, but wanted to test that my newest DHCP DNS settings are functional, and needed to release and renew in one go. Nov 18, 2020 at 20:47
3

Use AT command. Example AT 12:58 ipconfig /release

AT 12:59 ipconfig /renew (this is useful when connecting with psexec, because it does not handle && commands)

1
  • Would definitely work! Use at to schedule a renew in a minute or so and schedule the /release for shortly before, or just do the /release yourself
    – PsychoData
    Apr 15, 2015 at 21:18
1

When working remotely, via Remote Desktop, I always combine both commands into one command line entry.

Command Prompt (cmd.exe):

ipconfig /release & ipconfig /renew

Powershell (powershell.exe, pwsh.exe):

ipconfig /release ; ipconfig /renew

IMPORTANT: If you instead do these command separately, you'll get disconnected without being able to renew!

0

Since the at command is deprecated now and doesn't work in Windows 10 (it gives the error The AT command has been deprecated. Please use schtasks.exe instead. The request is not supported.), here's an example of using schtasks to schedule the command to renew later.

schtasks /create /tr "ipconfig /renew" /st 02:00 /sc once /tn iprenew

Note that this creates a one-time scheduled task which clutters up the scheduled tasks list so simply delete it when you're done via the GUI or the command line.

-5

In powershell it would be ipconfig /release | ipconfig /renew

1
  • This would pipe the output of ipconfig /release into ipconfig /renew. I guess both commands would run, but simultaneously - it might try (and fail) renewing before it releases. && might work instead of |, as in Jason's answer.
    – mwfearnley
    Jan 25, 2019 at 17:26

You must log in to answer this question.

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