TransWikia.com

Alias for IPs in the home LAN network

Super User Asked by sanjihan on December 9, 2021

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.

3 Answers

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.

Answered by Valentin on December 9, 2021

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.

(Untested, optional) How to avoid changing the DNS config on all computers

I'm not sure about the factual accuracy of the paragraphs below, please feel free to correct them if you spot mistakes

All computers in your home network should per default use a DNS server provided by your router. To avoid changing the DNS config on all your computers, you could instead tell your router to use your DNS server. After this, everyone in your network should be able to resolve the host names you specified in dnsmasq's config.

However, you'll likely be unable to resolve any other domains pointing to the outside network because your DNS server doesn't know how to handle them. To fix this, you could probably configure your DNS server as a DNS cache, caching the DNS entries from a public DNS server.

If your computer then needs to resolve a domain, the request would take the following path (in the end, following either option a) or b)):

                                                               /etc/hosts
                                                                   ^
                                                                   |
                                                              b) lookup
                                                                   |
|-------------|                |-----------|                |---------------|
|Your Computer|--DNS request-->|Your Router|--DNS request-->|Your DNS server|
|-------------|                |-----------|                |---------------|
                                                                   |
                                                            a) DNS request
                                                                   |
                                                                   v
                                                          |-----------------|
                                                          |Public DNS server|
                                                          |-----------------|

Sources / further reading

About dnsmasq:

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

How to change your router's DNS:

How to configure a DNS cache:

Answered by TuringTux on December 9, 2021

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:Windowssystem32driversetchosts 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

Answered by Yamakaja on December 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP