关闭ubuntu服务器53服务

创建于:2025-11-19 修改于: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服务

# This file is part of systemd.  
#  
# systemd is free software; you can redistribute it and/or modify it  
# under the terms of the GNU Lesser General Public License as published by  
# the Free Software Foundation; either version 2.1 of the License, or  
# (at your option) any later version.  
#  
# Entries in this file show the compile time defaults.  
# You can change settings by editing this file.  
# Defaults can be restored by simply deleting this file.  
#  
# See resolved.conf(5) for details  
**[**Resolve**]**  
#DNS=  
#FallbackDNS=  
#Domains=  
#LLMNR=no  
#MulticastDNS=no  
#DNSSEC=no  
#DNSOverTLS=no  
#Cache=no-negative  
#DNSStubListener=yes 将这行的注释拿掉,改为no保存,如下  
DNSStubListener**=**no   
#ReadEtcHosts=yes  
**```****###****重启****生效** **```****bash**systemctl restart systemd-resolved.service**#****检查**  
lsof -i :53  
**```**
💬 评论区