Preface#
Recently, it may be that I bought a domestic server and didn't use it, so it's better to make use of it to build an ADGuard DNS to remove ads for the poor and pitiful APPs in China.
Requirements#
- One server (preferably in the same country as you, please pay attention to local laws)
- Server supports opening port
53
- One brain
- Two hands
Installation#
One-click script:
curl -sSL https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh
If it is a server in mainland China, you can use a mirror source
curl -sSL https://mirror.ghproxy.com/https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh
The installation is complete as shown in the figure, proceed to the next step.
Configuration#
Open the browser and access http://<server IP>:3000
Click on "Start Configuration", and you can enter your favorite port for the web management port.
Oh, what's going on here? Don't worry, let's find out the reason (if you don't have this problem, skip to the next step).
Troubleshooting
Enter lsof -i:53
and get
root@VM-0-9-ubuntu:~# lsof -i:53
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 698 systemd-resolve 12u IPv4 10013 0t0 UDP 127.0.0.53:domain
systemd-r 698 systemd-resolve 13u IPv4 10014 0t0 TCP 127.0.0.53:domain (LISTEN)
named 725 bind 23u IPv4 11889 0t0 UDP localhost:domain
named 725 bind 24u IPv4 11898 0t0 UDP localhost:domain
named 725 bind 26u IPv4 13187 0t0 TCP localhost:domain (LISTEN)
named 725 bind 27u IPv4 13187 0t0 TCP localhost:domain (LISTEN)
named 725 bind 28u IPv4 13187 0t0 TCP localhost:domain (LISTEN)
named 725 bind 29u IPv4 11901 0t0 UDP 10.0.16.17:domain
named 725 bind 30u IPv4 11902 0t0 UDP 10.0.16.17:domain
named 725 bind 32u IPv4 11907 0t0 TCP 10.0.16.17:domain (LISTEN)
named 725 bind 33u IPv4 11907 0t0 TCP 10.0.16.17:domain (LISTEN)
named 725 bind 34u IPv4 11907 0t0 TCP 10.0.16.17:domain (LISTEN)
named 725 bind 35u IPv6 11908 0t0 UDP ip6-localhost:domain
named 725 bind 36u IPv6 11912 0t0 UDP ip6-localhost:domain
named 725 bind 37u IPv6 11913 0t0 TCP ip6-localhost:domain (LISTEN)
named 725 bind 38u IPv6 11913 0t0 TCP ip6-localhost:domain (LISTEN)
named 725 bind 39u IPv6 11913 0t0 TCP ip6-localhost:domain (LISTEN)
named 725 bind 40u IPv6 11914 0t0 UDP [fe80::5054:ff:fe5e:b356]:domain
named 725 bind 41u IPv6 11921 0t0 UDP [fe80::5054:ff:fe5e:b356]:domain
named 725 bind 42u IPv6 11922 0t0 TCP [fe80::5054:ff:fe5e:b356]:domain (LISTEN)
named 725 bind 43u IPv6 11922 0t0 TCP [fe80::5054:ff:fe5e:b356]:domain (LISTEN)
named 725 bind 44u IPv6 11922 0t0 TCP [fe80::5054:ff:fe5e:b356]:domain (LISTEN)
It can be seen that two processes are occupying port 53
. Let's solve named
first.
systemctl stop bind9
systemctl disable bind9
Then lsof again
root@VM-0-9-ubuntu:~# lsof -i:53
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 698 systemd-resolve 12u IPv4 10013 0t0 UDP 127.0.0.53:domain
systemd-r 698 systemd-resolve 13u IPv4 10014 0t0 TCP 127.0.0.53:domain (LISTEN)
It can be seen that named
is gone~~(if you like, you can also apt purge bind9
directly)~~
Then solve systemd-r
mkdir -p /etc/systemd/resolved.conf.d
touch /etc/systemd/resolved.conf.d/adguardhome.conf
mv /etc/resolv.conf /etc/resolv.conf.backup
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
Then write the following content to /etc/systemd/resolved.conf.d/adguardhome.conf
using your favorite editor
[Resolve]
DNS=127.0.0.1
DNSStubListener=no
Then enter the following command
systemctl restart systemd-resolved
Then there should be no process occupying port 53
root@VM-0-9-ubuntu:~# lsof -i:53
root@VM-0-9-ubuntu:~#
Refresh the page, and there should be no problem. Click "Next" to set up the administrator account and password.
Next
Then it's basically done. Click "Open Dashboard" to log in.
Then click "Settings → DNS Settings → Upstream DNS Servers" in order.
Enter your preferred DNS (supports pure DNS, DoH, DoT, etc.)
Then add a bootstrap server. Here, be sure to fill in the most popular DNS in your area, otherwise the domain names of the upstream DNS servers cannot be resolved (if any).
You can also add a backup (if the upstream server is down, this will be used)
The sensitive information is blurred here, but it doesn't matter. I deleted the server I used in the tutorial.
Then test it, and if there are no problems, click "Save".
Then the setup is complete. At this time, set the DNS settings of your home router (DHCP settings) / device to your server IP.
For ad filtering rules, please search online~
FAQ#
- Q: I don't have the qualifications to build a DNS server, but I just want to use it for myself. What should I do?
- A: You can be a little clever here and only open port 53 for your own C segment in the server's security group (I don't know if there will be any problems, but I have been using it for almost a month without any issues). If you are still worried, you can uninstall the agent of the service provider, which can be found online for major companies.
- Q: After setting up the DNS, I can't use the service provider's internal mirror source. What should I do?
- A: Add your service provider's internal DNS to
/etc/resolv.conf
. Here, I will use Tencent Cloud as an example. If you have a normal purchased server/lightweight cloud server and did not modify the network settings when purchasing, it is generally a VPC network. After clearing/etc/resolv.conf
, enter the following content and save it:
nameserver 183.60.83.19
nameserver 183.60.82.98
For other companies/other types, you can find them online.
Conclusion#
If you find this article helpful, please feel free to share it with friends in need. If you can sponsor the author's cat, that would be even better meow~
See you Next Time~
This article is synchronized and updated to xLog by Mix Space.
The original link is https://blog.nekorua.com/posts/build/97.html