Ubuntu: port 53 already in use. How to free the port 53?


Example error: when we ran custom DNS server and we got the error:

root@tutorialspots ~ # node bindns.js
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: bind EADDRINUSE 0.0.0.0:53
    at node:dgram:362:20
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on Server instance at:
    at Socket.<anonymous> (/root/node_modules/bindns/lib/ndns.js:341:43)
    at Socket.emit (node:events:513:28)
    at node:dgram:364:14
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -98,
  code: 'EADDRINUSE',
  syscall: 'bind',
  address: '0.0.0.0',
  port: 53
}

Node.js v18.15.0

Port 53 already in use. How to free the port 53?

You are most likely affected by systemd-resolve

You can confirm if you are affect by systemd-resolve by checking listening ports and applications:

sudo netstat -tulpn | grep :53 | grep LISTEN

tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      510/systemd-resolve

systemd-resolve is listening on port 53.

How to stop systems-resolve using port 53?

Step 1: Edit /etc/systemd/resolved.conf set DNSStubListener to no, and set value of DNS and FallbackDNS

sudo nano /etc/systemd/resolved.conf

[Resolve]
DNS=8.8.8.8
FallbackDNS=8.8.4.4
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=no-negative
DNSStubListener=no
#ReadEtcHosts=yes

Step 2: Create a symbolic link for /run/systemd/resolve/resolv.conf with /etc/resolv.conf

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

Step 3: restart your server

Leave a Reply