DNS & Domain Names

DNS Spoofing and Cache Poisoning

Understand how forged DNS answers redirect users, which defenses stop them and what warning signs to check on your own network.

Key takeaways

  • A poisoned cache can redirect many users at once without touching their devices or the real website.
  • Resolvers defend themselves by randomizing query details and refusing data that a server has no authority to give.
  • DNSSEC lets a resolver reject forged records outright for domains that are signed.
  • Many redirections happen closer to home, through a compromised router or altered settings on one device.

DNS spoofing means giving a device a false answer to a name lookup so it connects to the wrong place. Cache poisoning is the version that sticks: the false answer lands in a resolver's cache and is then served to everyone who uses that resolver until it expires.

Modern resolvers are far harder to poison than older ones, and HTTPS means a redirected visitor usually sees a certificate warning instead of a convincing copy of your bank. The practical defenses are keeping resolvers and routers updated, validating DNSSEC, encrypting the path to your resolver and taking certificate warnings seriously.

Why DNS can be fooled

A recursive resolver looks up names for its users by asking other servers. Classic DNS uses UDP, where there's no handshake. The resolver sends a question and waits for a reply that matches what it asked.

Originally, "matching" meant little: the right server address and port, the same question and a 16-bit transaction ID. The reply carried no proof of origin. Someone who could guess or observe those values could send a fake reply that arrived before the real one. The resolver would accept the first plausible answer and ignore the genuine one that followed.

Caching amplifies the damage. An accepted answer is reused for its whole TTL, which the forger chooses. DNS caching and time to live explains how long copies last.

Where false answers come from

Redirection can happen at several points, and they need different defenses.

Where How the answer is altered Main defense
Resolver cache Forged replies accepted from the network Updated resolver software and DNSSEC
Network path Someone between you and the resolver rewrites traffic Encrypted DNS
Home or office router Its DNS settings are changed by an intruder Strong admin password and firmware updates
Individual device Malware edits settings or the hosts file Security updates and scanning
Domain account The real records are changed at the source Registrar and DNS account security

The last row isn't spoofing in the strict sense, because the answers are authoritative. It's often the more damaging case, covered in domain hijacking.

Places a lookup can be subverted, from your screen outward
Your device Altered DNS settings, hosts file entries or malicious software. Your router Changed DNS servers redirect every device behind it. The network path Unencrypted queries can be read and rewritten. The recursive resolver A forged reply in its cache affects all of its users. The domain's accounts Stolen logins change the real records. Your device Altered DNS settings, hosts file entries or malicious software. Your router Changed DNS servers redirect every device behind it. The network path Unencrypted queries can be read and rewritten. The recursive resolver A forged reply in its cache affects all of its users. The domain's accounts Stolen logins change the real records.

How resolvers raised the bar

In 2008, security researcher Dan Kaminsky disclosed a technique that made poisoning far more practical against many resolvers of the time. Vendors responded with coordinated updates.

The central fix was source port randomization: sending each query from an unpredictable port, so a forger has to guess the port as well as the transaction ID. The number of combinations grows from tens of thousands to billions. RFC 5452 describes measures for making resolvers resilient to forged answers.

Other protections include:

  • Bailiwick checking. A resolver ignores records about names that the answering server has no authority over.
  • DNS cookies, defined in RFC 7873, which let client and server recognize each other and discard off-path forgeries.
  • Random capitalization of the queried name, which some resolvers use as extra unpredictability, since replies echo it.
  • Falling back to TCP when something looks suspicious, because forging a TCP conversation blindly is much harder.

These raise the cost of guessing. None of them helps against someone who can read the query in transit.

Why poisoning is worth an attacker's effort

One successful forgery in a shared resolver reaches every customer who asks for that name afterward. The website itself is untouched, so its owner sees nothing in their logs except fewer visitors. The users did nothing wrong either: they typed the correct address.

The possible uses follow from that. A forged address record can send visitors to a lookalike server. A forged mail record can divert messages. A forged answer for a software update server can try to feed users something else, which is why well-designed update systems verify signatures on the files themselves and don't trust the name alone.

Poisoning also has limits. It lasts only as long as the cache entry, affects only users of that resolver and doesn't give access to the real server. That narrower, temporary reach is one reason many attackers prefer simpler routes, such as phishing or taking over an account.

Spoofing on a local network

On a shared local network, a hostile device may not need to poison anything upstream. If it can place itself between you and the router, or answer your query before the real server does, it can supply false results to you alone. Other local name lookup protocols used to find nearby devices are similarly trusting, since they accept answers from whoever responds.

