Modify DNS server configuration by raspberry pie

Posted by mars_rahul on Sun, 03 May 2020 06:41:09 +0200

Modify profile

1
sudo vim /etc/dhcpcd.conf

Add the following content, we use Google DNS (Beijing Unicom test speed is good)

1
static domain_name_servers=8.8.8.8 8.8.4.4

Complete sample file section

1
2
3
4
interface eth0
        static ip_address=192.168.1.3/24
        static routers=192.168.1.1
        static domain_name_servers=8.8.8.8 8.8.4.4

Setting configuration effective

1
sudo service dhcpcd restart

Validate

We use the dig command to verify whether dns is effective

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
dig droidyue.com

; <<>> DiG 9.11.5-P4-5.1-Raspbian <<>> droidyue.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54841
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;droidyue.com.            IN  A

;; ANSWER SECTION:
droidyue.com.     299 IN  A   104.27.129.205
droidyue.com.     299 IN  A   104.27.128.205

;; Query time: 44 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Apr 19 17:07:11 CST 2020
;; MSG SIZE  rcvd: 73

Focus on this message

1
2
3
4
;; Query time: 44 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Apr 19 17:07:11 CST 2020
;; MSG SIZE  rcvd: 73

Be careful

Do not modify the file / etc/resolv.conf directly

1
2
3
4
5
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver fe80::1%eth0
You have new mail in /var/mail/pi

As the above English says, this file will be washed out, and you need to reset it some time in the future. So follow the changes in the article.

Recommended reading

Topics: sudo DNS vim Google