How to Automatically Clear the Windows 11 DNS Cache on Startup

Your computer maintains a local address book called the DNS (Domain Name System) cache, which saves the IP addresses of the websites you visit so they load faster the next time. However, if a website changes its server IP address, your stale DNS cache will try to send you to the old location, resulting in connection errors. While you can manually flush the cache using the command prompt, you can easily configure Windows 11 to automatically wipe it clean every time you turn on your computer.

How to Create the Batch Script

We need to create a tiny text file that contains the exact command used to flush the DNS cache.

  1. Right-click anywhere on your Windows 11 desktop, select New, and click Text Document.
  2. Open the new text document in Notepad.
  3. Type the following single line of text: ipconfig /flushdns
  4. Click on File in the top left corner and select Save As…
  5. In the Save As dialog box, click the Save as type dropdown menu and change it from Text Documents (*.txt) to All Files (*.*).
  6. Name the file ClearDNS.bat and save it to your desktop. You will notice the file icon changes to look like a small window with gears in it, indicating it is now an executable batch file.

How to Run the Script on Startup

Now we must place this batch file into the hidden Windows Startup folder so the operating system knows to run it during the boot sequence.

  1. Press the Windows Key + R on your keyboard to open the Run dialog box.
  2. Type exactly: shell:startup and press Enter.
  3. A File Explorer window will open, revealing your personal Startup folder.
  4. Click and drag your ClearDNS.bat file from your desktop into this Startup folder.

The automation is now complete. The next time you restart your Windows 11 PC, you will briefly see a black command prompt window flash on your screen for a fraction of a second. This is your script automatically executing the ipconfig /flushdns command in the background, ensuring you start every browsing session with a perfectly clean, up-to-date DNS cache.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.