当前位置: 首页 > news >正文

Linux部署dnsmasq软件

1、dnsmasq软件介绍

dnsmasq 是一款轻量级的网络服务软件,主要用于提供 DNS(域名系统)和 DHCP(动态主机配置协议)服务

作用

  1. 提高网络效率

    • 通过 DNS 缓存,减少网络延迟。
    • 减少对外部 DNS 请求的数量。
  2. 自动 IP 配置

    • 自动为新连接的设备分配 IP 地址,无需手动设置,降低配置复杂性。
  3. 增强网络安全

    • 通过内置的过滤功能,可以限制不必要的 DNS 请求,提高网络安全性。
  4. 简化网络管理

    • 集成 DNS 和 DHCP 服务,使网络管理更加方便。

2、安装

yum -y install dnsmasq

[master-61 root ~] # yum install -y dnsmasq 
Loaded plugins: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                            | 3.6 kB  00:00:00     
epel                                                                            | 4.3 kB  00:00:00     
extras                                                                          | 2.9 kB  00:00:00     
updates                                                                         | 2.9 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package dnsmasq.x86_64 0:2.76-17.el7_9.3 will be installed
--> Processing Dependency: libnettle.so.4()(64bit) for package: dnsmasq-2.76-17.el7_9.3.x86_64
--> Running transaction check
---> Package nettle.x86_64 0:2.7.1-9.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
 Package               Arch                 Version                        Repository             Size
=======================================================================================================
Installing:
 dnsmasq               x86_64               2.76-17.el7_9.3                updates               281 k
  stalling for dependencies:
 nettle                x86_64               2.7.1-9.el7_9                  updates               328 k

Transaction Summary
=======================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 608 k
Installed size: 1.3 M
Downloading packages:
(1/2): nettle-2.7.1-9.el7_9.x86_64.rpm                                          | 328 kB  00:00:00     
(2/2): dnsmasq-2.76-17.el7_9.3.x86_64.rpm                                       | 281 kB  00:00:00     
-------------------------------------------------------------------------------------------------------
Total                                                                  1.6 MB/s | 608 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : nettle-2.7.1-9.el7_9.x86_64                                                         1/2 
  Installing : dnsmasq-2.76-17.el7_9.3.x86_64                                                      2/2 
  Verifying  : dnsmasq-2.76-17.el7_9.3.x86_64                                                      1/2 
  Verifying  : nettle-2.7.1-9.el7_9.x86_64                                                         2/2 

Installed:
  dnsmasq.x86_64 0:2.76-17.el7_9.3                                                                     

Dependency Installed:
  nettle.x86_64 0:2.7.1-9.el7_9                                                                        

Complete!

3、创建dnsmasq配置文件,设置上游dns服务器地址,设置本地域名解析记录

[master-61 root ~] # vim /etc/dnsmasq.conf 

取消注释,指定上游dns服务器地址
resolv-file=/etc/resolv.dnsmasq.conf


指定运行地址是内网环境
listen-address=172.16.1.61

本地域名解析记录
addn-hosts=/etc/hosts.dnsmasq.conf


查找出配置文件中没有注释的内容
[master-61 root ~] # grep -Ev '^($|#)'  /etc/dnsmasq.conf 
resolv-file=/etc/resolv.dnsmasq.conf
listen-address=172.16.1.61
addn-hosts=/etc/hosts.dnsmasq.conf
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig

4、创建对应的数据文件

[master-61 root ~] # echo 'nameserver 233.5.5.5' > /etc/resolv.dnsmasq.conf

[master-61 root ~] # cat >/etc/hosts.dnsmasq.conf <<EOF
> 172.16.1.61 master-61
> 172.16.1.5 slb-5
> 172.16.1.6 slb-6
> 172.16.1.7 web-7
> 172.16.1.8 web-8
> 172.16.1.9 web-9
> 172.16.1.31 nfs-31
> 172.16.1.41 rsync-41
> 172.16.1.51 db-51
> EOF

5、 启动dnsmasq服务,生效加上的自定义记录

[master-61 root ~] # systemctl start dnsmasq

6、测试dnsmasq是否可以使用

先注释掉本地hosts解析记录
[master-61 root ~] # vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#内网ip       外网ip     主机名     机器的作用
#172.16.1.61  10.0.0.61  master-61  管理机
#172.16.1.5   10.0.0.5   slb-5      负载均衡服务器  
#172.16.1.6   10.0.0.6   slb-6      负载均衡服务器  
#172.16.1.7   10.0.0.7   web-7      web服务器       
#172.16.1.8   10.0.0.8   web-8      web服务器       
#172.16.1.9   10.0.0.9   web-9      web服务器       
#172.16.1.31  10.0.0.31  nfs-31     存储服务器      
#172.16.1.41  10.0.0.41  rsync-41   备份服务器     
#172.16.1.51  10.0.0.51  db-51      数据库服务器

发现ping不通了
[master-61 root ~] # ping web-7
ping: web-7: Name or service not known


需要指定本地的你dns配置文件的记录,使用dnsmasq的服务端地址
[master-61 root ~] # vim /etc/resolv.conf 
# Generated by NetworkManager
nameserver 172.16.1.61

相关文章:

  • 【前端】【面试】【功能函数】写一个JavaScript树形结构操作函数:`filter` 与 `forEach`
  • C++ QT 6.6.1 QCustomPlot的导入及使用注意事项和示例 | 关于高版本QT使用QCustomPlot报错问题解决的办法
  • vue+element ui 实现选择季度组件
  • Linux(CentOS)安装 Nginx
  • java23种设计模式-命令模式
  • 安全性质量属性场景
  • 策略模式结合SpringBoot
  • 银行信贷业务解析:运营与数据双视角下的业务本质与技术支撑
  • C#连接sql server
  • 什么是SEO通俗准确的解释
  • angular轮播图
  • 交换机与路由器连接方式
  • 2.25力扣每日一题--设计内存分配器
  • 排序算法适合的场景
  • TCP,http,WebSocket
  • android aosp系统定制如何监控系统性能
  • 改进的Siddon算法与原算法的区别及具体改进
  • SSL/TLS 协议、SSL证书 和 SSH协议 的区别和联系
  • 中级软考笔记-基础知识-8-网络与信息安全
  • 基于SpringBoot的精品水果线上销售平台系统设计与实现(源码+SQL脚本+LW+部署讲解等)
  • 2017招远网站建设/太原关键词优化报价
  • 建设网站需要花费什么费用/第三波疫情将全面大爆发
  • php7.3能装wordpress/seo建设招商
  • 佛山哪里有做网站的/上优化seo
  • wordpress入侵过程/seo作弊
  • 日本门户网站有哪些/百度联盟广告