Use Your Router to Centralize Your Network Device Management

Posted by JD 07/18/2011 at 04:00

Bare with me here. This is a great technique. I think you’ll thank me later after doing what this article suggests.

Homes and businesses today have lots of network devices. Using DHCP is the easiest way to get those on the network, but if you ever want those different devices to talk to each other, perhaps to transfer a file or to have a central backup server, then now your are running a network. Running a network means you probably want to know which devices are on your network or maybe that is just me. Perhaps you want each device to locate each other device too? Static IPs are possible under DHCP, sometimes called DHCP Reservations or Static Leases.

Make it easy for everyone in the house by using your router to force static IPs for the devices when they are at home, but still can connect to DHCP networks easily when roaming. This is really good for portable WiFi devices like laptops, smartphones, and for home entertainment devices that easily support DHCP.

A Quick Review

The /etc/hosts file is the telephone book for a network. Here’s a small example:


192.168.0.1 router
192.168.0.2 server
192.168.0.3 xbmc
192.168.0.4 samsung-tv
192.168.0.5 nas
192.168.0.6 wdtv
192.168.0.7 tivo
192.168.0.8 hdhr
192.168.0.9 bluray
192.168.0.10 xbox
192.168.0.15 game-rig
192.168.0.20 laptop
192.168.0.26 iphone
192.168.0.27 android
192.168.0.28 tablet

This gives you an idea of the types of devices are connected to many home networks. I bet most home networks are using DHCP for each of these. Today, we will accomplish 2 things:

  1. Setup each DHCP network device with a static IP address provided by the router.
  2. Setup the router to provide hostname resolution (i.e. DNS) for these devices on our internal network. This means from any PC on the network, you’ll be able to find your smartphone or media player on the network.

Some Reasons

Better /etc/hosts File Management

Historically, the easiest way to manage letting all systems find each other is by maintaining a hosts file that you copy to each host. If you’re reading this still, you are probably already doing something in your /etc/hosts on Linux or SYSTEMROOT/Windows/system32/drivers/etc/hosts file on Windows. That can be a big hassle if you have more than a few devices. Centralizing that to your router means never needing to copy the hosts file again and it will never be out of date on older devices when new devices are added to the network – provided you update the router configuration.

Static IPs for DHCP Devices

Not all devices support static IP addresses, but they almost universally support DHCP. For example, the HD-Homerun, HDHR3, device is DHCP only. For control freaks like me, not having a static IP for that device is troublesome. It means firewall rules aren’t as well known – a Windows7 PC needs to open firewall ports to use the HDHR3 device. Smartphones with WiFi are another example of devices that easily work with DHCP, but probably aren’t as easy to configure with a static IP for home-only use.

Easier IP Data Entry

Other times the data entry for devices is a hassle. Like on media playback devices using a remote control to set an IP address. Think about your XBox or TiVo or WD TV HD Live or other, similar, device. Sure, it is a one time configuration, but eventually you’ll need to reenter that IP information. Why bother when you can just have your router handle that for you? You’ll probably be entering the information in a web browser. That means copy/paste on a real keyboard are available.

Running a Home Server

If you run a server or NAS, Network Attached Storage, device at home, letting all the other devices easily find it by name is very handy. Suppose you have a cheap ($50) NAS for backups connected to your home network. Letting the other devices connect by calling it “NAS” or “Backup” is much nicer than having to type in 192.168.0.5 all the time, right?

Centralized IP Management

Lastly, the main reason for this is to have a central database and provide the IP data for all connected devices out to all the others. With many routers, you can export or backup the configuration data. Definitely do this, so if you need to reload the firmware, you can quickly put all these settings back as they were.

Router Setup

Every router is a little different, so you’ll need to find how your router handles this. We run DD-WRT, a FLOSS firmware replacement for many routers with lots of extra features, but I suspect 90% of the home routers sold now have the capabilities we’ve been discussing.

What Data You Need

