About Me

header ads

[GUIDE] Ubuntu: how to free port 53 used by systemd-resolved

ubuntu-19-04-eol

Ubuntu has systemd-resolved set on port 53 by default. In case you want to use that specific port, maybe to launch your DNS server, you can't do it. You would receive an error similar to the following: “listen tcp 0.0.0.0:53: bind: address already in use“. In this short guide, we see how to clear door 53.

The following instructions work on Ubuntu 20.04 but also on Ubuntu 18.04 and on the various derivatives of Ubuntu (I refer to Pop! _OS, Zorin OS, Elementary OS, Linux Mint, etc). In addition, it works with any system with systemd 232 or higher.

Ubuntu, let's clear port 53

To verify that port 53 is in use give the following command:

sudo lsof -i :53

If the output you get is similar to the following then the port is actually in use:

ubuntu-porta-53-768x479

Conversely, if you don't get any output, the port is not in use.

It is worth noting that it is possible to free port 53 by simply uncommenting DNSStubListener setting it no to /etc/systemd/resolved.conf. The other steps are to enable a DNS server: without it, your system will not be able to resolve any domain name, so you will not be able to visit websites etc. We proceed by points:

  • Edit the file /etc/systemd/resolved.conf with a text editor (with root privileges), for example, you can use nano: sudo nano /etc/systemd/resolved.conf;
  • Uncomment the line DNS= and the line DNSStubListener= by removing the #;
  • Change the value by DNS= setting it at will (eg: 1.1.1.1 to use Cloudflare's DNS);
  • Change the row by DNSStubListener= setting it to no;
  • If you have used Nano dates Ctrl + x, then y and finally Enter to save and close.

The file, if you have operated correctly, will look like this at the end of operations:

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

At this point you just have to create a link for /run/systemd/resolve/resolv.conf with /etc/resolv.conf as destination:

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

Reboot your Ubuntu based system. If all went well, port 53 should be free on your system. To check, again, we use the command sudo lsof -i :53 : it should not return any output.

Discard these changes

To cancel what has been done, go backwards. Open the file with an editor /etc/systemd/resolved.conf. Comment out the lines DNS= and DNSStubListener=no then save the changes. Remove the link like this:

sudo rm /etc/resolv.conf

Reboot the system.

Post a Comment

3 Comments