首页 > 其他分享 >用Dockers搭建DNS服务器

用Dockers搭建DNS服务器

时间:2023-07-08 16:00:23浏览次数:35  
标签:Dockers ... dns conf DNS ubuntu 服务器 docker python3

1、Docker-Compose的配置文件

用vi编辑器,创建文件:

vi docker-compose.yml

内容如下:

version: '3.6'

networks:
   main:
     ipam:
       config:
         - subnet: 10.10.1.0/24

services:
   web:
     image: 'sameersbn/bind:9.16.1-20200524'
     container_name: dns
     restart: always
     networks:
       main:
         ipv4_address: 10.10.1.2
     ports:
       - '53:53/udp'
       - '10000:10000/tcp'
     volumes:
       - '/mnt/data/dns-server:/data'
     shm_size: '256m'
保存后退出

2、用docker-compose启动容器

- 可能提示没有安装docker-compose

root@dns-server:/home/public/software/dns# docker-compose up -d
 Command 'docker-compose' not found, but can be installed with:
 snap install docker          # version 20.10.24, or
 apt  install docker-compose  # version 1.29.2-1
 See 'snap info docker' for additional versions.
- 遵照上一步的提示,安装docker-compose

root@dns-server:/home/public/software/dns# apt install docker-compose
 Reading package lists... Done
 Building dependency tree... Done
 Reading state information... Done
 The following additional packages will be installed:
   bridge-utils containerd dns-root-data dnsmasq-base docker.io pigz python3-docker python3-dockerpty python3-docopt python3-dotenv python3-texttable python3-websocket runc ubuntu-fan
 Suggested packages:
   ifupdown aufs-tools cgroupfs-mount | cgroup-lite debootstrap docker-doc rinse zfs-fuse | zfsutils
 The following NEW packages will be installed:
   bridge-utils containerd dns-root-data dnsmasq-base docker-compose docker.io pigz python3-docker python3-dockerpty python3-docopt python3-dotenv python3-texttable python3-websocket runc ubuntu-fan
 0 upgraded, 15 newly installed, 0 to remove and 60 not upgraded.
 Need to get 72.7 MB of archives.
 After this operation, 288 MB of additional disk space will be used.
 Do you want to continue? [Y/n] Y
 Get:1 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63.6 kB]
 Get:2 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 bridge-utils amd64 1.7-1ubuntu3 [34.4 kB]
 Get:3 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 runc amd64 1.1.4-0ubuntu1~22.04.3 [4,244 kB]
 Get:4 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 containerd amd64 1.6.12-0ubuntu1~22.04.3 [34.4 MB]
 Get:5 http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 dns-root-data all 2021011101 [5,256 B]                                                                                                                                                               
 Get:6 http://cn.archive.ubuntu.com/ubuntu jammy-updates/main amd64 dnsmasq-base amd64 2.86-1.1ubuntu0.3 [354 kB]                                                                                                                                                
 Get:7 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-websocket all 1.2.3-1 [34.7 kB]                                                                                                                                                          
 Get:8 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-docker all 5.0.3-1 [89.3 kB]                                                                                                                                                             
 Get:9 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-dockerpty all 0.4.1-2 [11.1 kB]                                                                                                                                                          