To set this up, you’ll need to find the MAC address for each device. This is a unique identifier for the network adapter and is guaranteed to be unique anywhere in the world today. You’ll be building a table that contains the MAC, hostname and IP address for each device. This data will be entered into your router’s web interface. I’ve made up the MAC addresses, which are hexadecimal below. Here’s an example.


MAC IP Hostname

F0:4D:A2:44:29:C5 192.168.0.2 server
0d:22:43:77:22:58 192.168.0.3 xbmc
0c:18:dd:03:0b:6f 192.168.0.4 samsung-tv
CD:46:19:A9:DC:D9 192.168.0.5 nas
.
.
.

Some Important Rules:

  • Uppercase or lowercase letters do not matter.
  • No MAC address can be made up, they must be really from the device. Most non-computer devices will have them labeled pretty clearly on the outside, near the network port.
  • IP addresses need to be unique too.
  • IP addresses need to be on the subnet that your router supports. This is often 192.168.0.1-192.168.0.254 or 192.168.1.1-192.168.1.254. You can usually pick any IP addresses in those ranges for your static IPs, but it is common to limit them to a certain range below .100.
  • You will probably want a truly dynamic address range of about 10 IPs for guest devices.
  • Hostnames need to be unique, but laptop1, laptop2, laptop3 are fine, if you like that. Some routers may support multiple hostnames for each device, so laptop2 moms_lap could be a valid entry to have 2 names.
  • You can reuse existing IPs that a machine already has, but this is not what you want to do, probably.
  • Any machines already configured with static IPs will need to be de-configured, i.e. reset back to DHCP.
  • Other normal networking rules still apply.

On Windows, the easiest way to get the needed data is with the

ipconfig /all
command. Unfortunately, most home routers need the MAC address with colon separators, so you’ll want to search and replace all the non-colon dividers in MAC addresses.

On Linux, you’ll probably want to use the

$ ifconfig
command to locate the MAC address for a single device. As usual, there are 20 other ways to get the IP/MAC addresses of devices. I used arp to get a quick list of all the devices and the MAC for each on the network here. Running the command from a central server means that almost all client machines will report in and you’ll get the existing IP hostname and MAC in an easy to use format with colons already in the MAC addresses. Copy/paste is wonderful.

Under DD-WRT (the version we’re running anyway), we locate the Administration tab, then the Services sub-tab. Scrolling down to the DHCP Server section, we find the Static Leases section. It is well marked for MAC, IP and hostname entries. Our table had 2 starter entries, so we needed to add more. Using colons instead of ‘-’ characters in the MAC is important. Sorry Windows users, you’ll need to change those characters, somehow. DD-WRT and other router firmwares will certainly change the location of these settings, so you may need to look around a little in the firmware pages for your router website.

You do not need to add all the devices on your network to the router if you do not want to. Also, you may want to either start with a new /etc/hosts file or significantly clean up the existing hosts files on each machine to prevent conflicting addresses. I just re-IPed all the media devices on this network.

After you enter this data into the router and reboot it, then you will probably need to restart the networking on each impacted device so they will automatically get the new, static IP from the router.

DNS Service from the Router

On the same tab as the static leases in DD-WRT, are the DNSMasq settings. We need to

  • enable DNSMasq radio button
  • enable Local DNS radio button
  • enter some Additional DNS Options so nslookup queries are answered.
    -b —domain=int.domain.
    address=/xbmc/192.168.0.3
    address=/wdtv/192.168.0.6
    address=/hdhr/192.168.0.8

I had to reboot the router for the DNS to work, but the static leases worked without a reboot. The DD-WRT wiki has more details if you need it.

Test It

To ensure everything is working for each device, you’ll want to verify that the

  • device is set to DHCP, not static
  • device is responding to the new IP from the router settings.
    $ ping device-name
  • DNS server returns the IP when you query it for the hostname
    $ nslookup hdhr 
  • DNS server returns the hostname when you query it for the IP address
    $ nslookup  192.168.0.8

Of course on Linux, you can use dig or host commands to verify this too. From Windows, you’ll use nslookup.