23

Is it possible to assign a readable string alias to an IP address like 192.168.1.1? Maybe something like this:

192.168.1.1 -> router.home

or

192.168.1.22 -> printer.home

There is no need for router.home to be reachable from the outside web, but only in the LAN. In fact, it shouldn't be reachable from outside web.

I guess the goal is to have a local DNS server, which responds to router.home address. Any idea how to create such an alias?

EDIT: Yamakaja's answer works great, but it requires changing hosts file on every computer in LAN. Can local DNS lookup be done at the home router instead? That would skip a lot of manual work.

  • 2
    Note that some routers do this themselves, for example, if you use Asus routers, and you go to router.asus.com it will open the router's config page. Other routers have similar "tricks" to do similar to this as well. – acejavelin Jun 25 '16 at 14:07
  • Nope, I do not use asus router. The question is actually a bit more general... Not only I would like to access router without the IP, but other devices attached to network too. I will add an edit. – sanjihan Jun 25 '16 at 14:13
  • 2
    My point was some routers have this capability built in since they often act as a DNS caching server, since you didn't state what router you are using I left it open to "other routers have similar tricks to do this as well" – acejavelin Jun 25 '16 at 14:16
  • 1
    yes yes, I got that and thank you! router was just an example. imagine running printer or raspberry PI or internet controlled ventilation system on the LAN too. – sanjihan Jun 25 '16 at 14:19
  • @sanjihan I think you will need to disclose the make and model of your router or else tell what you are using for DNS for someone to give you instructions further on the configurations you may be able to complete for this task. So to recap, 1.) make and model of your router device or 2.) what are you using exactly for DNS (e.g. Windows DNS, built-in router functionality, etc.) – Pimp Juice IT Jun 25 '16 at 14:30
18

In addition to Yamakaja's answer, this is how you setup a local DNS server.

First, you need a computer you want to run the DNS server on. This can be one of your normal computers (if they run Linux and are on most of the time) or for example a Raspberry Pi. The advantages of such a device are that it's cheap, does not need much power and it's small.

Setting up the DNS server

I decided to set up the DNS server on a Raspberry Pi using dnsmasq, which is a small DNS server tool, ideal for use in small networks. You could also use bind, the de facto standard DNS tool, but this is probably a little too mighty for a small home network.

Install dnsmasq using the package manager, on Debian-based systems (e. g. Raspbian), the command would be

sudo apt-get install dnsmasq

I now assume you already have set up a static IP address allocation (i.e. the IP addresses you mention in your question don't change). If you haven't, dnsmasq can be also used as a DHCP server, but I haven't done that yet.

dnsmasq fetches the host names from the /etc/hosts. Edit this file as follows:

# IP address    Host name
192.168.1.1     router
192.168.1.22    printer

The host name router is now assigned to 192.168.1.1, printer to 192.168.1.22.

Now, you've set up your own DNS server, but the computers in your network don't use it yet. To make them use this server, you have to do one step of preparation:

Find the IP address of your dnsmasq device using ip address (let's assume it's 192.168.1.42). Open the /etc/dnsmasq.conf and append the following lines:

listen-address=127.0.0.1
listen-address=192.168.1.42

This tells dnsmasq it should listen to requests to it when they are addressed either to 127.0.0.1 (i.e. when itself wants to use its DNS server) or 192.168.1.42 (i.e. when other computers want to use its DNS server).

Using the DNS server

You have to tell each computer in your network it should (also) use 192.168.1.42 as DNS server. The way you do this depends on your operating system. You can look this up for your specified operation system on the internet easily (just search "Change DNS server on <OS>", or something like that).

For Windows 7, you could follow this tutorial: https://www.opennicproject.org/configure-your-dns/how-to-change-dns-servers-in-windows-7/.

On my system (Arch Linux), I had to append the following line to /etc/resolvconf.conf

name_servers=192.168.1.42

Note the file you have to use depends to your network manager configuration. Add the DNS server IP on each computer you want to use your DNS.

You'll probably have to restart the devices if it does not work immediately.

That's it, you're done. You can now access all devices you've entered in /etc/hosts of the dnsmasq server simply using the host name you've given it.

(Optional) Checking functionality

If you want to check whether the DNS resolve works correctly, install dnsutils (Linux) on the system that should use your server. Then execute

$ dig router

This should return something like this

; <<>> DiG 9.10.4-P1 <<>> router
;; global options: +cmd
;; Got answer:
...

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;router.                        IN      A

;; ANSWER SECTION:
router.                 0       IN      A       192.168.1.1

;; Query time: 14 msec
;; SERVER: 192.168.1.42#53(192.168.1.42)
;; WHEN: So Jun 26 10:43:18 CEST 2016
;; MSG SIZE  rcvd: 50

It shows you the host name you wanted to resolve, the IP address it got resolved to and the DNS server used. As you see, everything is fine.

(Optional) Specifying a TLD

If you want to access the devices not just with router or printer but with router.home and printer.home, add the following lines to your /etc/dnsmasq.conf:

expand-hosts # Tells dnsmasq to add a TLD to each host name
domain=home # The TLD

You may need to restart again.

Sources / further reading

About dnsmasq:

About bind (if you're interested in it):

10

Yes it is, and there are two (or more?) options:


Editing your hosts file (the lazy way)

Depending on your operating system you will have to add an entry to your "hosts" file. You can find it at /etc/hosts on most Unixoids and in C:\Windows\system32\drivers\etc\hosts on Windows.

To add your entry go to the bottom of the file and add a row in this format:

<IP>       <the hostname to assign>

eg.

192.168.1.1      router

(Note, the space between the ip and the hostname doesn't matter. But it looks better if matches up with the other entries. You can use tabs or spaces)

Then you can access your router in a browser by just accessing

http://router/

or

router/

Local DNS Server

Please see TuringTux's answer for more information

  • Thanks man! This works great for a single computer. Is it possible to extend this to all computers in the LAN without manually changing the hosts file in every single computer? – sanjihan Jun 25 '16 at 13:56
  • @sanjihan Its not that easy, for example you could buy your own domain name for less than 1$ on namecheap and use that to point to your stuff. For example you could setup router.<yourdomain>.<tld> to point to 192.168.1.1 But that will make your names longer. Also please mark my answer as accepted so other users know that this question has been answered. – Yamakaja Jun 25 '16 at 15:12
  • Can you just use the PC name if they are part of the same Workgroup? – jiggunjer Jun 26 '16 at 15:39
  • @jiggunjer i actually don't know. I'm not that familiar with Windows – Yamakaja Jun 26 '16 at 19:37
2

I want to update the great answer above:

You may want to look into your router and check if it has manual DNS entry support.

If so, you can just add your local 192.168.1.22 address on it as printer.home. Otherwise you're limited with local hosts file editing or your own DNS server setup I afraid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.