How Can You Identify DNS Leaks in a Linux Network Namespace?
A Linux network namespace has its own interfaces, routes and often its own resolver settings. Learn how to check where DNS questions really go from inside one, and what to change when they go the wrong way.
10 min readUpdated Nov 11, 2026By XPASS Editorial Team

A network namespace is a separate copy of the Linux network stack. Inside it you get your own interfaces, your own routing table, your own firewall rules and your own loopback. People use namespaces to keep one application behind a VPN tunnel while the rest of the computer uses the normal connection, to test a configuration without touching the host, or simply because a container runtime or a service manager created one for them. The idea is neat, but it adds a trap that catches careful people: the route to the internet and the route your DNS questions take are two different things, and a namespace separates them even more sharply than a normal desktop does.
This article shows how to check, step by step, whether DNS questions from inside a namespace go where you think they go. It covers how a namespace finds its resolver, how to read the evidence from inside and outside, what the common leak patterns look like, and how to fix them without making your system worse. It is a general Linux guide. If you want the broader host-level version first, read how to test and fix DNS leaks on Linux and the explanation of what a DNS leak is.
What a network namespace does and does not isolate
A namespace isolates the things the kernel keeps in its network stack. That list is specific, and knowing it makes the rest of the article easy to follow.
- Interfaces. A new namespace starts with only a loopback interface, and it is down. Any other interface, such as a virtual Ethernet pair end or a WireGuard device, has to be moved or created there.
- Addresses and routes. The routing table is private. A default route in the host does not exist in the namespace unless you add one.
- Firewall rules. nftables and iptables rules in the namespace are separate from the host rules.
- Sockets and ports. A program listening on a port in one namespace is invisible from another.
What a namespace does not isolate on its own is the file system. The list of resolvers lives in /etc/resolv.conf, which is an ordinary file, and unless something swaps it, a program inside a namespace reads the same file as a program outside. That single fact explains most namespace DNS leaks and most namespace DNS failures. The routing table in the namespace may be perfect, with every packet heading into a tunnel, while the resolver list still says "ask the home router", or "ask 127.0.0.53", an address that means something completely different from inside.

