Local network resolution

Q I have a desktop running Fedora 9 and a laptop running Ubuntu 8.04, as well as my son's and wife's machines running XP. These are all connected via a D-Link router. I connect my desktop and laptop via SSH but use the local IP number to do this. The issue for me is that all machines use DHCP to get their IP addresses so they change regularly. What I'd like to do is use computer names for each machine and then resolve these to the actual IP addresses. To do this, I believe I need to setup a DNS server locally. I really don't want to use static IP addresses.

A Most routers also act as DNS servers, so yours is probably already doing this. Some also have the facility to specify the IP address and hostname given to particular computers. The normal approach with DHCP servers is to pick an unused address for the pool of available addresses each time a request is received, but it's sometimes possible to specify which address a particular computer should receive. The computer is identified by the MAC (Media Access Control) address of the computer's network card. If your router allows this, you can specify the MAC address of each computer along with the preferred IP address and hostname.

When you've done this, access by hostname should just work. The MAC address is six pairs of hexadecimal digits (such as 01:23:45:67:89:AB) and can be found in the network properties, or by running ifconfig in a terminal. On Windows, run ipconfig in a command prompt. If your router can't handle this, you can use dnsmasq (www.thekelleys.org.uk/dnsmasq): a useful, lightweight DNS and DHCP server that would suit your needs (I use it on my home network). This will take care of everything for you, but you'll need to set up the machine running dnsmasq to use a static IP address. Disable the DHCP server in your router and put the following in /etc/dnsmasq.d/local:

log-facility=/var/log/dnsmasq.log
domain=example.com
dhcp-range=192.168.1.128,192.168.1.192
dhcp-option=option:router,192.168.1.1
dhcp-host=00:1A:92:81:CB:FE,192.168.1.3,hostname

The first line sets up logging, which you may need if things don't work as expected first time round. The next line contains the domain of your local network and the third line contains the range of addresses to be allocated by DHCP, followed by a line giving the router address that all hosts will need to know to be able to contact the internet. The final line is repeated once for each computer, and contains the MAC address of that computer, the IP address to be allocated to it and the hostname to be given it. The IP address is outside of the dhcp-range value given previously to prevent it being given to another computer. Make sure /etc/resolv.conf on this computer contains the address of at least one DNS server.

If your ISP changes DNS addresses from time to time, it may be best to put the router's address in here and let the router and ISP sort the correct addresses out over DHCP. If you do not want to use your ISP's DNS servers, put the ones you want in resolv.conf. Start dnsmasq, or restart it if it was already running when you edited the configuration file. Then reconnect each of your other computers and they should be given the hostnames and IP addresses you want. More importantly, you should be able to contact each of them using the hostnames, so you don't have to remember the numbers anymore.

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar