DNSDNS The internet’s phone book. It turns a name people can remember, like example.com, into the number address computers use to find the server. More about DNS → uses portPort A numbered door on a server. Each service listens behind its own door: web pages on 443, email on others, remote login on 22. More about Port → 53, over both UDP and TCP, while encrypted DNS moves to port 853 or 443. This guide is for anyone running a server, a firewallFirewall A gatekeeper that decides which connections are allowed into a server and blocks the rest. More about Firewall → or a home DNS filter who needs to know which DNS ports to open, why both protocols matter, and how to test that port 53 really answers.
Plain DNS listens on port 53, on both UDP and TCP. Most lookups use UDP; TCP is used for large answers and zone transfers, so never open only UDP 53. Encrypted DNS uses TCP 853 for DNS over TLS, UDP 853 for DNS over QUIC and 443 for DNS over HTTPSHTTPS The secure version of the web, shown by the padlock. Everything sent between you and the site is scrambled so nobody in between can read or change it. More about HTTPS →. Test a server with dig @203.0.113.10 example.com and again with +tcp added.
What port 53 is and why DNS has one
A port number tells a server which program should receive an incoming message. Web serversWeb server The program that answers visitors’ browsers and sends them your website. Also used for the computer it runs on. More about Web server → wait on 80 and 443, SSH waits on 22, and DNS servers wait on 53. The number was fixed in the original DNS specification (RFC 1035) and has not changed since.
Two kinds of DNS server listen on port 53:
- Recursive resolvers, such as your internet provider’s resolver or Google DNS, take a question from your device and chase the answer for you.
- Authoritative nameserversNameserver The server that holds all of a domain’s settings. Whoever runs your nameservers controls where your website and email point. More about Nameserver → hold the real records for a domain and give the final answer.
Both use the same port. The difference is who should be allowed to reach it. For the full journey of a lookup, read how DNS works.
One detail people often miss: port 53 is the port on the server side. Your computer sends its question from a random high-numbered source port (for example 51234) to port 53 on the resolver. That randomness is deliberate. It makes it much harder for an attacker to forge a reply and poison a resolver’s cacheCache A saved copy of something, kept so it does not have to be made or fetched again. Like keeping a printed copy instead of reprinting it for every person who asks. More about Cache →, so you should never pin DNS clients to a fixed source port.
UDP or TCP: why DNS uses both
UDP and TCP are the two main ways of carrying data over the internet. UDP sends a single message with no setup, which is fast. TCP first opens a connection with a short handshake, which costs a round trip but can carry any amount of data reliably.
DNS was designed to use both:
| Situation | Protocol | Why |
|---|---|---|
| Ordinary lookup (A, AAAA, MX, most TXT) | UDP 53 | One small question, one small answer, no handshake needed |
| Answer too big for one UDP message | TCP 53 | The server sets the “truncated” flag and the client retries over TCP |
| Zone transfer between primary and secondary nameservers (AXFR, IXFR) | TCP 53 | A whole zone is far too big for UDP |
| DNSSEC-signed answers and long TXT records (SPF, DKIM) | Often TCP 53 | Signatures and keys make answers large |
Modern DNS uses an extension called EDNS(0) that lets UDP answers grow beyond the old 512 byte limit, so fewer lookups fall back to TCP than in the past. But fallback still happens every day, and RFC 7766 makes TCP support a requirement for DNS software, not an option.
A firewall that allows only UDP 53 looks fine in casual testing, because small lookups work. Then a domain with a long SPFSPF A list you publish saying which services are allowed to send email for your domain. Mail from anywhere else looks suspicious. More about SPF → record, a large DNSSEC answer or a secondary nameserver trying to copy the zone quietly fails. Always open TCP and UDP together.
Encrypted DNS ports: 853 and 443
Plain DNS on port 53 is not encrypted. Anyone on the network path can read which names you look up and, in principle, change the answers. Three newer standards wrap DNS in encryption, and each uses its own port:
| Name | Port | Protocol | Notes |
|---|---|---|---|
| Plain DNS | 53 | UDP and TCP | The default everywhere, unencrypted |
| DNS over TLS (DoT) | 853 | TCP | RFC 7858. Used by Android’s Private DNS setting and by systemd-resolved when enabled |
| DNS over QUIC (DoQ) | 853 | UDP | RFC 9250. Newer and less widely supported |
| DNS over HTTPS (DoH) | 443 | TCP (and UDP for HTTP/3) | RFC 8484. Looks like normal web traffic, used by browsers |
| Multicast DNS (mDNS) | 5353 | UDP | Local network only, for names ending in .local |
Because DoH shares port 443 with every HTTPS website, you cannot block it by port without blocking the web. That is why a network-wide DNS filter can be bypassed by a browser using its own DoH resolver. DoT on 853 is easy to spot and to allow or block deliberately.
The full list of everyday ports, including these, is in common network ports.
Which DNS ports to open on your server
What you open depends on what the server actually does. Most web servers do not need any inbound DNS port at all.
| Your server | Inbound port 53 | Outbound port 53 |
|---|---|---|
| Web or mail server that only looks names up | Keep closed | Allow (UDP and TCP) |
| Authoritative nameserver for your domains | Open to everyone, UDP and TCP | Allow, for zone transfers and NOTIFY messages |
| Recursive resolver for your own office or network | Open only to your own addresses | Allow |
| Home DNS filter on a local network | Open to the local network only | Allow |
Never run an open resolver
A recursive resolver that answers anyone on the internet is called an open resolver. Attackers abuse open resolvers for amplification attacks: they send small questions with a forged source address, and your server fires much larger answers at the victim. If your server resolves names for other machines, restrict port 53 to the addresses that should use it.
Allow port 53 with UFW (Ubuntu and Debian)
UFW is the usual firewall front end on Ubuntu. Leaving out the protocol opens both TCP and UDP, which is what DNS needs:
sudo ufw allow 53
sudo ufw status
To allow only your own network, for example a resolver for an office using 198.51.100.0/24:
sudo ufw allow from 198.51.100.0/24 to any port 53
Allow port 53 with firewalld (AlmaLinux and Rocky Linux)
firewalld ships with a ready-made dns service that covers 53/tcp and 53/udp:
sudo firewall-cmd --permanent --add-service=dns
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
You should see dns in the list. For a full walkthrough of either tool, including how not to lock yourself out of SSHSSH A secure way to type commands on a server from your own computer, as if you were sitting at it. More about SSH →, see how to set up a firewall on Linux.
Cloud servers often have a second firewall in the provider’s control panelControl panel A website you log into to manage your hosting with buttons and forms, instead of typing commands. cPanel and Plesk are the common ones. More about Control panel → (security groups or network firewall rules). If you open port 53 on the server but not there, queries still never arrive.
How to check what is listening on port 53
Before you open anything, find out which program owns the port. On any modern Linux system:
sudo ss -tulpn | grep ':53 '
Typical output on a fresh Ubuntu server looks like this:
udp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=612,fd=13))
tcp LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=612,fd=14))
That is systemd-resolved, Ubuntu’s built-in local resolver cache. It listens only on 127.0.0.53 (newer releases also use 127.0.0.54), an address inside the machine, so it is not reachable from outside and it is not a security problem. It is, however, the most common reason a DNS server you install refuses to start.
Fixing “address already in use” on port 53
If you install BIND, Unbound, dnsmasq or a DNS filter such as Pi-hole on Ubuntu and it fails with “address already in use”, systemd-resolved’s stub listener is in the way. To free the port:
- Open
/etc/systemd/resolved.confwithsudo nano /etc/systemd/resolved.conf. - Under
[Resolve], setDNSStubListener=noand save. - Point the system at the real resolver list instead of the stub, then restart the service:
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
sudo systemctl restart systemd-resolved
- Run
sudo ss -tulpn | grep ':53 'again. Nothing should be listening now, so start your DNS server and check that it has taken the port.
How to test port 53 from outside
A normal port checker is not enough for DNS. Tools such as nc and Windows Test-NetConnection only test TCP properly, and UDP has no handshake to confirm. The reliable test is to ask a real DNS question. The examples use 203.0.113.10 as your server’s address.
With dig (Linux and macOS)
Test UDP, the default:
dig @203.0.113.10 example.com
Then force TCP:
dig +tcp @203.0.113.10 example.com
Look for status: NOERROR in the header and an ANSWER SECTION. If UDP works but TCP times out, a firewall is allowing only UDP. For more on reading the output, see how to run a DNS lookup.
On dig 9.18 or newer you can also test encrypted DNS. These query a public resolver over DoT and DoH:
dig +tls @9.9.9.9 example.com
dig +https @9.9.9.9 example.com
With PowerShell (Windows)
Resolve-DnsName example.com -Server 203.0.113.10
Resolve-DnsName example.com -Server 203.0.113.10 -TcpOnly
The first uses UDP, the second forces TCP. nslookup example.com 203.0.113.10 also works for a quick UDP check.
Reading the result
| What you see | What it means |
|---|---|
| An answer with NOERROR | The port is open and the server is answering |
connection timed out; no servers could be reached | A firewall is dropping the traffic, or nothing listens on that address |
connection refused (TCP) | Nothing is listening on TCP 53, or the firewall rejects it |
status: REFUSED | Port 53 is open, but the server will not answer you. Normal for an authoritative server asked about someone else’s domain, or a resolver that is correctly restricted |
For other ways to probe a port, see the port checker guide.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
| BIND, dnsmasq or Pi-hole will not start: “address already in use” | systemd-resolved stub listener holds 127.0.0.53:53 | Set DNSStubListener=no and relink /etc/resolv.conf as shown above |
| Small lookups work, some domains fail or time out | Only UDP 53 is open | Open TCP 53 as well |
| Secondary nameserver never gets zone updates | TCP 53 blocked between primary and secondary | Allow TCP 53 between the two servers and allow transfers in the DNS server’s own settings |
| Server works locally but not from outside | Cloud provider firewall, or server listening only on 127.0.0.1 | Open 53 in the provider’s panel and check the listen address in your DNS server’s settings |
| Your server is sending floods of DNS traffic | It is an open resolver being abused | Restrict recursion and port 53 to your own networks |
| Android Private DNS shows “cannot connect” | Outbound TCP 853 is blocked on that network | Allow 853 outbound, or switch Private DNS to automatic |
| Browser ignores your network DNS filter | Browser is using DNS over HTTPS on 443 | Turn off the browser’s secure DNS setting, or use a DoH-aware filter |
Official documentation
- RFC 1035: Domain names, implementation and specification
- RFC 7766: DNS transport over TCP
- RFC 7858: DNS over TLS
Related
- DNS leak test: check which resolver really answers your lookups after you change DNS settings.
- How to flush your DNS cache: clear old answers on your own computer once a DNS server change is live.
- What is DNS propagation?: why a record change reaches some resolvers before others.
- Quad9 DNS: another public resolver you can query on 53, 853 and 443 when testing.
Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.