How a command inside a namespace finds its resolver
The common way to run something in a namespace is ip netns exec NAME command. This tool does one helpful thing for DNS. Before it runs your command, it checks for a directory called /etc/netns/NAME/. For each file in that directory, it makes the file appear in place of the matching file in /etc. So if /etc/netns/NAME/resolv.conf exists, your command sees it as /etc/resolv.conf. If it does not exist, the command sees the host's file.
This gives three typical situations.
- No per-namespace file. The command reads the host's resolver list. On many desktops that is
nameserver 127.0.0.53, the systemd-resolved stub. Inside the namespace,127.0.0.53refers to the namespace's own loopback, where nothing is listening, so lookups time out. Some people respond by pointing the file at the router address, for example192.168.1.1, which then leaks if the namespace can reach the home network. - A per-namespace file that names a resolver reachable through the tunnel. This is the setup you want. Lookups travel through the same path as the rest of the namespace's traffic.
- A per-namespace file that names a public resolver and the namespace has a route to it outside the tunnel. Lookups work, but they leave through the normal network. That is a leak even though everything looks fine.
A caution: other tools start processes in namespaces in other ways. A container runtime, a systemd service with a private network setting, or a program that calls setns directly may not use the /etc/netns convention at all. Always check what the process itself reads rather than assuming. Section "Check the resolver the process actually uses" below shows how.
Step 1: list what exists
Start from the host and look at the situation before you test anything.
- Run
ip netns list. This shows the namespaces created with the standard tooling. Namespaces created by other tools may not be listed by name, so treat an empty result with some caution. - Run
ls /etc/netns/and, for each name,cat /etc/netns/NAME/resolv.confif it exists. - Run
sudo ip netns exec NAME ip addrto see the interfaces and addresses inside. - Run
sudo ip netns exec NAME ip routeto see the routes. Note the default route and which device it uses. - Run
sudo ip netns exec NAME cat /etc/resolv.confto see what a command inside actually reads.
Write the answers down in a small table. You want to be able to say, in one sentence each, which device carries the default route, which resolver address is configured, and whether that address is reachable through that device.
Step 2: test the route before you test DNS
DNS is a set of packets like any other. If the route to the resolver is wrong, the DNS path is wrong. So begin with the route.
Run sudo ip netns exec NAME ip route get 1.1.1.1, replacing the address with the resolver address from the file. The output names the device the kernel would use. If the resolver is, say, a private address that is only reachable inside a tunnel, the device should be the tunnel interface. If you see the veth pair that connects the namespace to the host, the packet is heading to the host, and the host will forward it according to its own rules. That could be through the tunnel, or it could be straight out of the physical interface. Follow it one more step in the host with ip route get and the source address of the namespace.
A short example makes this concrete. Suppose a namespace called work has a veth device veth-ns with address 10.200.0.2 and a default route through 10.200.0.1, which is the host end. The host forwards and translates this traffic out of the physical interface wlp3s0, and there is no tunnel in the path at all. The namespace's DNS file says nameserver 192.168.1.1. Every lookup goes out wlp3s0 to the router, in the open. Nothing in the namespace looks broken, yet the namespace is not protected. This is the pattern that the evidence in the next step will expose.
Step 3: capture the evidence
A configuration file tells you what should happen. A capture tells you what does happen. You need two vantage points, one inside and one outside.
Open three terminals.
In the first, capture on the host's physical interface:
sudo tcpdump -ni wlp3s0 'udp port 53 or tcp port 53'
In the second, capture inside the namespace, on all of its interfaces:
sudo ip netns exec work tcpdump -ni any 'udp port 53 or tcp port 53'
In the third, run a lookup from inside the namespace for a name you have not visited recently:
sudo ip netns exec work dig +short example.net
Interpret the two captures together.
- If the inside capture shows the question on the tunnel device and the outside physical capture shows nothing on port 53, the question travelled inside the tunnel. Encrypted tunnel packets will appear on the physical link, but you will not see a readable port 53 query. That is the result you want.
- If the inside capture shows the question on the veth device or any non-tunnel device, and the outside capture shows the same question on
wlp3s0addressed to your router or a public resolver, the question left in the open. That is a leak. - If the inside capture shows nothing at all, the program probably did not use that resolver, or it cached the answer. Flush caches where you can, and use a different name.
- If the lookup times out and nothing appears on the physical link, it is a failure and not a leak. This is common with the
127.0.0.53problem described above.
Two small tips avoid false alarms. Use names unlikely to be cached, such as a fresh subdomain you control or a rarely visited site. And do not rely on a browser-based leak test from inside a namespace unless the browser runs there; that test measures the browser's path and not the shell's.
Check the resolver the process actually uses
The files in /etc are only one source. Programs can have their own idea of DNS, and namespaces make this more important because you may have a different set of programs inside.
- Applications with built-in DNS-over-HTTPS. Some browsers can send their questions through an HTTPS connection to a chosen provider. Those questions go to port 443, not port 53, and your capture above will not show them. If a browser runs in the namespace, check its own network settings and decide deliberately.
- Language runtimes. Some programs ship their own resolver code and read the configuration themselves. They may honour
/etc/resolv.confbut ignore the nsswitch settings thatgetentuses. - Containers. A container started inside a namespace usually gets its own
resolv.confgenerated by the container tool. The file you edited in/etc/netnsdoes not affect it. - System services. A service started with a private network setting is in a namespace that
ip netns listmay not show. Its resolver comes from its own unit configuration.
To look at the real behaviour, run the program under strace for a moment and watch what it opens and connects to, or use ss -tupn inside the namespace to see which remote addresses it contacts. For quick shell checks, getent hosts example.org uses the system resolver path and dig queries the server in the file directly. When the two answer differently, the difference itself is the clue.
Common leak and failure patterns
| What you see | Likely cause | What to try |
|---|---|---|
| Lookups time out; nothing on the physical link | Namespace reads host file with 127.0.0.53 | Create a per-namespace resolv.conf with a reachable resolver |
| Question seen on the physical link to the router | Namespace file names the router or the veth route leads out the physical interface | Change the resolver and the namespace route so both stay in the tunnel |
| Question seen on physical link to a public resolver | Namespace has a route to that address outside the tunnel | Remove the outside route or block it with a firewall rule |
| Works for dig but not for the application | Application uses its own DNS or a container resolver | Check the application settings and its own resolv.conf |
| Works at first, then reverts | Another tool rewrites the file or recreates the namespace | Find which tool manages the file and configure it there |
| Only IPv6 questions leak | The namespace has an IPv6 route outside the tunnel | Route IPv6 through the tunnel or disable it inside the namespace |

