Ubuntu: How to release port 53, used by systemd-resolved

By default, Ubuntu has systemd-resolved listening on port 53. If you want to run your own DNS server, you can’t, because port 53 is already in use, so you will receive an error similar to the following: “Listening on tcp 0.0.0.0:53: bind: address is already in use” How to stop using systemd-resolved using port 53 on Ubuntu. These instructions have been tested on Ubuntu 20.04, but they can also be used on other Ubuntu versions, such as Ubuntu 18.04, the upcoming Ubuntu 20.10, and Ubuntu-based Linux distributions such as Pop! _OS, Zorin OS, Elementary OS, Linux Mint, etc. Basically, this can be used on any system with system version 232 or higher.

To see if port 53 is being used on the system, use:

sudo lsof -i :53

Example output showing that systemd-resolved uses port 53 on the default Ubuntu 20.04 system:

$ sudo lsof -i :53

COMMAND   PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 610 systemd-resolve   12u  IPv4  19377      0t0  UDP localhost:domain 
systemd-r 610 systemd-resolve   13u  IPv4  19378      0t0  TCP localhost:domain (LISTEN)

If there is no output, it means that port 53 is not used.

How to stop using portd-resolved using port 53 on Ubuntu

It’s worth noting that just uncomment will release port 53 DNSStubListener And set it to no In /etc/systemd/resolved.conf. The other steps are to enable the DNS server-without it, your system will not be able to resolve any domain names, so you will not be able to access websites using a web browser, etc. Edit /etc/systemd/resolved.conf Use a text editor (as the root user), for example to open it with the Nano console text editor:

sudo nano /etc/systemd/resolved.conf

And uncomment (delete # From the front of the line) DNS= Line and DNSStubListener= line. Next, change DNS= The value in this file is assigned to the DNS server you want to use (for example, use 127.0.0.1 with local proxy, 1.1.1.1 with Cloudflare DNS, etc.), and also changed DNSStubListener= Value from yes to no.
After making these changes, the file should look like this (I use 1.1.1.1 as the DNS server here, which is Cloudflare DNS):

[Resolve]
DNS=1.1.1.1
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=no
DNSStubListener=no
#ReadEtcHosts=yes

To save the file using the Nano text editor, press Ctrl + xAnd enter y then press Enter.2. Create a symbolic link for /run/systemd/resolve/resolv.conf versus /etc/resolv.conf As destination:

sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Here, -s Used to create symbols rather than hard links, and -f Used to delete any existing target files (so it will delete /etc/resolv.conf If it exists) 3. Restart the system.
Port 53 should now be free on your Ubuntu system, and you should no longer get errors such as “listening on tcp 127.0.0.1:53: bind: address is already in use”.
You can check if port 53 is in use by running the following command sudo lsof -i :53 -If port 53 is not used, this command should not display any output.
You might like:

  • How to flush DNS cache on Linux (for BIND, Dnsmasq or nscd resolved by systemd)
  • How to permanently change the MAC address on Linux

How to undo changes

Do you want to undo the changes made according to the instructions in this article? This is what you must do1. Start with editing /etc/systemd/resolved.conf Use a text editor (as the root user), for example to open it with the Nano console text editor:

sudo nano /etc/systemd/resolved.conf

And comment out (add # Before the trip) DNS= with DNSStubListener=no, And then save the file. To save the file using the Nano text editor, press Ctrl + xAnd enter y then press Enter.2. Remove /etc/resolv.conf Symbolic link:

sudo rm /etc/resolv.conf

3. Restart the system.

Source

Sidebar