dnsmasq 是一个轻量级的 DNS 和 DHCP 服务器,广泛应用于局域网中。以下是安装和配置 dnsmasq 的一般步骤
菜大胆Astrill网络梯子2026-09-05230
安装 dnsmasq 根据你的操作系统,使用相应的方法安装 dnsmasq。 在 Ubuntu/Debian 系统中: 更新软件包列表:sudo apt update 安装 dnsmasq:sudo apt install dnsmasq 启动并设置开机启动:sudo systemctl start dnsmasq sudo systemctl enable dnsmasq 在 CentOS/RHEL 系统中: 更新软件包列表:sudo yum update 安装 dnsmasq:sudo yum install dnsmasq 启动并设置开机启动:sudo systemctl start dnsmasq sudo systemctl enable dnsmasq 在 Windows 系统中: 下载 dnsmasq 的 Windows 版本,通常可以从 官方网站 获取。 双击安装文件,按照提示进行安装。 在 macOS 系统中: 使用 Homebrew 安装:brew install dnsmasq 启动 dnsmasq:dnsmasq --no-daemon --interface=eth --conf-file=/usr/local/etc/dnsmasq.conf 配置 dnsmasq 创建或编辑 dnsmasq 的配置文件,通常位于 /etc/dnsmasq.conf(Linux)或其他路径(Windows/macOS)。 在 Linux 中: 打开配置文件: sudo nano /etc/dnsmasq.conf 配置 DNS 和 DHCP: interface=eth dhcp-range=192.168.1./24,192.168.1.1 interface=eth:指定要绑定的网络接口。 dhcp-range=192.168.1./24,192.168.1.1:配置 DHCP 范围,168.1./24 是子网,168.1.1 是 DHCP 服务器地址。 保存并退出编辑器。 在 Windows 中: 打开 dnsmasq 的配置文件,通常位于 C:\Program F...
安装 dnsmasq
根据你的操作系统,使用相应的方法安装 dnsmasq。
在 Ubuntu/Debian 系统中:
- 更新软件包列表:
sudo apt update
- 安装 dnsmasq:
sudo apt install dnsmasq
- 启动并设置开机启动:
sudo systemctl start dnsmasq sudo systemctl enable dnsmasq
在 CentOS/RHEL 系统中:
- 更新软件包列表:
sudo yum update
- 安装 dnsmasq:
sudo yum install dnsmasq
- 启动并设置开机启动:
sudo systemctl start dnsmasq sudo systemctl enable dnsmasq
在 Windows 系统中:
- 下载 dnsmasq 的 Windows 版本,通常可以从 官方网站 获取。
- 双击安装文件,按照提示进行安装。
在 macOS 系统中:
- 使用 Homebrew 安装:
brew install dnsmasq
- 启动 dnsmasq:
dnsmasq --no-daemon --interface=eth --conf-file=/usr/local/etc/dnsmasq.conf
配置 dnsmasq
创建或编辑 dnsmasq 的配置文件,通常位于 /etc/dnsmasq.conf(Linux)或其他路径(Windows/macOS)。
在 Linux 中:
-
打开配置文件:
sudo nano /etc/dnsmasq.conf
-
配置 DNS 和 DHCP:
interface=eth dhcp-range=192.168.1./24,192.168.1.1
interface=eth:指定要绑定的网络接口。dhcp-range=192.168.1./24,192.168.1.1:配置 DHCP 范围,168.1./24是子网,168.1.1是 DHCP 服务器地址。
-
保存并退出编辑器。
在 Windows 中:
- 打开 dnsmasq 的配置文件,通常位于
C:\Program Files\dnsmasq\dnsmasq.conf。 - 配置 DNS 和 DHCP:
interface=eth dhcp-range=192.168.1./24,192.168.1.1
在 macOS 中:
- 打开 dnsmasq 的配置文件,通常位于
~/.dnsmasq。 - 配置 DNS 和 DHCP:
interface=eth dhcp-range=192.168.1./24,192.168.1.1
启动 dnsmasq
根据你的操作系统启动 dnsmasq:
在 Linux 中:
sudo systemctl start dnsmasq
在 Windows 中:
双击启动 dnsmasq 的桌面 shortcut。
在 macOS 中:
在终端中运行:
dnsmasq --no-daemon --interface=eth --conf-file=/usr/local/etc/dnsmasq.conf
设置开机启动(可选)
在 Linux 中,设置开机启动:
sudo systemctl enable dnsmasq
测试配置
- 查看 dnsmasq 的状态:
sudo systemctl status dnsmasq
- 在同一子网内的设备上测试 DNS 和 DHCP:
- DNS:
nslookup localhost
- DHCP:
dhclient
- DNS:
常见问题
- 配置错误:检查配置文件是否有语法错误,确保所有设置正确无误。
- 服务无法启动:检查防火墙设置,确保 dnsmasq 的端口(53)未被阻挡。
- 权限问题:确保运行 dnsmasq 的用户有足够的权限。
通过以上步骤,你应该能够成功安装并配置 dnsmasq,管理局域网内的 DNS 和 DHCP 服务。

相关文章