Fix: give the namespace its own resolver on purpose
The reliable fix has three parts, and you should do all of them, because each one covers a gap that the others leave.
- Write a per-namespace resolver file. Create the directory with
sudo mkdir -p /etc/netns/workand writenameserver ADDRESSinto/etc/netns/work/resolv.conf, where the address is a resolver that is reachable through the tunnel. Your VPN setup or your administrator tells you which address to use. Do not guess or copy an address from a forum post. Do not point the file at a local stub that does not exist inside the namespace. - Make the namespace route match. The default route in the namespace should go into the tunnel device, and the resolver address should be reachable through it. If the namespace only reaches the internet through the host's veth, the answer to "where does DNS go" is "wherever the host sends it". Check the host with
ip route getand its forwarding or translation rules. - Add a safety net. A firewall rule inside the namespace can drop plain DNS that tries to leave on any device other than the tunnel and loopback. Then a future mistake fails closed rather than quietly leaking. An example in nftables, run inside the namespace:
table inet dnsguard {
chain output {
type filter hook output priority 0; policy accept;
oifname != "wg0" oifname != "lo" udp dport 53 drop
oifname != "wg0" oifname != "lo" tcp dport 53 drop
}
}
Replace wg0 with the name of your tunnel device. Load it with sudo ip netns exec work nft -f dnsguard.nft. When this rule is active and the tunnel is down, DNS stops working inside the namespace. That is the intended behaviour, but it surprises people, so plan for it. Also remember the client still has to find the tunnel endpoint, so use a literal address for the endpoint where you can.
After the changes, repeat the captures from step 3. A fix you have not measured is a hope.
Limits and what to watch for
Be honest about what these checks can prove.
- They show one moment. A clean capture means the lookups you ran just now went the right way. Programs that start later, or after the network changes, may behave differently. Repeat the test after a reboot and after you move between networks.
- They do not cover encrypted DNS. If an application sends questions over HTTPS, port 53 captures stay quiet. That traffic is not necessarily a leak, but you should know it is there and decide whether you want it.
- A tunnel is not a guarantee. A VPN moves traffic through another network and hides your lookups from the local one. It does not make you anonymous, it does not protect against malware, and it does not stop an account or a cookie from identifying you. See what a VPN cannot protect you from for the wider picture.
- Namespaces are not a security boundary by themselves. They separate networking, but they are only one layer. Treat them as a convenience for keeping traffic apart, not as a sandbox for untrusted software.
- Your own tooling matters. This article describes general Linux techniques. It does not say that VPNclient or any other app creates or manages namespaces. If you run the free VPNclient app in the normal way on desktop Linux, apply the same checks from the host and, if you build namespaces yourself, from inside them. If the results surprise you, contact support with what you measured.
A short checklist
Use this list when you are in a hurry.
- Confirm the tunnel is up and carries the namespace default route.
- Read
/etc/netns/NAME/resolv.confand check it is not a loopback stub or the home router. - Run
ip route get RESOLVERinside the namespace and confirm the tunnel device. - Capture on port 53 on the host's physical interface while looking up a fresh name from inside.
- Check IPv6 separately.
- Check applications that carry their own DNS.
- Add the firewall guard and test that lookups fail when the tunnel is down.
- Repeat after a reboot.
For routing questions that sit underneath this, such as why a packet picks one device over another, the article on how the Linux routing table behaves with a VPN is a good companion.
Summary
A network namespace gives you a private routing table but not a private resolver by default. DNS leaks there usually come from a resolver file inherited from the host, a stub address that means nothing inside the namespace, or a route that lets lookups leave through the normal network. Find out which file the process reads, confirm the route to the resolver, capture port 53 from both sides, then fix the file, the route and a firewall guard together, and test again.
If you want to use the free VPNclient app with an XPASS pass on a 64-bit Linux desktop, the Linux setup guide covers installing it, and you can look at the pricing page when you are ready.
Frequently asked questions
Why can a network namespace leak DNS even when the VPN works?
A namespace has its own interfaces and routing table, but the resolver settings it reads are a separate matter. If the namespace inherits the host's /etc/resolv.conf, its DNS questions may be sent to a router address or to a local stub that does not exist inside the namespace, so they either fail or take a different path from the one you intended.
Where does a command run with ip netns exec read its DNS settings?
The ip netns exec command looks for a file named /etc/netns/NAME/resolv.conf and, if it exists, shows it to the command as /etc/resolv.conf. If the file does not exist, the command sees the host's normal /etc/resolv.conf.
Why does 127.0.0.53 not work inside my namespace?
The address 127.0.0.53 is the local listener of systemd-resolved on the host. Each namespace has its own loopback interface, so that listener is not reachable from inside unless you start one there. Point the namespace at a real resolver address instead.
How do I prove a leak instead of guessing?
Capture traffic on port 53 on the host's physical interface while you run a lookup from inside the namespace. If your lookup appears there in plain form, the question left through the normal network and not through the tunnel.
Does VPNclient work with Linux network namespaces?
The article describes general Linux techniques and does not claim that VPNclient has any namespace feature. VPNclient is the free app used with an XPASS pass on 64-bit Intel or AMD desktop Linux with systemd. Check its behaviour with the same tests described here, and contact support if something looks wrong.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Need a VPN for a short trip or a busy month?
XPASS sells prepaid passes for a set number of days. You pay once and nothing renews automatically.
See passesKeep reading

Device Guides
How to Test and Fix DNS Leaks on Linux
Linux has several layers that decide where DNS questions go. Learn to test which one is answering while your VPN is up, and how to fix it on systemd-resolved, NetworkManager and plain resolv.conf.
9 min read

VPN Security
What Is a DNS Leak?
A DNS leak happens when your device asks for website addresses outside the VPN tunnel. Here is why it happens, how to test for it, and what to do about it.
10 min read

Device Guides
Linux VPN Routing Tables Explained
A VPN on Linux is mostly a set of routing decisions. Learn to read ip route, understand the half-default trick and policy tables, and diagnose why traffic goes the wrong way.
9 min read