【Mac】dnsmasq 安装与配置

一. 问题

  前期搭建好 nginx 后,一直都是本机环境,但是我想要内网环境,比如: 局域网服务呢?

二. 安装

  1. 使用如下命令,搜索一下潜在的包:
$ brew search dnsmasq

==> Formulae
dnsmasq                                  dnsmap
  1. 使用如下命令进行安装,命令参考如下:
$ brew install dnsmasq

==> Downloading https://ghcr.io/v2/homebrew/core/dnsmasq/manifests/2.86
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/dnsmasq/blobs/sha256:d4e2c92c41
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Pouring dnsmasq--2.86.monterey.bottle.tar.gz
==> Caveats
To restart dnsmasq after an upgrade:
  sudo brew services restart dnsmasq
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/dnsmasq/sbin/dnsmasq --keep-in-foreground -C /usr/local/etc/dnsmasq.conf -7 /usr/local/etc/dnsmasq.d,*.conf
==> Summary
🍺  /usr/local/Cellar/dnsmasq/2.86: 10 files, 628.5KB
==> Running `brew cleanup dnsmasq`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

三. 配置

配置文件,所在路径:

/usr/local/etc/dnsmasq.conf
  1. 建议对配置文件做个备份, 然后再修改, 已防修改坏了, 最多还原成原始状态, 然后继续修改;
  2. 原始备份文件内容如下:
# Configuration file for dnsmasq.
#
# Format is one option per line, legal options are the same
# as the long options legal on the command line. See
# "/usr/local/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.

# Listen on this specific port instead of the standard DNS port
# (53). Setting this to zero completely disables DNS function,
# leaving only DHCP and/or TFTP.
#port=5353

# The following two options make you a better netizen, since they
# tell dnsmasq to filter out queries which the public DNS cannot
# answer, and which load the servers (especially the root servers)
# unnecessarily. If you have a dial-on-demand link they also stop
# these requests from bringing up the link unnecessarily.

# Never forward plain names (without a dot or domain part)
#domain-needed
# Never forward addresses in the non-routed address spaces.
#bogus-priv

# Uncomment these to enable DNSSEC validation and caching:
# (Requires dnsmasq to be built with DNSSEC option.)
#conf-file=%%PREFIX%%/share/dnsmasq/trust-anchors.conf
#dnssec

# Replies which are not DNSSEC signed may be legitimate, because the domain
# is unsigned, or may be forgeries. Setting this option tells dnsmasq to
# check that an unsigned reply is OK, by finding a secure proof that a DS 
# record somewhere between the root and the domain does not exist. 
# The cost of setting this is that even queries in unsigned domains will need
# one or more extra DNS queries to verify.
#dnssec-check-unsigned

# Uncomment this to filter useless windows-originated DNS requests
# which can trigger dial-on-demand links needlessly.
# Note that (amongst other things) this blocks all SRV requests,
# so don't use it if you use eg Kerberos, SIP, XMMP or Google-talk.
# This option only affects forwarding, SRV records originating for
# dnsmasq (via srv-host= lines) are not suppressed by it.
#filterwin2k

# Change this line if you want dns to get its upstream servers from
# somewhere other that /etc/resolv.conf
#resolv-file=

# By  default,  dnsmasq  will  send queries to any of the upstream
# servers it knows about and tries to favour servers to are  known
# to  be  up.  Uncommenting this forces dnsmasq to try each query
# with  each  server  strictly  in  the  order  they   appear   in
# /etc/resolv.conf
#strict-order

# If you don't want dnsmasq to read /etc/resolv.conf or any other
# file, getting its servers from this file instead (see below), then
# uncomment this.
#no-resolv

# If you don't want dnsmasq to poll /etc/resolv.conf or other resolv
# files for changes and re-read them then uncomment this.
#no-poll

# Add other name servers here, with domain specs if they are for
# non-public domains.
#server=/localnet/192.168.0.1

