Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What Port 53 Is For

Port 53 belongs to DNS, the system that turns names such as example.com into IP addresses. A program that needs an address sends a question to port 53 of a resolver, and the resolver asks the nameservers responsible for the domain on their port 53 in turn. For the full path of a lookup, see what is DNS.

DNS uses both transport protocols on the same port number: UDP 53 and TCP 53. A firewall rule for DNS almost always needs both.

UDP or TCP?

CaseTransport
Ordinary query and answerUDP 53
Answer too large for UDPRetried on TCP 53
Zone transfer between nameserversTCP 53
DNS over TLSTCP 853
DNS over HTTPS443

When an answer does not fit in a UDP packet, the server sends a shortened answer with the truncation flag set, and the client asks again over TCP. Current DNS standards expect every server to answer over TCP as well, so a firewall that opens only UDP 53 causes failures that appear only for some names.

Who Needs Port 53 Open

  • Every server, outgoing: a server that cannot reach a resolver cannot resolve names, so package updates, mail delivery, and API calls fail. Most firewalls allow outgoing traffic by default.
  • A DNS server, incoming: open port 53 only on an authoritative nameserver for your domains, or on a resolver that serves your own private network.
  • Everything else: a web server, mail server, or database server does not need incoming port 53.

Check What Listens on Port 53

sudo ss -ulnp 'sport = :53'
sudo ss -tlnp 'sport = :53'

On Ubuntu the output usually shows systemd-resolved on 127.0.0.53 and often 127.0.0.54 as well. That is the local stub resolver: programs on the server send their questions to it, and it forwards them to the upstream resolvers. It listens on a loopback address only, so it cannot be reached from outside. To see which upstream resolvers it uses and to test it:

resolvectl status
dig @127.0.0.53 example.com

Reading dig output is covered in dig command.

Port 53 Already in Use

A DNS program that listens on every address (0.0.0.0) on port 53 can fail to start on Ubuntu with "address already in use", because the stub resolver holds port 53 on its loopback addresses. The cleanest fix is to configure the new program to listen only on the addresses it needs. If it must take over local resolution, switch the stub off. Keep your SSH session open and test name lookups at the end:

sudo nano /etc/systemd/resolved.conf
# under [Resolve] set: DNSStubListener=no
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
sudo systemctl restart systemd-resolved
dig example.com

The link step matters: without it, /etc/resolv.conf still points programs at 127.0.0.53, where nothing answers any more.

Firewall Rules for a DNS Server

On Ubuntu and Debian with ufw, a rule without a protocol opens both TCP and UDP:

sudo ufw allow 53

On AlmaLinux and Rocky Linux with firewalld, the dns service covers both:

sudo firewall-cmd --permanent --add-service=dns
sudo firewall-cmd --reload

More on ufw rules in UFW allow port.

Never Run an Open Resolver

A recursive resolver that answers anyone on the internet is an open resolver. Attackers send it small queries with a forged source address, and it sends much larger answers to the victim. If you run a resolver, limit who may use recursion. In BIND:

options {
    recursion yes;
    allow-recursion { localhost; localnets; };
};

In Unbound the same job is done by access-control lines. An authoritative nameserver should answer only for its own zones, with recursion off. From a machine outside your network, a recursive question to your server should be refused:

dig @203.0.113.53 example.org

Here 203.0.113.53 stands for your DNS server's public address. The status line of the reply should read REFUSED.

Encrypted DNS

DNS over TLS wraps the same questions in TLS on TCP port 853. DNS over HTTPS sends them inside HTTPS on port 443. Both protect lookups between a client and its resolver; the resolver still talks to nameservers on port 53. A list of other well-known ports is in common port numbers, and the servers behind port 53 are explained in what is a nameserver.

Was this answer helpful?
Loading...