DNS port: what port 53 is and which DNS ports to open

Why DNS uses port 53 over UDP and TCP, which ports encrypted DNS uses, what to open in your firewall, and how to test port 53 properly.

7–11 minutes
Network switch with many blue patch cables

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:

SituationProtocolWhy
Ordinary lookup (A, AAAA, MX, most TXT)UDP 53One small question, one small answer, no handshake needed
Answer too big for one UDP messageTCP 53The server sets the “truncated” flag and the client retries over TCP
Zone transfer between primary and secondary nameservers (AXFR, IXFR)TCP 53A whole zone is far too big for UDP
DNSSEC-signed answers and long TXT records (SPF, DKIM)Often TCP 53Signatures 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:

NamePortProtocolNotes
Plain DNS53UDP and TCPThe default everywhere, unencrypted
DNS over TLS (DoT)853TCPRFC 7858. Used by Android’s Private DNS setting and by systemd-resolved when enabled
DNS over QUIC (DoQ)853UDPRFC 9250. Newer and less widely supported
DNS over HTTPS (DoH)443TCP (and UDP for HTTP/3)RFC 8484. Looks like normal web traffic, used by browsers
Multicast DNS (mDNS)5353UDPLocal 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 serverInbound port 53Outbound port 53
Web or mail server that only looks names upKeep closedAllow (UDP and TCP)
Authoritative nameserver for your domainsOpen to everyone, UDP and TCPAllow, for zone transfers and NOTIFY messages
Recursive resolver for your own office or networkOpen only to your own addressesAllow
Home DNS filter on a local networkOpen to the local network onlyAllow

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:

  1. Open /etc/systemd/resolved.conf with sudo nano /etc/systemd/resolved.conf.
  2. Under [Resolve], set DNSStubListener=no and save.
  3. 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
  1. 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 seeWhat it means
An answer with NOERRORThe port is open and the server is answering
connection timed out; no servers could be reachedA 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: REFUSEDPort 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

SymptomCauseFix
BIND, dnsmasq or Pi-hole will not start: “address already in use”systemd-resolved stub listener holds 127.0.0.53:53Set DNSStubListener=no and relink /etc/resolv.conf as shown above
Small lookups work, some domains fail or time outOnly UDP 53 is openOpen TCP 53 as well
Secondary nameserver never gets zone updatesTCP 53 blocked between primary and secondaryAllow TCP 53 between the two servers and allow transfers in the DNS server’s own settings
Server works locally but not from outsideCloud provider firewall, or server listening only on 127.0.0.1Open 53 in the provider’s panel and check the listen address in your DNS server’s settings
Your server is sending floods of DNS trafficIt is an open resolver being abusedRestrict recursion and port 53 to your own networks
Android Private DNS shows “cannot connect”Outbound TCP 853 is blocked on that networkAllow 853 outbound, or switch Private DNS to automatic
Browser ignores your network DNS filterBrowser is using DNS over HTTPS on 443Turn off the browser’s secure DNS setting, or use a DoH-aware filter

Official documentation

Get the next guide

One email when there is something worth reading: new guides, errors going around, and hosting changes that affect your site.

No tracking pixels, and one click to leave.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.