Defenses here belong to the network and the device. Managed switches can restrict which ports may act as DHCP or DNS servers and can check address resolution messages. Guest networks should isolate clients from one another. On your own device, avoid sensitive work on networks you don't trust, or send traffic through a VPN you control or have reason to trust. Disable legacy local name lookup features in managed environments where nothing depends on them.

Rogue configuration is the quieter risk

Many real redirections involve no clever forgery. A router with a default password gets its DNS servers changed. A piece of unwanted software edits the computer's resolver settings. A malicious network hands out a resolver of its own through DHCP, the service that configures devices when they join.

Signs include unexpected advertisements, search results from an unfamiliar engine, certificate warnings on sites that normally work and resolver addresses you don't recognize. None is conclusive alone. Together they justify a careful look at the router and the device, including the hosts file.

DNSSEC: proof instead of luck

DNSSEC attaches signatures to records. A validating resolver checks them against a chain of trust that begins at the root zone. A forged record can't carry a valid signature without the zone's private key, so the resolver rejects it.

The protection applies only when both sides participate: the domain must be signed and the resolver must validate. DNSSEC explained covers how to check each.

Encrypting the first hop

DNS over TLS and DNS over HTTPS wrap your queries in an authenticated, encrypted connection to the resolver. A person on the same Wi-Fi can't read or rewrite them. This doesn't help if the resolver itself has bad data, or if your device has been told to use a hostile resolver over an encrypted channel. See DNS over HTTPS and DNS over TLS.

What HTTPS catches

Suppose a forged answer sends your browser to a server the attacker controls. For an HTTPS site, that server needs a certificate valid for the name. Without one, the browser shows a warning and, for sites using HSTS, refuses to let you click through. HSTS explains that rule.

This is a strong safety net with gaps. People may type an address without HTTPS, older or poorly written applications may skip certificate checks and an attacker who controls a domain's DNS for long enough may be able to obtain a certificate. Certificate Transparency logs help owners notice unexpected certificates, as described in certificate transparency.

A familiar site looks wrong or throws a certificate warning
Does it happen only on this one device? YES Check its DNS settings and hosts file, then scan it. 1 NO Does it happen on every device on this network only? YES Check the router's DNS servers, update firmware and change its admin password. 2 NO Does it disappear when you use a different resolver? YES Report it to the operator of the original resolver or network. 3 NO Treat it as the site's problem Do not click through or sign in. Contact the owner through a channel you already trust. Does it happen only on this one device? 1 IF YES Check its DNS settings and hosts file, then scan it. NO Does it happen on every device on this network only? 2 IF YES Check the router's DNS servers, update firmware and change its admin password. NO Does it disappear when you use a different resolver? 3 IF YES Report it to the operator of the original resolver or network. NO Treat it as the site's problem Do not click through or sign in. Contact the owner through a channel you already trust.

Checking your own setup

To see which resolvers your computer uses:

# Windows
Get-DnsClientServerAddress
ipconfig /all
# Linux with systemd-resolved
resolvectl status

# macOS
scutil --dns

Compare the addresses with what you expect: your router, your provider or a resolver you chose. Log in to the router and confirm its DNS settings too. Then compare answers from your resolver and from another.

dig www.example.com +short
dig @9.9.9.9 www.example.com +short

Different addresses aren't proof of tampering. Large sites hand out different servers by location, and filters intentionally rewrite answers. Look for a certificate mismatch or an address that makes no sense.

Hardening checklist

For households. Change the router's default admin password, install firmware updates, turn off remote administration unless you need it and replace routers that no longer receive updates. Updating router firmware shows how.

For organizations running resolvers. Keep resolver software current, confirm source port randomization isn't undone by an address translation device in front of it, enable DNSSEC validation, don't offer recursion to the whole internet and monitor for odd changes in answers.

For domain owners. Sign your zone if your provider automates it well, protect registrar and DNS accounts with strong multi-factor sign-in, serve everything over HTTPS with HSTS and watch certificate logs for names you own.

If you suspect poisoning

Stop entering passwords on the affected connection. Switch to a different network, such as mobile data, and see whether the problem follows. Record the answers you're getting with timestamps. Flush your caches and check the router. If you run the resolver, flush it, update it and review logs. If you entered credentials on a page that now seems doubtful, change them from a clean connection and review account activity.

Spoofing of this kind is one form of man-in-the-middle attack, and the same habit protects you from many of them: when your browser says it can't verify who you're talking to, believe it.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in DNS & Domain Names →

Latest news on this topic