# Example of routing PTR queries to nameservers: this will send all
# address->name queries for 192.168.3/24 to nameserver 10.1.2.3
#server=/3.168.192.in-addr.arpa/10.1.2.3

# Add local-only domains here, queries in these domains are answered
# from /etc/hosts or DHCP only.
#local=/localnet/

# Add domains which you want to force to an IP address here.
# The example below send any host in double-click.net to a local
# web-server.
#address=/double-click.net/127.0.0.1

# --address (and --server) work with IPv6 addresses too.
#address=/www.thekelleys.org.uk/fe80::20d:60ff:fe36:f83

# Add the IPs of all queries to yahoo.com, google.com, and their
# subdomains to the vpn and search ipsets:
#ipset=/yahoo.com/google.com/vpn,search

# You can control how dnsmasq talks to a server: this forces
# queries to 10.1.2.3 to be routed via eth1
# server=10.1.2.3@eth1

# and this sets the source (ie local) address used to talk to
# 10.1.2.3 to 192.168.1.1 port 55 (there must be an interface with that
# IP on the machine, obviously).
# server=10.1.2.3@192.168.1.1#55

# If you want dnsmasq to change uid and gid to something other
# than the default, edit the following lines.
#user=
#group=

# If you want dnsmasq to listen for DHCP and DNS requests only on
# specified interfaces (and the loopback) give the name of the
# interface (eg eth0) here.
# Repeat the line for more than one interface.
#interface=
# Or you can specify which interface _not_ to listen on
#except-interface=
# Or which to listen on by address (remember to include 127.0.0.1 if
# you use 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在CentOS 7上安装和配置dnsmasq来进行内网域名解析,可以按照以下步骤进行操作: 1. 使用yum命令安装dnsmasq:`yum install dnsmasq -y` \[1\] 2. 修改dnsmasq配置文件:`vim /etc/dnsmasq.conf`,确保以下配置项正确设置: - 指定上游DNS服务器:`resolv-file=/etc/resolv.dnsmasq.conf` - 严格按照resolv-file文件中的顺序进行DNS解析:`strict-order` - 开启本地hosts文件和缓存的域名解析:`no-resolv` - 设置当前服务器的IP地址:`listen-address=192.168.119.12` - 指定解析记录文件的目录:`conf-dir=/etc/dnsmasq.d` - 添加自定义的DNS记录文件:`addn-hosts=/etc/dnsmasq.hosts` \[1\] \[2\] \[3\] 3. 创建并编辑上游DNS服务器配置文件:`vim /etc/resolv.dnsmasq.conf`,写入上游DNS服务器的IP地址,每行一个: ``` nameserver 119.29.29.29 nameserver 114.114.114.114 nameserver 8.8.8.8 nameserver 1.1.1.1 ``` 4. 创建并编辑自定义的DNS解析记录文件:`vim /etc/dnsmasq.hosts`,写入需要解析的域名和对应的IP地址,每行一个: ``` 123.206.16.61 pyyugo.cn 123.206.16.61 goyugo.cn ``` 5. 修改当前服务器的DNS域名服务器配置文件:`vim /etc/resolv.conf`,将nameserver指定为自建的dnsmasq服务器的IP地址:`nameserver 192.168.119.12` 6. 重启dnsmasq服务:`systemctl restart dnsmasq` 7. 确认域名解析是否生效:可以使用`nslookup`或`dig`命令来查询指定域名的解析结果,例如:`nslookup pyyugo.cn` \[1\] 通过以上步骤,你应该能够在CentOS 7上成功安装和配置dnsmasq来进行内网域名解析。 #### 引用[.reference_title] - *1* [centos7安装dnsmasq局域网dns](https://blog.csdn.net/weixin_30642267/article/details/99929828)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [centos7配置dnsmasq](https://blog.csdn.net/qq_39689711/article/details/129271125)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [CentOS安装配置DNSMasq](https://blog.csdn.net/tiger57/article/details/129594344)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值