Network Stack Reset
Reset TCP/IP stack, DNS cache, and network adapters
Table of Contents
Automatically reset the Windows network stack to resolve connectivity issues.
Overview
This script performs a complete network stack reset including TCP/IP, DNS cache, Winsock catalog, and IP configuration. This resolves most network connectivity problems.
Use Case: When experiencing network connectivity issues, DNS resolution failures, or “limited connectivity” errors.
Platform: Windows 7/8/10/11, Windows Server 2012 R2+ Requirements: Administrator privileges Execution Time: 1-2 minutes (reboot required)
The Script
1<#
2.SYNOPSIS
3 Reset Windows network stack
4
5.DESCRIPTION
6 Resets TCP/IP stack, Winsock catalog, DNS cache, and IP configuration.
7 Resolves most network connectivity issues.
8
9.PARAMETER SkipReboot
10 If specified, does not prompt for reboot after reset
11
12.EXAMPLE
13 .\Reset-NetworkStack.ps1
14 Performs full network reset and prompts for reboot
15
16.EXAMPLE
17 .\Reset-NetworkStack.ps1 -SkipReboot
18 Performs network reset without reboot prompt
19
20.NOTES
21 Author: glyph.sh
22 Requires: Administrator privileges
23 Reference: https://glyph.sh/kb/windows-common-issues/
24#>
25
26[CmdletBinding()]
27param(
28 [switch]$SkipReboot
29)
30
31#Requires -RunAsAdministrator
32
33Write-Host "========================================" -ForegroundColor Cyan
34Write-Host " Network Stack Reset Script" -ForegroundColor Cyan
35Write-Host "========================================" -ForegroundColor Cyan
36Write-Host ""
37Write-Host "WARNING: This will reset all network settings!" -ForegroundColor Yellow
38Write-Host "A reboot will be required after completion." -ForegroundColor Yellow
39Write-Host ""
40
41$confirmation = Read-Host "Continue? (Y/N)"
42if ($confirmation -ne 'Y' -and $confirmation -ne 'y') {
43 Write-Host "Operation cancelled." -ForegroundColor Yellow
44 exit
45}
46
47Write-Host ""
48
49# Release DHCP lease
50Write-Host "[1/6] Releasing DHCP lease..." -ForegroundColor Yellow
51try {
52 ipconfig /release | Out-Null
53 Write-Host " DHCP lease released" -ForegroundColor Green
54}
55catch {
56 Write-Host " Failed to release DHCP lease" -ForegroundColor Red
57}
58
59Write-Host ""
60
61# Flush DNS cache
62Write-Host "[2/6] Flushing DNS cache..." -ForegroundColor Yellow
63try {
64 ipconfig /flushdns | Out-Null
65 Write-Host " DNS cache flushed" -ForegroundColor Green
66}
67catch {
68 Write-Host " Failed to flush DNS cache" -ForegroundColor Red
69}
70
71Write-Host ""
72
73# Reset Winsock catalog
74Write-Host "[3/6] Resetting Winsock catalog..." -ForegroundColor Yellow
75try {
76 netsh winsock reset | Out-Null
77 Write-Host " Winsock catalog reset" -ForegroundColor Green
78}
79catch {
80 Write-Host " Failed to reset Winsock" -ForegroundColor Red
81}
82
83Write-Host ""
84
85# Reset TCP/IP stack
86Write-Host "[4/6] Resetting TCP/IP stack..." -ForegroundColor Yellow
87try {
88 netsh int ip reset | Out-Null
89 Write-Host " TCP/IP stack reset" -ForegroundColor Green
90}
91catch {
92 Write-Host " Failed to reset TCP/IP" -ForegroundColor Red
93}
94
95Write-Host ""
96
97# Reset IPv6 stack
98Write-Host "[5/6] Resetting IPv6 stack..." -ForegroundColor Yellow
99try {
100 netsh int ipv6 reset | Out-Null
101 Write-Host " IPv6 stack reset" -ForegroundColor Green
102}
103catch {
104 Write-Host " Failed to reset IPv6" -ForegroundColor Red
105}
106
107Write-Host ""
108
109# Renew DHCP lease
110Write-Host "[6/6] Renewing DHCP lease..." -ForegroundColor Yellow
111try {
112 ipconfig /renew | Out-Null
113 Write-Host " DHCP lease renewed" -ForegroundColor Green
114}
115catch {
116 Write-Host " Failed to renew DHCP (normal if not using DHCP)" -ForegroundColor Yellow
117}
118
119Write-Host ""
120Write-Host "========================================" -ForegroundColor Cyan
121Write-Host " Network Stack Reset Complete" -ForegroundColor Cyan
122Write-Host "========================================" -ForegroundColor Cyan
123Write-Host ""
124
125if (-not $SkipReboot) {
126 Write-Host "A reboot is required for changes to take effect." -ForegroundColor Yellow
127 $rebootNow = Read-Host "Reboot now? (Y/N)"
128
129 if ($rebootNow -eq 'Y' -or $rebootNow -eq 'y') {
130 Write-Host "Rebooting in 10 seconds..." -ForegroundColor Yellow
131 shutdown /r /t 10 /c "Network stack reset - reboot required"
132 } else {
133 Write-Host "Please reboot manually when ready." -ForegroundColor Yellow
134 }
135}Usage
Basic Usage
1.\Reset-NetworkStack.ps1Skip Reboot Prompt
1.\Reset-NetworkStack.ps1 -SkipRebootWhat It Does
- Releases DHCP:
ipconfig /release - Flushes DNS Cache:
ipconfig /flushdns - Resets Winsock:
netsh winsock reset - Resets TCP/IP:
netsh int ip reset - Resets IPv6:
netsh int ipv6 reset - Renews DHCP:
ipconfig /renew
Common Issues This Resolves
- Cannot connect to network
- “Limited connectivity” errors
- DNS resolution failures
- IP address conflicts
- Cannot access internet
- Network adapter errors
After Running
- Reboot Required: Changes take full effect after reboot
- Reconfigure Static IPs: If using static IPs, you’ll need to reconfigure them
- Rejoin Network: May need to reconnect to WiFi
- Test Connectivity: Use
ping 8.8.8.8andping google.com
See Also
Download
1Invoke-WebRequest -Uri "https://glyph.sh/scripts/Reset-NetworkStack.ps1" -OutFile "Reset-NetworkStack.ps1"
2.\Reset-NetworkStack.ps1