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
      throw er; // Unhandled 'error' event

Error: bind EADDRINUSE
    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: '',
  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 *               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


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