DNS Cache in the OS and Application: Why Changing Proxy Doesn't Change Resolution — Step-by-Step Reset Guide
Table of contents
- Introduction: what you'll get and who this guide is for
- Preparation: tools, access, and backups
- Core concepts: how a name becomes an address and where it gets stuck
- Step 1: diagnostics — finding which layer is holding the old address
- Step 2: flushing the system dns cache on linux, windows, and macos
- Step 3: clearing the browser dns cache and connection pool
- Step 4: managing dns cache in the jvm and java applications
- Step 5: handling caches in other runtimes, utilities, and on the proxy side
- Step 6: tuning ttl and automating flushes
- Verifying the result: checklist and full test scenario
- Common mistakes and fixes
- Advanced techniques
- Faq: common questions about dns cache and flushing
- Conclusion
Introduction: What You'll Get and Who This Guide Is For
A familiar situation: you switched the proxy in your system or app, refreshed the page, but the site still opens from the old address, shows the old region, or just ignores the new settings entirely. Your first thought is usually: the proxy isn't working. In practice, the proxy is fine most of the time. There's just a DNS cache sitting somewhere between your program and the network that already memorized the answer and won't ask again until the record's time-to-live expires.
This guide is specifically about caches. We won't dig into remote resolution through a proxy or the difference between socks5 and socks5h schemes — that's a whole separate topic covered in another article. Here we're tackling a different layer of the problem: why even with a properly configured proxy the old IP keeps living in your system, exactly where it's stored, and how to guarantee you kick it out.
What you'll get out of this. After working through the guide, you'll be able to figure out in a couple of minutes which cache is holding the old record: the system resolver, the nscd service, the browser, a Java virtual machine, or an application's connection pool. You'll learn to flush each of these caches on Linux, Windows, and macOS, tune record lifetimes for your tasks, and verify results so there's no doubt left.
Who this guide is for. Developers, testers, admins, and anyone who regularly works with proxies, tests sites from different regions, migrates services to new addresses, or debugs network issues. Intermediate level: you're comfortable with basic terminal commands, but you don't need deep DNS knowledge. Advanced sections are marked separately and can be skipped on a first read.
What you should know beforehand. How to open a terminal or command prompt on your OS, how to run commands with administrator rights, and what an IP address is. We'll explain everything else as we go.
How much time it'll take. A full run-through with verification takes 40 to 60 minutes. If you just need to flush the cache in one specific place, find the relevant step and you'll be done in 5 minutes.
Preparation: Tools, Access, and Backups
Before you start, make sure you have everything you need on hand. The list is short, but every item matters: without admin rights you can't flush the system cache, and without the dig utility it's hard to see record TTLs.
Required tools
- Terminal with administrator rights. On Linux and macOS that's sudo, on Windows it's the command prompt or PowerShell running as administrator.
- dig and nslookup utilities. On Linux, dig comes in the dnsutils package (Debian and Ubuntu) or bind-utils (Fedora, RHEL). On macOS dig is installed by default. On Windows there's nslookup, and you can get dig as part of the BIND package or use the PowerShell command Resolve-DnsName.
- curl utility. Present in current Windows 11 versions, macOS, and almost every Linux distribution in 2026.
- Browser. Chrome, any Chromium-based browser, or Firefox. We'll cover both families.
- Java Development Kit version 17, 21, or 25 if you plan to do the JVM step. If you don't use Java, skip that step.
- Access to the proxy server you're working with: address, port, username, and password. We'll be switching proxies to observe the cache effects.
- A test domain. Best is a domain where you can change the A record, or one with geographically dependent responses. If you don't have your own, any large CDN site will work: those domains often return different answers by region.
System requirements
This guide has been tested on Ubuntu 24.04 and 26.04, Debian 13, Fedora 43, Windows 11 with current 2026 updates, and macOS 15 and later. On other systems the commands may differ slightly, but the logic is the same.
Installing what's missing
- On Ubuntu or Debian, run
sudo apt update && sudo apt install dnsutils curl. - On Fedora, run
sudo dnf install bind-utils curl. - On macOS you don't need to install anything. Optionally, install bind via Homebrew:
brew install bind. - On Windows, open PowerShell as administrator and verify that
Resolve-DnsName example.comreturns a result. That's enough.
Backups
We'll be editing configuration files: java.security, nscd.conf, files in the /etc/systemd/resolved.conf.d directory, and the hosts file. Before changing any file, make a copy. Universal approach: sudo cp /path/to/file /path/to/file.bak. On Windows, just copy the file into the same folder with a .bak suffix using File Explorer.
Warning: flushing the DNS cache is safe by itself and won't break your system. But thoughtlessly disabling the systemd-resolved or nscd service can leave you without name resolution until reboot. Don't disable services unless the guide explicitly says otherwise. We'll only flush their caches and adjust parameters.
Tip: Create a text journal file and write down every command and its result. Half an hour later you won't remember which cache you flushed first, and the journal will save you time when troubleshooting common errors.
Core Concepts: How a Name Becomes an Address and Where It Gets Stuck
To confidently fight caches, you need to understand how many there are and why they exist at all. Let's break down the key terms in plain language.
DNS and resolution
DNS is a distributed directory that translates human-friendly names like example.com into IP addresses that the network understands. The translation process is called resolution. Every time a program wants to connect to a site, it needs the IP, and it either asks the resolver or pulls it from a cache.
TTL — record lifetime
TTL (Time To Live) is the number of seconds during which the domain owner permits the answer to be remembered. If TTL is 300, any cache along the path is allowed to hold the address for 5 minutes without asking again. Typical values: from 60 seconds for services that move frequently to 86400 seconds — a full day — for stable resources. Important: TTL is an upper bound. A cache may evict a record earlier, but it's not allowed to hold it longer. In practice, some caches ignore TTL and hold records by their own rules. Those are exactly the cases we care about.
The layered cake of caches
The main thing to grasp: DNS cache is not a single place. A name lookup passes through several layers, and each one can answer from its own memory without descending further. Let's list the layers from top to bottom, from application to network.
- Application cache. The browser keeps its own name-to-address table. A Java virtual machine caches InetAddress results. Some libraries and frameworks add their own caches on top of the system one.
- Connection pool. Technically not a DNS cache, but the effect is the same: the application has already opened a TCP connection to the old IP and reuses it without resolving anything. Browsers and HTTP clients do this constantly.
- System resolver and its cache. On modern Linux this is usually systemd-resolved listening on 127.0.0.53. On older and minimal systems it's nscd (Name Service Cache Daemon) or dnsmasq. On Windows it's the DNS Client service. On macOS it's mDNSResponder.
- The hosts file. Static entries that override DNS. Not a cache in the strict sense, but a frequent source of surprises.
- Router or local DNS server cache on your ISP's network. We can't influence this one, but we must account for it.
- The domain's authoritative server. The source of truth, which a query reaches only when all caches above are empty or stale.
Why the proxy isn't the culprit here
The proxy server operates at the transport level: it accepts your connection and opens its own connection to the target. Name resolution happens before that, by its own rules. If the application resolves the name itself, it pulls the address from caches in layers 1–4 and only then decides whether to go direct or through the proxy. Changing proxies doesn't touch any of these caches. The records live their own lives, and until TTL expires or the cache is forcibly flushed, you'll keep seeing the old result.
There's also the opposite situation: when using an HTTP proxy with the CONNECT method or a SOCKS proxy with remote resolution, the name is passed to the proxy, and the proxy does the resolving. Then local caches aren't involved, but the cache on the proxy side is. We don't cover that scenario in detail, but in Step 5 we'll show how to quickly figure out where the resolution actually happened.
Negative cache
A separate term that often causes confusion: negative cache. If a resolver received a response that a name doesn't exist, it will remember that too. In the JVM negative answers are stored for 10 seconds by default, in systemd-resolved they follow the TTL from the domain's SOA record. So if you just added a domain and the application stubbornly says the name isn't found, the negative cache may be the culprit.
Step 1: Diagnostics — Finding Which Layer Is Holding the Old Address
Goal of this stage: learn to determine in just a few commands which level the record is stuck at, so you don't blindly flush everything.
The diagnostic principle is simple: query the same domain at different layers and compare the answers. If the authoritative server returns the new address, the system resolver returns the new address, but the browser returns the old one, the culprit is obvious.
Querying the authoritative source
- Open a terminal.
- Run
dig example.com A +noall +answer, substituting your domain. You'll see a line likeexample.com. 287 IN A 93.184.215.14. The second field is the remaining TTL in seconds at your resolver. If the number decreases across repeated runs, the answer is coming from cache. - Now bypass local caches and query a public resolver directly:
dig @1.1.1.1 example.com A +noall +answer. Compare the address and TTL. - Finally, find the domain's authoritative server:
dig example.com NS +short. Take any name from the list and query it:dig @ns1.example-dns.net example.com A +noall +answer. Here the TTL is always full and the address is the freshest.
On Windows the equivalent: Resolve-DnsName example.com -Type A for the system resolution and Resolve-DnsName example.com -Type A -Server 1.1.1.1 to bypass the local cache.
Querying the system resolver
- On Linux with systemd-resolved, run
resolvectl query example.com. At the end of the output there will be a data source line: Data from: cache means the answer came from cache, Data from: network means the query went out to the network. - Check how regular programs resolve through the system library:
getent hosts example.com. This is exactly the path used by curl without special flags, Python, Go, and most utilities. If the result differs from dig, there's another layer in between: the hosts file, nscd, or a special order in /etc/nsswitch.conf. - On Windows, run
ipconfig /displaydns | findstr example.com. If the domain shows up in the list, it's in the DNS Client service cache. - On macOS, run
dscacheutil -q host -a name example.com. The output shows what the system hands to applications.
Querying the application
- In Chrome, open
chrome://net-internals/#dnsand click the Lookup button, entering the domain in the field next to it. The result shows whether the record is in the browser cache. - In Firefox, open
about:networking#dns. The table shows all cached names, their addresses, and the remaining lifetime in the Expires column. - To check which IP the application actually used, open
chrome://net-internals/#socketsin Chrome: you'll see open sockets and destination addresses there.
Verification: by the end of this step you should have a four-row table: the address from the authoritative server, from the system resolver, from getent, and from the browser. A discrepancy between neighboring rows points to the layer where the record is stuck.
Possible issues
- dig isn't installed. Go back to the prep section and install the dnsutils or bind-utils package. As a temporary workaround you can use
nslookup example.com, but it won't show TTL. - resolvectl reports a bus connection error. That means systemd-resolved isn't running and the system uses a different resolver. Check the contents of /etc/resolv.conf: if it's not 127.0.0.53, look for nscd or dnsmasq in Step 2.
- All answers are the same, but the site still behaves oddly. The connection pool or the cache on the proxy side is likely to blame. That's covered in Step 5.
Tip: the +noall +answer flag on dig trims extra output and leaves just the answer. Add an alias to your shell profile, e.g. alias d='dig +noall +answer', and diagnostics will go twice as fast.
Step 2: Flushing the System DNS Cache on Linux, Windows, and macOS
Goal of this stage: clear the operating system cache so that the next query from any application is guaranteed to go out to the network.
Linux: systemd-resolved
On Ubuntu, Fedora, Debian with default settings, and most modern 2026 distributions, resolution is handled by systemd-resolved. Confirm it with systemctl is-active systemd-resolved: an active response confirms it.
- Look at the cache stats before flushing:
resolvectl statistics. In the Cache block you'll see Current Cache Size, Cache Hits, and Cache Misses. Note down the Current Cache Size value. - Flush the cache:
sudo resolvectl flush-caches. The command outputs nothing, which is normal. - Run
resolvectl statisticsagain. The Current Cache Size value should be zero. - Flush the negative cache too if you added a new domain. There's no separate command: flush-caches clears everything at once, including negative records.
- Verify:
resolvectl query example.comshould now show Data from: network at the end.
Alternative approach if resolvectl is unavailable: sudo systemctl restart systemd-resolved. Restarting takes less than a second and also clears the cache, but briefly interrupts resolution for all programs. In interactive work that's unnoticeable, but on a loaded server flush-caches is better.
Linux: nscd
The nscd service caches not only DNS but also users, groups, and other data from /etc/nsswitch.conf. It shows up in older installs, in some server images, and where it was set up deliberately. Check its presence: systemctl is-active nscd.
- Flush just the hosts table without touching the rest:
sudo nscd -i hosts. The -i flag means invalidate. - If the command is unavailable, restart the service:
sudo systemctl restart nscd. - Verify the result via
getent hosts example.com. getent goes through nscd, while dig bypasses it.
Warning: nscd has its own TTL settings in /etc/nscd.conf, and they can be larger than the DNS record TTL. The line positive-time-to-live hosts 3600 means nscd will hold the address for an hour even if the domain owner set TTL to 60 seconds. This is one of the most common reasons why on servers the old address lives longer than expected. We'll come back to this in Step 6.
Linux: dnsmasq
dnsmasq often serves as a local caching resolver on routers, in container environments, and in old NetworkManager versions. The sign: /etc/resolv.conf points to 127.0.0.1 or 127.0.1.1, and the command pidof dnsmasq returns a process ID.
- Flush the cache via signal:
sudo kill -HUP $(pidof dnsmasq). The HUP signal makes dnsmasq reread its config and clear the cache. - Or restart the service:
sudo systemctl restart dnsmasq.
Windows 11
- Press the Windows key, type cmd, right-click the Command Prompt item, and select Run as administrator.
- Run
ipconfig /displaydnsto see the cache contents. The list can be long: scroll or filter it throughfindstr. - Flush the cache:
ipconfig /flushdns. You should see the message Successfully flushed the DNS Resolver Cache. - PowerShell alternative:
Clear-DnsClientCacheto flush andGet-DnsClientCacheto view. The PowerShell option is more convenient for scripts.
If the command says the cache couldn't be flushed, check whether the DNS Client service is running: Get-Service Dnscache. The status should be Running. If the service is stopped, Windows resolves without a cache and the problem definitely isn't here.
macOS
- Open Terminal: Finder, Applications, Utilities, Terminal. Or press Cmd+Space and type Terminal.
- Run
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder. Enter your administrator password when prompted. Both parts are needed: the first clears the directory service cache, the second makes mDNSResponder drop its own cache. - There will be no output. Verify the result:
dscacheutil -q host -a name example.comshould return the fresh address.
Verification: after flushing on any OS, repeat the diagnosis from Step 1. The system resolver should return the address matching the authoritative server's answer, and the TTL on the first query should be the maximum for that record.
Possible issues
- After flushing, the address is still old. Check the hosts file: on Linux and macOS it's /etc/hosts, on Windows it's C:\Windows\System32\drivers\etc\hosts. An entry there fully overrides DNS. Also check the upstream resolver cache: if
dig @1.1.1.1also returns the old address, the domain owner's changes haven't propagated yet and you'll have to wait the full TTL. - resolvectl flush-caches worked, but the browser still shows the old thing. That's expected: the browser won't ask the system until its own cache expires. Move on to Step 3.
Tip: systemd-resolved has a Cache=no-negative parameter that disables negative answer caching. For developers who frequently create new domains on test environments, this saves you from endless "name not found" errors right after publishing a record.
Step 3: Clearing the Browser DNS Cache and Connection Pool
Goal of this stage: make the browser forget old addresses and close already-open connections to the old server so a new query goes through the current resolution and proxy chain.
The browser is the trickiest layer. It caches addresses independently of the system, keeps connections open for speed, and can even resolve names with its own DNS-over-HTTPS client, completely bypassing the OS settings.
Chrome and Chromium-based browsers
- In the address bar, type
chrome://net-internals/#dnsand press Enter. - Click the Clear host cache button. There won't be visual confirmation; the button just works.
- Go to the
chrome://net-internals/#socketstab. - Click Flush socket pools. This button closes all open connections. Without it, the browser will keep sending queries over the already-established channel to the old IP, and flushing DNS won't help.
- Click Close idle sockets there too for good measure.
- Check whether secure DNS is on: open
chrome://settings/securityand find the Use secure DNS option. If it's enabled with a specific provider, Chrome resolves through that provider, and neither the system cache nor system DNS servers are involved at all. For tests where the system resolution matters, temporarily switch the option to the current service provider or disable it. - Open the test site again. Best in a new tab.
Those addresses work in Chrome, Edge, Yandex Browser, Opera, and other Chromium builds in current 2026 versions. In Edge the address starts with edge:// instead of chrome://, otherwise identical.
Firefox
- Type
about:networking#dnsin the address bar. - Click the Clear DNS Cache button at the top of the page. The records table clears immediately.
- Switch to the HTTP tab of the same about:networking page and look at the list of active connections. There's no separate close button, so to flush the connection pool either restart Firefox or toggle offline mode and back: menu, Work Offline, then uncheck it.
- To control cache lifetime, open
about:config, confirm the warning, and find thenetwork.dnsCacheExpirationparameter. The default is 60 seconds. For debugging set it to 0: Firefox will stop caching names. Don't forget to restore the value afterward. - The
network.dnsCacheEntriesparameter sets the maximum number of records, 400 by default. There's no point lowering it, but it's useful to know about. - Check
network.trr.mode: a value of 2 or 3 means Firefox uses DNS-over-HTTPS and the system resolver is partially or fully ignored. For clean system-resolver tests, set it to 0 or 5.
Profile and incognito as an alternative
If you need a quick "clean slate" check, open an incognito or private window. In Chrome the incognito DNS cache is shared with the main window, so this method doesn't guarantee a clean resolution, but in Firefox the private window has its own cache. The most reliable option for both families is a separate browser profile created for testing. The profile starts with empty caches and an empty connection pool.
Verification: after clearing, open chrome://net-internals/#dns and click Lookup for the test domain: the address should match the authoritative server's answer from Step 1. In Firefox the about:networking#dns table should show a new record with the full TTL.
Possible issues
- The Clear host cache button was clicked, but the site loads from the old server. Almost always you forgot Flush socket pools. The connection is already open and doesn't need DNS.
- The site uses HTTP/3 or QUIC. Such connections can survive pool flushes. Temporarily disable QUIC via
chrome://flags/#enable-quic, restart the browser, and retry the test. - An extension or PAC script manages the proxy. The dnsResolve function in PAC files uses the browser cache. If proxy rules depend on the target IP, the old address leads to the old route. Flush the cache and reload the PAC through the system proxy settings.
Tip: bookmark chrome://net-internals/#dns and chrome://net-internals/#sockets on your bookmarks bar. Two clicks instead of typing the address notably saves time during repeated proxy switches.
Step 4: Managing DNS Cache in the JVM and Java Applications
Goal of this stage: understand caching rules in the Java virtual machine, flush the cache on a running application, and tune TTL so that changing a proxy or address is picked up without a restart.
Java applications are notorious for "sticking" to the old IP. The reason is the InetAddress class, which caches resolution results separately from the system. The rules: successful answers are stored for 30 seconds, or indefinitely if the security manager is enabled; negative answers are stored for 10 seconds. In Java 17, 21, and 25 the security manager is disabled and removed in newer versions, so by default you're dealing with 30 seconds. But many server applications override these parameters in their config, and that's where you encounter values in hours or even infinity.
Checking current settings
- Find the java.security file. In JDK 17 and newer it lives in
$JAVA_HOME/conf/security/java.security. On Windows the path looks likeC:\Program Files\Java\jdk-21\conf\security\java.security. - Open the file and find the lines
networkaddress.cache.ttlandnetworkaddress.cache.negative.ttl. By default the first is commented out, the second is 10. - Check the application's launch parameters: look in scripts and systemd units for the flags
-Dsun.net.inetaddr.ttland-Dsun.net.inetaddr.negative.ttl. These are system properties acting as a fallback if security properties aren't set. - Check the application code for
Security.setPropertycalls with these keys: the code can override everything you configure externally.
Configuring TTL
- Make a backup:
sudo cp $JAVA_HOME/conf/security/java.security $JAVA_HOME/conf/security/java.security.bak. - Open the file in an editor with admin rights and uncomment or add the line
networkaddress.cache.ttl=10. A value of 10 seconds is a reasonable compromise for applications that must react quickly to address changes. A value of 0 disables the cache entirely: every resolution goes to the system. A value of -1 enables indefinite caching and doesn't suit our tasks. - If needed, reduce the negative cache:
networkaddress.cache.negative.ttl=0. Useful on environments where domains appear on the fly. - If you don't want to touch the global JDK file, create your own, e.g.
/etc/myapp/java.security.override, with two parameter lines, and hook it in at launch with the flag-Djava.security.properties=/etc/myapp/java.security.override. This overrides only the specified properties, leaving the rest standard. - The fastest option without editing files: add
-Dsun.net.inetaddr.ttl=10 -Dsun.net.inetaddr.negative.ttl=0to the launch parameters. Remember that these properties are lower priority than properties from java.security if those are explicitly set. - Restart the application so the new parameters take effect.
Warning: setting TTL to 0 on a high-load service sharply increases the number of DNS queries: every new connection will resolve the name. For production systems pick 10–60 seconds, and leave zero for debugging environments.
Flushing the cache without restarting
There's no public method to clear the InetAddress cache in the JDK. However, there are workable approaches.
- Wait for TTL to expire. At the default 30 seconds this is faster than any manipulation. Check that nobody set -1.
- Use a custom resolver. Starting from Java 18 there's an InetAddressResolverProvider interface through which an application can plug in its own resolution implementation with any caching logic and an explicit flush method. This is an advanced path for those who control the code.
- Check the address via JShell. For diagnostics, launch
jshelland runInetAddress.getByName("example.com"). This shows the address the JVM itself returns with the current settings, independent of the system.
Connection pools in Java
As with the browser, Java clients have pools: the standard library's HttpClient, Apache HttpClient, OkHttp, database drivers. Even after flushing DNS, a connection to the old IP will remain in the pool until it closes by idle timeout. If the application must switch to the new address immediately, configure a short idle timeout on the pool or call pool closure from an admin endpoint if one exists.
Verification: launch the application with the new parameters, change the test domain's A record or reconfigure hosts, wait for the configured TTL plus a couple of seconds, and confirm through logs or jshell that the application got the new address.
Tip: in containers based on Eclipse Temurin and similar images the java.security file lives in the standard path, but rebuilding the image for two lines is inconvenient. Use the JAVA_TOOL_OPTIONS environment variable with the needed -D flags: the JVM picks them up automatically at startup without changing the launch command.
Step 5: Handling Caches in Other Runtimes, Utilities, and on the Proxy Side
Goal of this stage: cover the remaining places where the old address might hide: Python, Node.js, and Go libraries, the curl utility, web servers, and also understand when resolution actually happens not on your side but on the proxy.
Python, Node.js, Go
Good news: the standard libraries of these languages don't have their own DNS cache. Python via the socket module, Node.js via dns.lookup, and Go via the net package by default call the system resolver through the getaddrinfo function. So for them Step 2 is enough. There are nuances.
- Node.js. Some libraries, e.g. cacheable-lookup used by popular HTTP clients, add their own cache. Look for them in the project dependencies and configure the maxTtl parameter. Node.js also has the dns.Resolver class, which talks to DNS servers directly, bypassing the system resolver: then the system cache isn't involved, but getent won't help you diagnose either.
- Go. When built with CGO_ENABLED=0, Go uses its own pure resolver, which reads /etc/resolv.conf and /etc/hosts but doesn't go through nscd and systemd-resolved via NSS. It has no cache, but http.Transport holds a keep-alive connection pool. To force reconnection, call CloseIdleConnections.
- Python. The requests library with the default adapter reuses connections within a session. Create a new session after changing the proxy or close the old one via the close method.
curl
curl has flags that help test without cache influence.
curl -v https://example.com/— in the verbose output the line Trying 93.184.215.14:443 shows which IP the connection actually goes to.curl --resolve example.com:443:203.0.113.10 https://example.com/— substitutes the desired address for the name, completely bypassing DNS. Invaluable when testing a new server before changing the record.curl --dns-servers 1.1.1.1 https://example.com/— forces resolution through the specified server, bypassing the system cache. Works only if curl is built with the c-ares library; check thecurl -Voutput for the word AsynchDNS.
nginx and other web servers
nginx resolves names in the proxy_pass directive once at startup and holds the address forever if the name is written statically. To make addresses update, set resolver 127.0.0.53 valid=30s; in the http or server block and use a variable in proxy_pass: then nginx will re-resolve the name every 30 seconds. Similar mechanisms exist in HAProxy and Envoy. If you changed the backend address and nginx keeps going to the old one, reload the config: sudo nginx -s reload.
Where the resolution actually happened: locally or on the proxy
This point connects our guide to the remote resolution topic without delving into it. A quick way to figure out who resolved the name is to look at the client's verbose output.
- Run
curl -v -x http://user:pass@proxy.example:8080 https://example.com/. If the output shows the line CONNECT example.com:443 HTTP/1.1 and no line showing a connection attempt to the target site's IP, the name went to the proxy as text, and the proxy resolved it. Your local caches weren't involved here, but the cache on the proxy side or its resolver's might have been. - Run
curl -v -x socks5://user:pass@proxy.example:1080 https://example.com/. In this case curl resolves the name locally and you'll see the target IP in the output. Here your caches from Steps 2–4 play their full role. - The socks5h scheme passes the name to the proxy. Details and privacy implications are covered in a separate article about DNS through a proxy; for our task it's enough to remember the rule: if the name resolves on the proxy, you don't flush local caches — you wait for the TTL on the proxy side or change the proxy server.
Verification: for each tool you use you should be able to say where resolution happens and whether the tool has its own cache or pool. Write it in your journal as a table: tool, resolution location, cache presence, flush command.
Tip: when changing proxies in mobile proxy services, the exit node IP can change on a schedule or via an IP change link. Your DNS cache doesn't flush in the process. If you're testing how a site reacts to different exit addresses, be sure to close the connection pool after each switch, otherwise the old connection will keep going through the previous channel.
Step 6: Tuning TTL and Automating Flushes
Goal of this stage: make caches stop getting in your way constantly: set reasonable record retention limits and prepare a script that flushes all layers with one command.
Limiting the systemd-resolved cache
- Create the overrides directory if it doesn't exist:
sudo mkdir -p /etc/systemd/resolved.conf.d. - Create the file
/etc/systemd/resolved.conf.d/cache.confwith the contents: line[Resolve], thenCache=yes, thenCacheFromLocalhost=no. If you want to fully disable the cache while debugging, replace the first directive withCache=no. - Restart the service:
sudo systemctl restart systemd-resolved. - Verify it applied:
resolvectl statusshows the current parameters. systemd-resolved has no separate maximum TTL parameter; the service respects record TTLs but not above an internal ceiling. For most tasks this is enough.
Limiting the nscd cache
- Make a backup:
sudo cp /etc/nscd.conf /etc/nscd.conf.bak. - Open /etc/nscd.conf and find the hosts block. Set
positive-time-to-live hosts 60andnegative-time-to-live hosts 5. This limits address retention to a minute and errors to five seconds. - If you need nscd only for users and groups but not for DNS, set
enable-cache hosts no. Then name resolution goes directly to the system resolver. - Restart the service:
sudo systemctl restart nscd.
Full flush script for Linux
Create the file ~/bin/dnsflush.sh and make it executable with chmod +x ~/bin/dnsflush.sh. Script contents line by line:
- The first line declares the interpreter:
#!/usr/bin/env bash. systemctl is-active --quiet systemd-resolved && sudo resolvectl flush-caches && echo "resolved: ok"systemctl is-active --quiet nscd && sudo nscd -i hosts && echo "nscd: ok"pidof dnsmasq >/dev/null && sudo kill -HUP $(pidof dnsmasq) && echo "dnsmasq: ok"resolvectl statistics 2>/dev/null | grep -i "Current Cache Size"
The script checks which services are active and flushes only those. Run it after every proxy or address change.
Script for Windows
Create the file dnsflush.ps1 with two lines: Clear-DnsClientCache and Get-DnsClientCache | Measure-Object | Select-Object -ExpandProperty Count. The second line prints the record count after flushing, which should be zero or close to it. Run it from PowerShell as administrator. If the system blocks script execution, allow it for the current user: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned.
Script for macOS
Create the file dnsflush.sh with the line sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder; echo "macOS DNS cache flushed". Make it executable via chmod and run it from Terminal.
Test browser profile with the cache disabled
For Chrome, create a launch shortcut with the parameters --user-data-dir=/tmp/chrome-test --host-resolver-rules="MAP example.com 203.0.113.10". The first flag creates a separate clean profile, the second hard-maps the name to the address for the session, which is handy when testing a new server. For Firefox, create a separate profile via about:profiles and set network.dnsCacheExpiration to 0 in it.
Verification: run your flush script, then immediately execute resolvectl query example.com or the equivalent for your OS. The data source should be network, and the cache statistics record count should be zero.
Tip: if you switch proxies frequently within one work session, bind the flush script to a hotkey through your desktop environment's settings. One keypress instead of three commands notably reduces the risk of forgetting a layer.
Verifying the Result: Checklist and Full Test Scenario
Let's run the final test that confirms you control all layers. It takes about 10 minutes.
Checklist
- You know which system resolver is used on your machine and can flush its cache with one command.
- You can view record TTL via dig or Resolve-DnsName and understand where the answer comes from: cache or network.
- You flush the browser DNS cache and connection pool and know that without the second the first is useless.
- Your Java applications launch with an explicitly set networkaddress.cache.ttl, not the defaults.
- You have a full flush script for your OS.
- You can determine with a single curl command whether a name resolves locally or on the proxy.
Full test scenario
- Add a line with the test domain and a deliberately wrong address to the hosts file, e.g. 203.0.113.99. This simulates the "old" address.
- Open the domain in the browser and confirm the connection isn't established or goes to the fake address. Check via chrome://net-internals/#dns that the record got cached.
- Remove the line from hosts.
- Refresh the page without flushing anything. Expected: the browser keeps using the fake address. This demonstrates the problem.
- Run your system cache flush script.
- Refresh the page again. Expected: still the old address, because the browser cache is untouched.
- Do Clear host cache and Flush socket pools.
- Refresh the page. Expected: the site opens from the correct address. This confirms you understand the order of layers.
- Repeat steps 1–8 with jshell instead of the browser if you work with Java, observing the TTL effect.
Success indicators
Each layer behaves predictably, you can say in advance what result the next query will give, and no surprises arise after changing the proxy. If a result differs from expectations at any step, go back to the diagnostics section and find the layer you missed.
Common Mistakes and Fixes
Flushed the system cache, but the browser still shows the old site
Cause: the browser has its own DNS cache and open connections. Fix: Clear host cache plus Flush socket pools in Chrome, Clear DNS Cache plus restart in Firefox. Check whether DNS-over-HTTPS is on in the browser: then the system resolver isn't involved at all.
The Java application holds the old IP for hours
Cause: java.security or launch parameters have networkaddress.cache.ttl=-1, or the application sets it in code. Fix: find and change the value to 10–60 seconds, restart the application. Also check the HTTP client pool: connections to the old IP live until the idle timeout.
The resolvectl command isn't found or won't connect
Cause: the system doesn't use systemd-resolved. Fix: look at /etc/resolv.conf. The address 127.0.0.1 points to dnsmasq or another local cache; ISP addresses mean there's no local cache. Act according to the relevant subsection of Step 2.
The new domain doesn't resolve even though the record is already published
Cause: the negative cache remembered the answer that the name doesn't exist. Fix: flush the system cache, in systemd-resolved add Cache=no-negative, in the JVM set networkaddress.cache.negative.ttl=0. Verify the record is visible from the authoritative server via dig with the server specified.
getent shows one address, dig shows another
Cause: there's a hosts file or nscd with its own TTL between them. Fix: check /etc/hosts and /etc/nsswitch.conf, flush nscd with the nscd -i hosts command, and if needed limit positive-time-to-live in nscd.conf.
After changing the IP on a mobile proxy, the site still sees the old exit address
Cause: not DNS but a live connection: the browser or client keeps working through the already-open TCP channel via the previous path. Fix: close the connection pool, disable QUIC while testing, and for scripts create a new session after each switch.
curl through socks5 shows the local target IP, but through http proxy it doesn't
Cause: in the socks5 scheme without the h suffix the name resolves locally, in HTTP CONNECT it resolves on the proxy. This is normal behavior, not an error. Fix: understand where resolution happens and flush the corresponding cache; details are in the separate article about remote resolution.
Windows says it failed to flush the cache
Cause: the command prompt was launched without admin rights, or the Dnscache service is stopped. Fix: restart the terminal as administrator; check the service status via Get-Service Dnscache and start it if needed.
Advanced Techniques
Real-time cache monitoring
On Linux, the command sudo resolvectl monitor prints all DNS queries passing through systemd-resolved, marking whether a query went out to the network. Run it in a separate window and switch proxies in the browser: you'll see with your own eyes which queries the browser makes and which it takes from its own cache without reaching the system. This is the most illustrative way to understand the layered nature of caches.
Network namespaces for clean tests
With ip netns you can create an isolated network namespace with its own resolv.conf and no shared caches. Running a browser or curl inside such a namespace guarantees that no system cache affects the result. Setup requires experience, but for regular comparative tests through different proxies it pays off handsomely.
Logging resolution in the JVM
The flag -Djava.net.preferIPv4Stack=true simplifies diagnostics by removing IPv6 from the equation, and the -Xlog:net flag in newer JDK versions helps you see network events. For deeper analysis, use Java Flight Recorder with network I/O events.
Your own caching resolver
If you manage a server and want centralized TTL control for all applications, stand up a local Unbound or Knot Resolver with cache-max-ttl and cache-min-ttl parameters. Then system applications get predictable behavior regardless of what the domain owner set. Note that lowering TTL against the domain owner's wishes is a debatable practice; apply it only on test environments.
Automatic flush on proxy switch
If you switch proxies with a script, add a call to the flush script from Step 6 at the end of the switching routine. For the browser, automating button clicks is harder: use separate profiles per configuration or launch the browser with the --host-resolver-rules flag, which makes the cache predictable.
FAQ: Common Questions About DNS Cache and Flushing
Do I need to reboot my computer after flushing the cache?
No. All commands in the guide take effect immediately. Rebooting also flushes caches, but it's the slowest way, and it won't help if the issue is in TTL on the nscd side or a JVM with indefinite caching: after a reboot they'll cache the first answer again.
How do I find out my domain's TTL?
Run dig with the authoritative server specified: dig @ns1.yourserver domain A +noall +answer. The second field in the answer is the full TTL. The answer from a regular resolver shows the remaining time, which decreases every second.
Can flushing the cache harm my system?
No. The cache is temporary storage, and the system will refill it. The only side effect is a brief slowdown of the first access to each site. Only fully disabling resolver services is harmful, and we're not doing that.
Why doesn't Chrome have a separate DNS cache TTL like Firefox?
Chrome respects the record TTL but caps positive answers at 60 seconds, and doesn't allow changing this via settings. You can only control it by clearing via net-internals or launch flags like --host-resolver-rules.
How do I flush the DNS cache in a Docker container?
By default a container has no caching resolver of its own and talks either to Docker's built-in DNS at 127.0.0.11 or to the servers from the host's resolv.conf. Docker's built-in DNS caches little. If the application inside the container is Java, configure the JVM. If you need to flush the host cache, do it on the host.
What if the domain's TTL is a day but I need to test a new address now?
Don't wait: use curl with the --resolve flag or Chrome with the --host-resolver-rules flag, or temporarily add a record to hosts. All three bypass DNS and let you test the new server immediately. Don't forget to remove the hosts entry after testing.
Does changing the proxy affect the DNS cache at all?
Not directly. None of the caches we covered track proxy settings. The only indirect effect: if resolution happens on the proxy, then with a new proxy you also get its cache, so the answer may differ. But local caches remain as they were.
How do I know the old record is held by the ISP, not by me?
Query a public resolver directly: dig with the server 1.1.1.1 or 8.8.8.8 specified. If the answer matches the authoritative server, but the system resolver gives a different one, the problem is on your machine. If public resolvers also give the old address, the changes haven't propagated yet and you have to wait for the TTL.
Do I need to change anything on my smartphone when testing through mobile proxies?
This guide doesn't cover the smartphone as a proxy traffic source; you work with it as a remote node. As for the device you're testing from, all the layers described apply. If you're testing from a phone, toggle airplane mode for a few seconds: this flushes the system DNS cache on iOS and Android, and restart the phone's browser.
Conclusion
Let's wrap up. You've understood that name resolution and proxy operation are different layers, and that changing the proxy doesn't have to change the resolution result. You've learned to diagnose the problem in four commands by comparing answers from the authoritative server, the system resolver, a library call, and the application. You can flush the cache of systemd-resolved, nscd, dnsmasq, the Windows DNS Client service, and macOS mDNSResponder. You clear the browser DNS cache and connection pool, manage JVM TTL via java.security and system properties, and know where caches hide in curl, nginx, and popular libraries. And most importantly — you have a script that does all of this with one command.
What to do next. Build the habit: changed the proxy or address — run the flush, close the connection pool, verify with dig. In a week it'll be automatic, and the problem "changing proxy doesn't change resolution" will cease to exist for you.
Where to grow. The next logical step is the article about DNS through a proxy and remote resolution: there you'll learn how to make names resolve on the proxy side and what consequences that carries. Then it's worth studying DNS-over-HTTPS in browsers and systems, because this mechanism is increasingly intercepting resolution from the operating system. And finally, mastering Linux network namespaces will give you a tool for absolutely clean comparative tests. Good luck, and may your records always update on time.