当前位置: 首页> 教育> 幼教 > Ubuntu server 24.04 (Linux) 搭建DNS服务器 通过Nginx实现UDP/TCP负载均衡 轻量级dnsmasq服务器

Ubuntu server 24.04 (Linux) 搭建DNS服务器 通过Nginx实现UDP/TCP负载均衡 轻量级dnsmasq服务器

时间:2025/7/13 4:32:33来源:https://blog.csdn.net/tonyhi6/article/details/139372504 浏览次数:0次

一 系统运行环境

test@test:~$ cat /etc/os-release 
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
test@test:~$ uname -a
Linux test 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
test@test:~$ /usr/local/openresty/nginx/sbin/nginx -v
nginx version: openresty/1.25.3.1

二 安装dnsmasq

1 Ubuntu24 输入如下安装

sudo apt update
sudo apt-get  install dnsmasq

2 查看版本

test@test:~$ dnsmasq -v
Dnsmasq version 2.90  Copyright (c) 2000-2024 Simon Kelley
Compile time options: IPv6 GNU-getopt DBus no-UBus i18n IDN2 DHCP DHCPv6 no-Lua TFTP conntrack ipset nftset auth cryptohash DNSSEC loop-detect inotify dumpfileThis 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.

三 Dnsmasq 配置

1 安装配置一台实例

#增加如下
sudo vim  /etc/dnsmasq.conf
#启动端口
port=853
#不解析/etc/hosts文件
no-hosts
#解析域名记录
addn-hosts=/etc/dnsmasq.d/dnsmasq.hosts
#上游dns
resolv-file=/etc/dnsmasq.d/resolv.dnsmasq.conf
#禁用轮询机制
no-poll
#按照顺序解析
strict-order
#记录dns查询日志
log-queries
#设置日志文件
log-facility=/var/log/dnsmasq.log
#本地缓存时间,根据实际情况配置
local-ttl=86500
#缓存数量
cache-size=90000
#监听地址
listen-address=192.168.50.18,127.0.0.1
#增加解析记录
sudo vim  /etc/dnsmasq.d/dnsmasq.hosts
192.168.50.18  www.test.com
#设置上游DNS地址
sudo  vim /etc/dnsmasq.d/resolv.dnsmasq.conf
nameserver 223.6.6.6
nameserver 114.114.114.114
#启动
sudo systemctl start dnsmasq
#系统启动
sudo systemctl enable dnsmasq
#查看状态
sudo systemctl status dnsmasq
#语法检查
sudo  dnsmasq --test
dnsmasq: syntax check OK.

2 参考例子,另外在安装配置一台dnsmasq服务器 

四 openresty(Nginx) 安装 可参考:ubuntu server 24.04 (Linux) 源码编译安装 OpenResty 1.25.3.1 Released-CSDN博客

五 Nginx 配置

#增加udp配置,在http段外面(⊙﹏⊙)
stream {# udp负载均衡upstream dns-server {server 192.168.50.19:53;server 192.168.50.18:8053;}server {listen 53 udp reuseport;proxy_pass dns-server;proxy_timeout 9s; #最长的超时时间proxy_responses 1; #连接超时时间error_log /var/log/dnsmasq.log;}}
#重新加载配置
sudo /usr/local/openresty/nginx/sbin/nginx -s reload

六  客户端UDP 负载均衡测试

windows 10 dns 配置为nginx 服务器的IP

查看2台服务器 dnsmasq 日志

关键字:Ubuntu server 24.04 (Linux) 搭建DNS服务器 通过Nginx实现UDP/TCP负载均衡 轻量级dnsmasq服务器

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: