Easy DNS and DHCP setup on Linux
DNS is short for Domain Name Service, it basically allows you to translate addresses like google.com to 74.125.45.100 (an IP addreess), this all happens in the background and you may not be aware of it (you don’t have to be, actually) — What you need to know is that this can impact the speed of your Internet browsing. If you need a background on DNS, visit my other post — Fast Internet Browsing.
You can install a DNS within your local network (that’s what this DIY guide is all about); it will improve significantly your Internet browsing speed — although it may not improve your limewire speed or YouTube speed.
It is also a good idea to install a DHCP (Dynamic Host Control Protocol) at the same time you will install a DNS, this way you can control certain aspects of the DHCP behavior like, which router to choose, where should workstations go to resolve IP addresses etc — DHCP options are quite a pain to set when using the built in DHCPs of your Linksys or DLink router, you won’t be able to set a lot of options — You don’t want to statically define IP information on all the workstations now, do you?
Installing dnsmasq on Debian 5 (Lenny)
While there are other DNS software, like BIND or djbdns, I like dnsmasq in particular because of the simplicity of installation and configuration.
You will need a default installation of Debian 5 for this DIY, you can refer to The Perfect installation – Debian Lenny . It could take you sometime, you may want to bookmark this page first, then come back to the guide when you’re done on the installation.
Are you back yet? Okay, now we need to install a couple of software. From the terminal, type
$ sudo apt-get update
$ sudo apt-get install dnsmasq ssh sysv-rc-conf
I included ssh on the install because I’m assuming this will be a headless server in your LAN, at some point you’d like to talk to it remotely (for configuration and monitoring). I included the he sysv-rc-conf because it’s a handy utility so that you can start/stop server programs — unless you’d like to do it the traditional way like “./etc/init.d/dnsmasq restart ..”
Configuring dnsmasq
You will need to edit dnsmasq.conf found in /etc/dnsmasq.conf, just type
$ sudo nano /etc/dnsmasq.conf
Don’t be overwhelmed by the size of dnsmasq, the authors and maintainers of dnsmasq did a pretty good of documenting the software, a lot of that documentation is actually found inside dnsmasq.conf.
Now, type the following lines at the top of your dnsmasq.conf, insert if (if you must) before the very first line of the default configuration. By default, every line of dnsmasq.conf is commented, you’re supposed to uncomment the ones you need to use. So, I thought I’d make the installation plain and simple for our purpose, don’t uncomment anything, just insert these codes right at the top of your dnsmasq.conf — don’t worry, I’ll explain what the lines mean.
expand-hosts domain mylan.com dhcp-range=192.168.1.5,192.168.1.100,24h dhcp-option=3,192.168.1.2
Line #3 means — you can reference workstations (or servers) inside your LAN using their shortnames, and DNS will take care of doing the FQDN for you (Fully Qualified Domain Name), for example; if you ping machine-one, the ping result will be machine-one.mylan.com
Line#4 Just declares the name of the domain you gave to your LAN – this doesn’t have to be registered, you can make up your own, it’s just in your LAN.
Line #6, the dhcp-range has 3 values (separated by comma), the first value (192.168.1.5) means that the DHCP server will start giving IP address using 192.168.1.5 when a workstation requests for an it. The second value (192.168.1.100) means that the last possible value your DHCP server will give to a workstation is 192.168.1.100). So your DHCP server can give out 95 unique IP address to 95 workstations in your LAN.
And finally, line #8 — means that when the DHCP server gives an IP address to machine-one, it will also tell machine-one where the Internet gateway is. In this case, the Internet gateway is 192.168.1.2 — You need to change this to suit your setup, the Internet gateway is the machine (or appliance) where you connected your modem. If you don’t write your own dhcp-option=3 .. then dnsmasq will assume that the Internet gateway is the same machine where dnsmasq is installed.
Now press
CTRL-O CTRL-X
ctrl-O saves the file, ctrl-X exits the editor (nano). You’re almost done, you just need to edit one more file, now type
$ sudo nano /etc/resolv.conf
Resolv.conf is the file which dnsmasq will use to resolve friendly-machine-names (like google.com) into their IP address counterparts, since you don’t have that information in your server, you need to point your resolv.conf to other machines that have more DNS information .. you need to point it to other DNS servers. You can use the ones that were provided to you by your ISP or you can use OpenDNS — which what I will use for this example. Just insert the following lines into your resolv.conf
nameserver 208.67.222.222 nameserver 208.67.220.220 # you can put other DNS servers here, like the ones your ISP gave you
Last step — we need to restart the dnsmasq service, you can do that by
$ sudo sysv-rc-conf
You will see a list of all the services running inside your Debian server, use the down arrow keys to select “dnsmasq”, then press the minus sign (-), wait for a while until you see a notification. You will have to press enter to dismiss the notification, then press the plus sign (+) to start the service.
That’s it, you now have a local caching name server and a DHCP server in your LAN.
{2 Comments below .. you can add one }
5.30.2009at 19:45
6.12.2009at 10:47
The best information i have found exactly here. Keep going Thank you
[...] http://www.kindawannadothat.com/2009/04/easy-dns-and-dhcp-setup-on-linux/ [...]