Setting Up a DNS Server on Raspberry Pi

  • 安装
  • 配置dnscrypt-proxy
  • 将路由器默认DNS更改为RPi
  • 配置失败自动重启

安装

1
2
sudo apt-get install dnscrypt-proxy
sudo apt-get install dnsutils #包含了dig什么的命令,最好装上

配置dnscrypt-proxy

1
2
3
sudo nano /etc/dnscrypt-proxy/dnscrypt-proxy.toml
listen_addresses = ['127.0.0.1:53', '192.168.0.150:53'] #按照你自己的IP改
server_names = ['cloudflare','cloudflare-ipv6']
1
dnscrypt-proxy -resolve cloudflare-dns.com

试试行不行,没问题再做下一步安装服务

非常重要,不然启动服务时会绑定端口失败

1
2
3
sudo nano /lib/systemd/system/dnscrypt-proxy.service #更改dnscrypt-proxy服务设置
#User=_dnscrypt-proxy #注释掉源文件这一行
User=root #新加这一行,让它以root身份运行(好像不怎么安全..哈哈不管了)

启动服务试试吧!

1
2
3
sudo systemctl enable dnscrypt-proxy
sudo systemctl start dnscrypt-proxy
sudo systemctl status dnscrypt-proxy

将路由器默认DNS更改为RPi

略略略!!!

自己百度,只有一点要注意,就是要改的地方是DHCP的,不是WAN口DNS!!!

参考网址

couldflare
DNScrypt-proxy

  • Installation
  • Configure dnscrypt-proxy
  • Change the router’s default DNS to the Raspberry Pi
  • Configure automatic restart on failure

Installation

1
2
sudo apt-get install dnscrypt-proxy
sudo apt-get install dnsutils # includes commands like dig, it's better to install it

Configure dnscrypt-proxy

1
2
3
sudo nano /etc/dnscrypt-proxy/dnscrypt-proxy.toml
listen_addresses = ['127.0.0.1:53', '192.168.0.150:53'] # change according to your own IP
server_names = ['cloudflare','cloudflare-ipv6']
1
dnscrypt-proxy -resolve cloudflare-dns.com

Try if it works, only proceed to the next step if there are no issues.

Very important, otherwise the service startup will fail to bind the port

1
2
3
sudo nano /lib/systemd/system/dnscrypt-proxy.service # change dnscrypt-proxy service settings
#User=_dnscrypt-proxy # comment out this line in the original file
User=root # add this new line, let it run as root (seems not very safe.. lol, whatever)

Now try starting the service!

1
2
3
sudo systemctl enable dnscrypt-proxy
sudo systemctl start dnscrypt-proxy
sudo systemctl status dnscrypt-proxy

Change the router’s default DNS to the Raspberry Pi

Skip!!!

Figure this out yourself, just one important note: the setting to change is in DHCP, not the WAN port DNS!!!

Reference URLs

cloudflare
DNScrypt-proxy


Setting Up a DNS Server on Raspberry Pi
https://tokisaki.top/blog/rpi-make-dns/
作者
Tokisaki Galaxy
发布于
2019年12月26日
许可协议