OpenWrt Configuring DHCP and DNS on OpenWrt
On Friday, November 1, 2013 Labels: Cracking WEP with BackTrack, OpenWrt Configuring DHCP and DNS on OpenWrt
Configuring DHCP and DNS on OpenWrt
This page contains an overview on how to configure DHCP and DNS on a Linksys WRT54GS running OpenWrt.
Introductory Information
The OpenWrt build includes a dnsmasq, a lightweight package which provides a caching DNS server and DHCP server. The DHCP server integrates with the DNS server, allowing it resolve hostnames for DHCP-allocated addresses, if desired.
A single instance of dnsmasq can be configured to provide different DNS and DHCP services on separate network interfaces.
Configuring DNSMasq
Edit Configuration File
Edit /etc/dnsmasq.conf and change the configuration to suit your environment.
I am using dnsmasq to provide DHCP and DNS services to the LAN ports, as well as to the WAN port (which I am using as an administrative interface only, with no routed access to the LAN / WLAN ports for any clients connected to the WAN port).
Note that the example below is for a WRT where the bridge has been broken, ie, the WLAN and LAN ports are not bridged, but have separate IPs, with the WRT routing traffic between them.
The contents of /etc/dnsmasq.conf on my WRT is similar to this:
# filter what we send upstream
domain-needed
bogus-priv
filterwin2k
# allow /etc/hosts and dhcp lookups via *.lan
local=/lan/
domain=houwels.sgnet.wafreenet
# enable dhcp (start,end,netmask,leasetime)
dhcp-authoritative
# dhcp range for LAN ports - 10.60.68.16/29 = 10.60.68.17-10.60.68.22
dhcp-range=vlan0,10.60.68.18,10.60.68.22,255.255.255.248,48h
# dhcp range for WAN port - 192.168.1.0/24
dhcp-range=vlan1,192.168.1.2,192.168.1.10,255.255.255.0,5m
# dhcp lease file
dhcp-leasefile=/tmp/dhcp.leases
# use /etc/ethers for static hosts; same format as --dhcp-host
# []
read-ethers
# default gateway and dns for LAN ports
dhcp-option=vlan0,3,10.60.68.17
dhcp-option=vlan0,6,10.60.68.17
The IP address of the LAN interface on my WRT is 10.60.68.17, so it is used as the default gateway and DNS by all clients connected to the LAN interfaces.
Specifying Static DHCP IP Addresses
If desired, details for any static DHCP IP addresses are specified in /etc/ethers, in the following format:
# desktop
xx:xx:xx:xx:xx:xx 10.60.68.18
# laptop
xx:xx:xx:xx:xx:xx 10.60.68.19
# another desktop
xx:xx:xx:xx:xx:xx 10.60.68.20
Note that you need to specify the actual MAC addresses in /etc/ethers, but I've replaced the MAC addresses with xx:xx:xx:xx:xx:xx in the example above for obvious reasons.
Completing Configuration
Edit init script
The default init script for dnsmasq contains some code to determine the LAN interface name, as well as the IP address and netmask, and assumes DHCP will only be active on the LAN interface.
We don't need these smarts in the init script, as everything is fully defined in the configuration file. Edit the init script /etc/init.d/S60dnsmasq, and replace the contents with
#!/bin/sh
/usr/sbin/dnsmasq
Restart dnsmasq
To make the changed configuration take effect, dnsmasq must be restarted. Restart it using the following:
killall dnsmasq
/etc/init.d/S60dnsmasq
Now the configuration can be tested by connecting a client PC to the LAN and WAN ports, and verify that the client PC can obtain a DHCP IP address, and can communicate with the DNS server.
No comments:
Post a Comment