Self-built DNS tutorial

Self-built DNS tutorial

DNSmasq is a small and convenient tool for configuring DNS services and DHCP servers. It is suitable for small networks. It provides DNS resolution and optional DHCP functions, and provides the function of local cache query requests.

1. Install dnsmasq

CentOS systems:

 yum update yum install -y dnsmasq

Debian/Ubuntu systems:

 apt-get update apt-get install -y dnsmasq

2. Check the version of DNSmasq

 dnsmasq -v

The following is the output, as long as it does not prompt that the command cannot be found (-bash: dnsmasq: command not found)

Dnsmasq version x.xx Copyright (c) 2000-2012 Simon Kelley
Compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack

This software comes with ABSOLUTELY NO WARRANTY.
Dnsmasq is free software, and you are welcome to redistribute it
under the terms of the GNU General Public License, version 2 or 3.

3. Configuration File
The configuration file of Dnsmasq is: dnsmasq.conf
The configuration file location for package manager installation is: /etc/dnsmasq.conf
This tutorial only introduces the configuration of DNS service. The following sections only point out the relevant configuration of DNS service.
First, make a backup copy of the configuration file, then clear the original configuration file and write the configuration content according to the following parameter instructions:

 cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak echo "" > /etc/dnsmasq.conf

Open the configuration file and write the configuration content according to the parameter instructions below. Press I to enter the editing mode. After making changes, press ESC to exit and enter :wq to save and exit.

 vi /etc/dnsmasq.conf

Configuration file parameter description :

 port=53 # 指定DNSmasq的監聽端口,默認為53端口,也可設置為5353端口從而防止53端口DNS污染(但某些設備如win并不支持非53端口) resolv-file=/xxx/xx.conf # 指定DNSmasq獲取上游DNS服務器地址的文件,不配置此項則默認從/etc/resolv.conf(linux默認DNS配置文件) 獲取strict-order # 嚴格按照resolv-file 參數指定的文件中按從上到下的順序發送DNS解析請求,直至獲取解析應答成功為止listen-address= # 指定DNSmasq監聽的地址,若僅提供為本機使用可設置為127.0.0.1 ,留空或設置為0.0.0.0 即任何人都可訪問address=/xxx.xx/xxxx # 自定義某些地址的解析服務器,可以過濾或者指定某些網站(支持ipv6,直接寫ipv6的地址即可) # 過濾廣告或者某域名,例如配置address=/www.nanqinlang.com/127.0.0.1 # 把廣告域名解析請求發送到錯誤的解析服務器IP 127.0.0.1 即可屏蔽該域名的訪問# 也可以把www.google.com 等指向一個國外的SNI代理IP,即可實現DNS科學上網server=208.67.222.222#5353 # 指定上游DNS解析服務器,此處推薦設置為可使用5353端口的opendns bogus-nxdomain=208.67.222.222 # 用于防止DNS污染/劫持,參數和上面server 項填寫相同的ip ,但不支持非53端口。 conf-dir=/etc/dnsmasq.d/ # 加載/etc/dnsmasq.d/ 文件夾內的配置文件

Configuration file example:

 port=53 strict-order listen-address=127.0.0.1 server=208.67.222.222#53 bogus-nxdomain=208.67.222.222 conf-dir=/etc/dnsmasq.d/

To customize address resolution, create a separate configuration file:
Copy code
vi /etc/dnsmasq.d/sni.conf

Then write the custom address parsing in the format, as shown below:

 address=/google.com/1.1.1.1 address=/google.com.hk/1.1.1.1 address=/google.co.jp/1.1.1.1 address=/gmail.com/1.1.1.1 address=/youtube.com/1.1.1.1

Note: If this file or configuration file is modified, DNSmasq needs to be restarted for it to take effect.

4. Instructions <br />Enable DNSmasq service

 service dnsmasq start

Stop DNSmasq Service

 service dnsmasq stop

Restart the DNSmasq service (restart is required after modifying the configuration file)

 service dnsmasq restart

5. Uninstall DNSmasq

If there are files in the /etc/dnsmasq.d directory, you need to delete this directory before uninstalling normally:

Delete this directory first

 rm -rf /etc/dnsmasq.d

CentOS systems

 yum remove dnsmasq -y

Debian/Ubuntu systems:

 apt-get remove --purge dnsmasq -y

Set DNS to your VPS IP in your PC/router/mobile device and port 53 (if any).

via: https://doub.io/wlzy-32/

<<:  SpeedyKVM: $3.8/month/2.6G memory/1TB hard disk/5TB traffic/KVM/Dallas

>>:  WootHosting: $189/month/E5620/80GB memory/12TB space/unlimited traffic/Los Angeles

Recommend

CeeHosting: $5/month/1GB RAM/30GB storage/free Windows

CeeHosting, a new hosting provider established in...

All-in-one installation script for BBR/BBR2/BBR Plus/ Ruisu etc. under Linux

BBR, BBR2, BBR Plus, Ruisu, etc. can be installed...

Namecheap offers free .me domains

Only for US students, requires a .edu email addre...

Introduction to American hosting provider Micfo

1. Introduction <br /> Micfo, an American h...

Tutorial on how to turn on the wall with GAE

In this magical land, climbing over the wall shou...

EVL Gaming: $12/year/128MB/5GB/150GB/KVM/Phoenix

EVL Gaming, LLC is an American hosting company re...

SystemInPlace provides free DNS resolution for unlimited domain names

1. Introduction to SystemInPlace SystemInPlace is...