Labels

Android (1) Apache (1) bash (2) boost (2) C (36) C++ (4) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (3) Dreamweaver (2) Eclipse (3) fail2ban (5) git (6) GitHub (5) Hacking (4) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (33) javascript (3) Linux (181) Mac (21) Machine Learning (1) mySQL (52) Netbeans (6) Networking (1) Nexus (1) OpenVMS (6) Oracle (3) Pandas (3) php (17) Postgresql (8) Python (9) raid (1) RedHat (15) Samba (2) Slackware (52) SQL (14) ssh (1) svn (1) tar (1) ThinkPad (1) Virtualbox (4) Visual Basic (2) Visual Studio (1) Windows (5) wire (1)

Tuesday, 28 July 2026

DHCP server on Slackware using dnsmasq

 Example configuration file:


# Listen on internal network interface
interface=eth0
listen-address=127.0.0.1,192.168.1.1

domain=company.local

# Restrict local domain queries to the local network
local=/company.local/

# Automatically add .local to simple, short hostnames
expand-hosts

# Reads entries from /etc/hosts AND your custom dhcp-hostsfile/addn-hosts
local-service

# Tells dnsmasq to answer queries for short names (e.g. 'printer' instead of 'printer.local')
domain-needed
bogus-priv

# Optional: Prevent forwarding plain names (without dots) to upstream servers
domain-needed

# Upstream public DNS servers

server=1.1.1.3

server=1.0.0.3

server=1.1.1.2

server=1.0.0.2

server=8.8.8.8

server=8.8.4.4

server=1.1.1.1

server=1.0.0.1

# Either or...

strict-order

#all-servers


# DHCP Range and Lease Time (12 hours)

dhcp-range=192.168.1.50,192.168.1.200,255.255.255.0,12h


# Gateway & Local DNS server push

dhcp-option=option:router,192.168.1.1

dhcp-option=option:dns-server,192.168.1.2


# Fixed IPs for core servers (MAC address mapping)

dhcp-host=AA:BB:CC:DD:EE:FF,appserver,192.168.1.10,infinite

log-facility=/var/log/dnsmasq.log

dhcp-hostsfile=/etc/dnsmasq.hosts


NOTES:

domain=company.local: Defines your local domain name. When DHCP clients request an IP address, Dnsmasq automatically appends .company.local to their hostname (e.g., a workstation named pc-smith becomes pc-smith.company.local). It also pushes this domain to DHCP clients as their search domain.

local=/company.local/: Directs Dnsmasq to treat any query ending in .company.local as strictly internal. It will never forward queries for .company.local to upstream internet DNS servers. If a local name isn't found in Dnsmasq's lease table or local hosts file, it immediately returns NXDOMAIN (non-existent domain).

option:router (Option 3): Sets the default gateway pushed to clients. In this setup, clients will send all non-local internet traffic through 192.168.1.1.

option:dns-server (Option 6): Tells clients which DNS server address to use. By pointing this to 192.168.1.2 (the IP of your Slackware box running Dnsmasq), all client DNS traffic routes through your local server.

Ensure /etc/resolv.conf has the search domain as listed above and also name server; example:

search company.local
nameserver 127.0.0.1


Check dnsmasq.leases file for current IP allocations.

To Block/ignore Mac addresses and assign to different range

# -------------------------------------------------------------------
# Scenario 1: Blocked MACs
# -------------------------------------------------------------------
# Silently ignore any DHCP request tagged as 'blocked'
dhcp-ignore=tag:blocked

# -------------------------------------------------------------------
# Scenario 2: Special Group Configuration
# -------------------------------------------------------------------
# Define the IP pool strictly for clients tagged as 'special_group'
dhcp-range=set:special_group,192.168.1.201,192.168.1.220,255.255.255.0,12h

# Optional: Custom options for the special group (e.g., custom DNS or gateway)
# dhcp-option=tag:special_group,option:dns-server,1.1.1.1
# dhcp-option=tag:special_group,option:router,192.168.1.254


then in the /etc/dnsmasq.hosts file;

# Standard Static IP + Hostname
00:11:22:33:44:55,192.168.1.50,mydevice

# --- Blocked Devices ---
# These devices get zero IP response from dnsmasq
00:11:22:33:44:55,set:blocked
11:22:33:44:55:66,set:blocked
DE:AD:BE:EF:66:77,set:blocked

# --- Special Group (Dynamic IP from .201-.220 pool) ---
AA:BB:CC:DD:EE:FF,set:special_group
22:33:44:55:66:77,set:special_group,iot-device

# --- Special Group + Fixed Static IP ---
33:44:55:66:77:88,set:special_group,192.168.1.205,special-server



To Assign to different subnets

If server has multiple network interfaces or VLAN subnets (e.g., 192.168.1.0/24 on eth0 and 10.0.0.0/24 on eth1), you can assign custom gateways and DNS servers alongside the IP range using tags:

# Define two distinct subnets
dhcp-range=set:vlan10,10.0.0.100,10.0.0.200,255.255.255.0,12h

# Tag specific MAC to land on VLAN 10
dhcp-host=00:11:22:33:44:55,set:vlan10

# Push custom gateway/router (option 3) to devices in that tag group
dhcp-option=tag:vlan10,option:router,10.0.0.1

See also here

No comments:

Post a Comment

Note: only a member of this blog may post a comment.