Have you ever thought of using your own server to access your designated IP address using a.com, of course, using the local hosts file can also be done, but in the current cluster service environment, what about the challenge of managing so many IP addresses? We use the docker version corresponding to DNSMasq docker-DNsmasq.

Use guide

Download mirror

dockerpulldocker-dnsmasq

Create the simplest configuration /opt/dnsmasq.conf


#dnsmasq config, for a complete example, see:

# http://oss.segetech.com/intra/srv/dnsmasq.conf

DNS resolution log

log-queries

# Define host-IP mapping

Address = / h0 172.17.205.28

Address = / h1/172.17.205.32

.

Run the container

 

docker run \

–name dnsmasq \

-d \

-p 53:53/udp \

-p 8080:8080 \

-v /opt/dnsmasq.conf:/etc/dnsmasq.conf \

–log-opt max-size=100m \

-e HTTP_USER=admin \

-e HTTP_PASS=admin \

–restart always \

jpillora/dnsmasq


Parameters that

  


Visit http://localhost:8080

Use the admin or admin account password to log in.

  


The DNS configuration

Add the following two lines to the /etc/resolv.conf file

If 172.17.205.28 is added, DNS resolution fails

Nameserver 127.0.0.1 # Mandatory

Nameserver 172.17.205.28 # Mandatory

The configuration of this machine is the same as that of other machines

The mandatory field has to be added before it takes effect, because DNS resolution is resolved from the top down

root@center ~# ping h1

PING h1 (172.17.205.32) 56(84) bytes of data.

64 bytes from 172.17.205.32 (172.17.205.32): icmp_seq=1 TTL =64 time= 0.155ms

64 bytes from 172.17.205.32 (172.17.205.32): icmp_seq=2 TTL =64 time= 0.203ms

^C

— h1 ping statistics —

2 packets transmitted, 2 received, 0% packet loss, time 1000ms

RTT min/avg/ Max /mdev = 0.155/0.179/0.203/0.024 ms


Increase the resolution

Click save to automatically take effect after a few seconds

Address = / h0 172.17.205.28

Address = / h1/172.17.205.32

Address = / h2/172.17.205.33

Address = / h3/172.17.205.34

Address = / h4/172.17.205.35…

Pay attention to

It is recommended that the hostname of other machines be the same as the above configuration

Otherwise, the following problems may occur

root@asdf ~# ping h0

ping: h0: Name or service not known