Skip to main content

How to Release a DHCP Lease in Batch Script

In a typical network, your computer's IP address is assigned automatically by a DHCP (Dynamic Host Configuration Protocol) server. This assignment, called a "lease," is temporary. Sometimes, for network troubleshooting, you need to force your computer to give up its current IP address and request a new one. The process of giving up the address is called "releasing the DHCP lease."

This guide will teach you how to use the standard, built-in ipconfig command to release your current IP address. You will learn the critical follow-up step of renewing the lease, the prerequisites for the command to work, and how to use it as part of a larger network reset script.

The Core Command: ipconfig /release

The ipconfig.exe utility is the primary command-line tool for managing the TCP/IP network configuration on a Windows machine. To release the DHCP lease for all adapters, you use the /release switch.

Syntax: ipconfig /release

This command sends a message to the DHCP server, informing it that you are no longer using your assigned IP address. This is a privileged operation and requires an elevated command prompt.

Basic Example: A Simple Lease Release Script

This script will immediately release the IP address for all network adapters.

warning

Running this command will disconnect your computer from the network until you get a new IP address!

@ECHO OFF
TITLE DHCP Lease Release
REM This script must be run as an Administrator.

ECHO --- Releasing DHCP IP Address Lease ---
ECHO Your network connection will be temporarily disconnected.
ECHO.
PAUSE

ipconfig /release

ECHO.
ECHO --- Operation complete ---
PAUSE

The Other Half of the Process: ipconfig /renew

Releasing your IP address is usually only half the battle. By itself, ipconfig /release leaves your computer without an IP address and unable to communicate on the network. The very next step is almost always to request a new lease from the DHCP server.

Syntax: ipconfig /renew

This command broadcasts a request on the network, and the DHCP server responds by assigning a new (or the same old) IP address lease to your computer.

For example, for any network reset, you should run the commands in this order:

ipconfig /release
ipconfig /renew

How the Command Works

When you run ipconfig /release, your computer sends a special packet called a DHCPRELEASE message to the DHCP server that originally gave it the IP address. This message tells the server, "I am done with the IP address X.X.X.X." The DHCP server receives this message and marks that IP address as "available" again in its pool of addresses, ready to be assigned to another computer. Your computer's network adapter is then left with a 0.0.0.0 IP address until it gets a new one.

Common Pitfalls and How to Solve Them

Problem: The Script is Not Run as Administrator

This is the most common reason the command fails. Modifying network configuration is a privileged operation.

Example of error message:

The requested operation requires elevation.

Solution: The script must be run as an Administrator. Right-click your .bat file or cmd.exe and select "Run as administrator."

Problem: The DHCP Client Service is Not Running

The ipconfig command communicates with the "DHCP Client" service (Dhcp) to perform these actions. If this service is stopped, the command will fail.

Example of error message:

The operation failed as no adapter is in the state permissible for this operation.

Solution: This is rare, but a robust script can check for and start the service if needed.

SC query Dhcp | FIND "STATE" | FIND "RUNNING" > NUL
IF %ERRORLEVEL% NEQ 0 (
ECHO DHCP Client service is not running. Starting it...
NET START Dhcp
)

Problem: How to Target a Specific Network Adapter

By default, ipconfig /release releases the IP for all adapters that use DHCP. If you only want to reset a specific connection (like your Wi-Fi), you can specify its name.

Solution: You can find the adapter's name by running ipconfig. The name is the string listed under "Ethernet adapter" or "Wireless LAN adapter".

REM The name of the adapter is "Wi-Fi".
ipconfig /release "Wi-Fi"
ipconfig /renew "Wi-Fi"

Practical Example: A Full Network Reset Script

This is the "go-to" script for many network troubleshooting situations. It combines releasing and renewing the IP address with flushing the DNS cache to perform a comprehensive reset of the network state.

@ECHO OFF
SETLOCAL
TITLE Full Network Reset Utility
REM This script must be run as an Administrator.

ECHO --- Network Reset Script ---
ECHO This will release/renew your IP, and flush your DNS cache.
ECHO Your network connection will be briefly interrupted.
ECHO.
PAUSE

ECHO Step 1: Releasing current IP address...
ipconfig /release

ECHO.
ECHO Step 2: Renewing IP address from DHCP server...
ipconfig /renew

ECHO.
ECHO Step 3: Flushing the DNS Resolver Cache...
ipconfig /flushdns

ECHO.
ECHO [SUCCESS] Network reset is complete.
PAUSE
ENDLOCAL

Conclusion

The ipconfig /release command is an essential tool for network diagnostics and troubleshooting from the command line.

Key takeaways for using it in a script:

  • You must run the script as an Administrator.
  • Releasing the lease will disconnect you from the network.
  • It should almost always be immediately followed by ipconfig /renew to restore connectivity.
  • You can target a specific network adapter by providing its name (e.g., ipconfig /release "Ethernet").