Get:10 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-docopt all 0.6.2-4 [26.9 kB]                                                                                                                                                            
 Get:11 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-dotenv all 0.19.2-1 [20.5 kB]                                                                                                                                                           
 Get:12 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 python3-texttable all 1.6.4-1 [11.4 kB]                                                                                                                                                         
 Get:13 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 docker-compose all 1.29.2-1 [95.8 kB]                                                                                                                                                           
 Get:14 http://cn.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 docker.io amd64 20.10.21-0ubuntu1~22.04.3 [33.3 MB]                                                                                                                                     
 Get:15 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 ubuntu-fan all 0.12.16 [35.2 kB]                                                                                                                                                                
 Fetched 72.7 MB in 20s (3,598 kB/s)                                                                                                                                                                                                                             
 Preconfiguring packages ...
 Selecting previously unselected package pigz.
 (Reading database ... 74075 files and directories currently installed.)
 Preparing to unpack .../00-pigz_2.6-1_amd64.deb ...
 Unpacking pigz (2.6-1) ...
 Selecting previously unselected package bridge-utils.
 Preparing to unpack .../01-bridge-utils_1.7-1ubuntu3_amd64.deb ...
 Unpacking bridge-utils (1.7-1ubuntu3) ...
 Selecting previously unselected package runc.
 Preparing to unpack .../02-runc_1.1.4-0ubuntu1~22.04.3_amd64.deb ...
 Unpacking runc (1.1.4-0ubuntu1~22.04.3) ...
 Selecting previously unselected package containerd.
 Preparing to unpack .../03-containerd_1.6.12-0ubuntu1~22.04.3_amd64.deb ...
 Unpacking containerd (1.6.12-0ubuntu1~22.04.3) ...
 Selecting previously unselected package dns-root-data.
 Preparing to unpack .../04-dns-root-data_2021011101_all.deb ...
 Unpacking dns-root-data (2021011101) ...
 Selecting previously unselected package dnsmasq-base.
 Preparing to unpack .../05-dnsmasq-base_2.86-1.1ubuntu0.3_amd64.deb ...
 Unpacking dnsmasq-base (2.86-1.1ubuntu0.3) ...
 Selecting previously unselected package python3-websocket.
 Preparing to unpack .../06-python3-websocket_1.2.3-1_all.deb ...
 Unpacking python3-websocket (1.2.3-1) ...
 Selecting previously unselected package python3-docker.
 Preparing to unpack .../07-python3-docker_5.0.3-1_all.deb ...
 Unpacking python3-docker (5.0.3-1) ...
 Selecting previously unselected package python3-dockerpty.
 Preparing to unpack .../08-python3-dockerpty_0.4.1-2_all.deb ...
 Unpacking python3-dockerpty (0.4.1-2) ...
 Selecting previously unselected package python3-docopt.
 Preparing to unpack .../09-python3-docopt_0.6.2-4_all.deb ...
 Unpacking python3-docopt (0.6.2-4) ...
 Selecting previously unselected package python3-dotenv.
 Preparing to unpack .../10-python3-dotenv_0.19.2-1_all.deb ...
 Unpacking python3-dotenv (0.19.2-1) ...
 Selecting previously unselected package python3-texttable.
 Preparing to unpack .../11-python3-texttable_1.6.4-1_all.deb ...
 Unpacking python3-texttable (1.6.4-1) ...
 Selecting previously unselected package docker-compose.
 Preparing to unpack .../12-docker-compose_1.29.2-1_all.deb ...
 Unpacking docker-compose (1.29.2-1) ...
 Selecting previously unselected package docker.io.
 Preparing to unpack .../13-docker.io_20.10.21-0ubuntu1~22.04.3_amd64.deb ...
 Unpacking docker.io (20.10.21-0ubuntu1~22.04.3) ...
 Selecting previously unselected package ubuntu-fan.
 Preparing to unpack .../14-ubuntu-fan_0.12.16_all.deb ...
 Unpacking ubuntu-fan (0.12.16) ...
 Setting up python3-dotenv (0.19.2-1) ...
 Setting up python3-texttable (1.6.4-1) ...
 Setting up python3-docopt (0.6.2-4) ...
 Setting up dnsmasq-base (2.86-1.1ubuntu0.3) ...
 Setting up runc (1.1.4-0ubuntu1~22.04.3) ...
 Setting up dns-root-data (2021011101) ...
 Setting up bridge-utils (1.7-1ubuntu3) ...
 Setting up pigz (2.6-1) ...
 Setting up containerd (1.6.12-0ubuntu1~22.04.3) ...
 Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
 Setting up python3-websocket (1.2.3-1) ...
 Setting up python3-dockerpty (0.4.1-2) ...
 Setting up ubuntu-fan (0.12.16) ...
 Created symlink /etc/systemd/system/multi-user.target.wants/ubuntu-fan.service → /lib/systemd/system/ubuntu-fan.service.
 Setting up python3-docker (5.0.3-1) ...
 Setting up docker.io (20.10.21-0ubuntu1~22.04.3) ...
 Adding group `docker' (GID 120) ...
 Done.
 Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
 Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
 Setting up docker-compose (1.29.2-1) ...
 Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
 Processing triggers for man-db (2.10.2-1) ...
 Scanning processes...                                                                                                                                                                                                                                            
 Scanning processor microcode...                                                                                                                                                                                                                                  
 Scanning linux images...                                                                                                                                                                                                                                         

Running kernel seems to be up-to-date.

The processor microcode seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
 root@dns-server:/home/public/software/dns#

- 再次用docker-compose启动容器
会发现linux系统已经能执行docker-compose命令,但是最终是报错。

root@ami-home-gateway:/home/david/software/dns# ls
 docker-compose.yml
 root@ami-home-gateway:/home/david/software/dns# docker-compose up -d
 /snap/docker/2285/lib/python3.6/site-packages/paramiko/transport.py:33: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
   from cryptography.hazmat.backends import default_backend
 Creating network "dns_main" with the default driver
 Pulling web (sameersbn/bind:9.16.1-20200524)...
 9.16.1-20200524: Pulling from sameersbn/bind
 d51af753c3d3: Pull complete
 fc878cd0a91c: Pull complete
 6154df8ff988: Pull complete
 fee5db0ff82f: Pull complete
 7d5f2b88fbe1: Pull complete
 677da372f47f: Pull complete
 4adaef8a17ca: Pull complete
 00abb6dce6f7: Pull complete
 d7852cfdd714: Pull complete
 Digest: sha256:685d9404bf08c177413a7448bfdb7ae71ee002a3fbf917fd8d46d4aadd687522
 Status: Downloaded newer image for sameersbn/bind:9.16.1-20200524
 Creating dns ... 
 Creating dns ... error

ERROR: for dns  Cannot start service web: driver failed programming external connectivity on endpoint dns (7113503da0649c0f745f4a53c16c3c1de24b767f6fbbf816747bf04d987fe803): Error starting userland proxy: listen udp4 0.0.0.0:53: bind: address already in use

ERROR: for web  Cannot start service web: driver failed programming external connectivity on endpoint dns (7113503da0649c0f745f4a53c16c3c1de24b767f6fbbf816747bf04d987fe803): Error starting userland proxy: listen udp4 0.0.0.0:53: bind: address already in use
 ERROR: Encountered errors while bringing up the project.

上边提示的很清楚,因为DNS需要的UDP53端口,被Ubuntu占用了,

3、修改物理服务器

修改/etc/systemd/resolved.conf文件

root@amicore:~# cd /etc/systemd/
root@amicore:/etc/systemd# ls
journald.conf  logind.conf  network  networkd.conf  pstore.conf  resolved.conf  sleep.conf  system  system.conf  timesyncd.conf  user  user.conf
 root@amicore:/etc/systemd# vi resolved.conf

文件修改两个地方

#  This file is part of systemd.
 #
 #  systemd is free software; you can redistribute it and/or modify it under the
 #  terms of the GNU Lesser General Public License as published by the Free
 #  Software Foundation; either version 2.1 of the License, or (at your option)
 #  any later version.
 #
 # Entries in this file show the compile time defaults. Local configuration
 # should be created by either modifying this file, or by creating "drop-ins" in
 # the resolved.conf.d/ subdirectory. The latter is generally recommended.
 # Defaults can be restored by simply deleting this file and all drop-ins.
 #
 # Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
 #
 # See resolved.conf(5) for details.

[Resolve]
 # Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
 # Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
 # Google:     8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
 # Quad9:      9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
 # 第一个改动,把这里的IP地址改成服务器在局域网中的地址
DNS=192.168.3.254
 #FallbackDNS=
 #Domains=
 #DNSSEC=no
 #DNSOverTLS=no
#MulticastDNS=no
 #LLMNR=no
 #Cache=no-negative
 #CacheFromLocalhost=no
 # 第二个改动,把#号去掉,yes改成no
DNSStubListener=no
 #DNSStubListenerExtra=
 #ReadEtcHosts=yes
 #ResolveUnicastSingleLabel=no

确认一下是否生效了?

重新启动服务器后:

root@amicore:/etc/systemd# cd /etc
root@amicore:/etc# vi resolv.conf

### 文件内容如下

# This is /run/systemd/resolve/resolv.conf managed by man:systemd-resolved(8).
 # Do not edit.
 #
 # This file might be symlinked as /etc/resolv.conf. If you're looking at
 # /etc/resolv.conf and seeing this text, you have followed the symlink.
 #
 # This is a dynamic resolv.conf file for connecting local clients directly to
 # all known uplink DNS servers. This file lists all configured search domains.
 #
 # Third party programs should typically not access this file directly, but only
 # through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
 # different way, replace this symlink by a static file or a different symlink.
 #
 # See man:systemd-resolved.service(8) for details about the supported modes of
 # operation for /etc/resolv.conf.

nameserver 192.168.3.1
 search .

nameserver只有192.168.3.1证明没有生效,得修改

root@amicore:/etc# rm -f resolv.conf
root@amicore:/etc# sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

再次查看,竟然还是没有生效,reboot服务器吧!
生效后文件内容如下

# This is /run/systemd/resolve/resolv.conf managed by man:systemd-resolved(8).
 # Do not edit.
 #
 # This file might be symlinked as /etc/resolv.conf. If you're looking at
 # /etc/resolv.conf and seeing this text, you have followed the symlink.
 #
 # This is a dynamic resolv.conf file for connecting local clients directly to
 # all known uplink DNS servers. This file lists all configured search domains.
 #
 # Third party programs should typically not access this file directly, but only
 # through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
 # different way, replace this symlink by a static file or a different symlink.
 #
 # See man:systemd-resolved.service(8) for details about the supported modes of
 # operation for /etc/resolv.conf.

nameserver 192.168.3.254
 nameserver 192.168.3.1
 search .

4、再次用docker-compose启动容器

先前的安装是失败了的,重新运行

docker-compose up -d

发现成功了

标签:Dockers,...,dns,conf,DNS,ubuntu,服务器,docker,python3
From: https://www.cnblogs.com/amisoft/p/17537369.html

相关文章

  • 麒麟V10服务器PHP连接MySQL报错PHP Warning: mysqli_connect(): Unexpected server r
     1.问题描述这个警告表示在进行缓存的caching_sha2认证过程中,服务器返回了一个意外的响应码99。这是由于MySQL服务器的配置或版本与使用的客户端库不兼容导致的。2.解决办法a.检查MySQL客户端版本:确保你使用的MySQL客户端版本与服务器版本兼容。如果......
  • 关于Azure-平台-Redhat-Linux-服务器时间同步的问题解决
    首先说明一下,关于Azure平台中国区,是没有RedhatLinux系统镜像的于是笔者这边是通过在Windows系统 Hyper-V管理器中安装完Redhat8.x操作系统后,最后将系统磁盘转换成转换为VHD格式然后经过一系列操作、最终在Azure平台上形成了自己的并且加固过的RedHatEnterpriseLinuxre......
  • 阿里云ECS服务器回滚服务器遇到的一些问题
    由于阿里云的ECS服务器系统盘快被占满了,清理垃圾也不理想,幸好早一些时间对系统盘有快照备份.于是进行了快照回滚。回滚后网站无法访问,安装的宝塔也是,通过VNC远程登陆,发现服务器端口正常,阿里云安全组也没问题,想到可能是阿里云服务器本身的一些问题。于是联系了客服。通过在......
  • 解决“Host key verification failed”远程连接linux服务器 could not establish conn
    在使用vscode远程连接linux服务器时,遇到了个报错:couldnotestablishconnectionto我用的服务器是腾讯云轻应用。查了半天看到阿里云文档里有类似的解决方法,最后得到解决。发现是本地缓存的问题?使用SSH远程连接Linux系统的ECS实例时,提示“Hostkeyverificationfailed”错误怎......
  • Jenkins服务器安装及使用文档。
    准备环境Ubuntu20.04.6LTS、Linux5.4.0-148-genericx86_64、jdk-jdk1.8.0_361、maven-3.9.3、git-2.25.11、下载Jenkins.war包,并放到随意位置(你自己定)https://get.jenkins.io/war-stable/2.346.3/2、将启动脚本jenkins.sh放入war包同一路径下#!/bin/bashAppName=jenk......
  • Linux服务器之间进行文件目录映射/挂载-优化
    转自:https://www.cnblogs.com/tanshaoxiaoji/p/linux_nfs.html稍有优化需要实现的功能为:将192.168.10.10服务器下的/home/要映射的目录/,映射为192.168.10.90服务器下的/home/被映射的目录/。1、分别在192.168.10.10、192.168.10.90服务器上安装nfs、rpcbind;yuminst......
  • 国产方德高可信服务器操作系统V4.0的安装
    前言中科方德积极参与欧拉开源社区工作,发布了基于欧拉开源操作系统的方德高可信服务器操作系统V4.0(欧拉版)。此款操作系统可提供高可信支持,为企业级用户提供稳定、高效的软件运行支撑环境,满足系统稳定性、安全性、可靠性等要求,适用于党政军及金融、电信、能源、交通及医疗卫生等各......
  • 计算机与服务器之间的关系
    1.计算机1.1计算机的起源历史计算机的历史可以追溯到200多年前。最初由数学家和企业家提出的理论,在19世纪,机械计算机的设计和制造是为了解决日益复杂的数字运算挑战。到20世纪初,技术的进步使计算机变得越来越复杂,计算机变得更大、更强大。今天,计算机几乎无法从19世纪的......
  • 宝塔搭建出现连接不到服务器 搭建宝塔8.0 面板会出现 连接丢失需要重新连接
    搭建宝塔8.0  面板会出现连接丢失需要重新连接碰见这个问题因为宝塔的8.0 镜像换了需要重新执行一下宝塔镜像btpipinstallsimple-websocket==0.10.0&&bt1  执行完成之后出现这个就可以使用面板 ......
  • 服务器io测试工具-fio
    Fio是一个I/O工具,旨在用于基准测试和压力/硬件验证。它支持19种不同类型的I/O引擎(sync、mmap、libaio、posixaio、SGv3、splice、null、network、syslet、guasi、solarisaio等)、I/O优先级(适用于较新的Linux内核)、评估I/O、分叉或线程作业等等。它可以在块设备和文件......