关闭ubuntu服务器53服务

创建于:2025-11-19

关闭ubuntu服务器53服务

默认安装好ubuntu server 20.04LTS后,系统会自动开放53的dns服务为本机提供服务。
Ubuntu的systemd-resolved将默认监听在53号端口,如果我们需要运行自己定义的dns服务器,端口已经在使用会导致端口冲突。所以我们会遇见下面的错误:

1  
2"listen tcp 0.0.0.0:53: bind: address already in use".  
3  

查看端口情况

1  
2root@ub20:/home/sk# netstat -lnpt|grep 53  
3Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name  
4tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 2119/systemd-resolv  
5  
6  

或者

1  
2root@ub20:/home/sk# sudo lsof -i :53  
3COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME  
4systemd-r 2119 systemd-resolve 12u IPv4 67939 0t0 UDP localhost:domain  
5systemd-r 2119 systemd-resolve 13u IPv4 67940 0t0 TCP localhost:domain **(**LISTEN**)**  
6  
7  

如何停止ubuntu上的systemd-resolved服务使用53

修改配置文件,我们可以修改/etc/systemd/resolved.conf中DNSStubListener的注释行,它将不再打开dns服务

#DNSStubListener=yes 将这行的注释拿掉,改为no保存,如下  
DNSStubListener**=**no   
**```**重启生效  
```bashsystemctl restart systemd-resolved.service  
lsof -i :53  
  
**```**
💬 评论区