← 返回命令列表

Linux command

dnsmasq 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Start dnsmasq

dnsmasq

Start with specific config file

dnsmasq -C [/etc/dnsmasq.conf]

Run in foreground

dnsmasq -d

Test configuration

dnsmasq --test

Start with DHCP

dnsmasq --dhcp-range=[192.168.1.50,192.168.1.150,12h]

Specify upstream DNS server

dnsmasq --server=[8.8.8.8]

Start as authoritative

dnsmasq --local=/[mydomain.local]/

Block ads

dnsmasq --addn-hosts=[/etc/hosts.ads]

说明

dnsmasq is a lightweight DNS forwarder and DHCP server designed for small networks. It provides DNS caching, DHCP, TFTP, and PXE boot services in a single, efficient package. As a DNS server, dnsmasq forwards queries to upstream servers and caches responses, reducing latency and bandwidth. It reads /etc/hosts for local name resolution and supports custom local domains. It can also provide DNS-based ad blocking. The DHCP server provides dynamic and static address assignment with support for BOOTP, PXE, and TFTP for network booting. dnsmasq is commonly used in routers, embedded systems, and as a local development DNS/DHCP solution.

参数

-d
Debug mode, foreground, log to stderr.
-k
Keep in foreground, don't daemonize.
-C _file_
Use specified configuration file.
--test
Check configuration syntax.
-p _port_
Listen on specified DNS port.
-a _address_
Listen on specified address.
--dhcp-range= _range_
Enable DHCP with address range.
--dhcp-host= _config_
Static DHCP assignment.
-h, --no-hosts
Don't read /etc/hosts.
-H, --addn-hosts= _file_
Additional hosts file.
--local= _domain_
Answer authoritatively for domain.
--server= _address_
Upstream DNS server.
-R, --no-resolv
Don't read /etc/resolv.conf for upstream servers.
-r, --resolv-file= _file_
Read upstream nameservers from specified file instead of /etc/resolv.conf.
--cache-size= _n_
DNS cache size (default 150).
--address= _/domain/address_
Return a specific address for all hosts in a domain. Useful for blocking or redirecting.
--log-queries
Log DNS queries.

FAQ

What is the dnsmasq command used for?

dnsmasq is a lightweight DNS forwarder and DHCP server designed for small networks. It provides DNS caching, DHCP, TFTP, and PXE boot services in a single, efficient package. As a DNS server, dnsmasq forwards queries to upstream servers and caches responses, reducing latency and bandwidth. It reads /etc/hosts for local name resolution and supports custom local domains. It can also provide DNS-based ad blocking. The DHCP server provides dynamic and static address assignment with support for BOOTP, PXE, and TFTP for network booting. dnsmasq is commonly used in routers, embedded systems, and as a local development DNS/DHCP solution.

How do I run a basic dnsmasq example?

Run `dnsmasq` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -d do in dnsmasq?

Debug mode, foreground, log to stderr.