2

I have several devices (including desktop, laptop, smartphone, etc.) connected to my wifi router. They have difference IP addresses each time according to the order they connects, so configuring /etc/hosts probably does not work.

How can I access any of them easily? Hostname seems good, but when I ping archlinux (my desktop's hostname is archlinux) on my laptop it has no knowledge who is that (ping: cannot resolve archlinux: Unknown host).

What's the simplest and platform-independent solution?

onemach
  • 23
  • 2
  • 9

4 Answers4

4

Since you use a router, you give every device you use frequently a static IP-Adress. For example your Server: 192.168.0.1 (this configuration is to do ON the router).

This would be the first step. Now it is possible to access every device with the IP-Adress (which will remain the same till ever).

From here you have 2 possibilities.

  1. decentralized -> specific name resolving with a local file where you describe which ip belongs to a hostname.
    Have a look here

  2. more work at the start, more complex, but more scalable and centralized (you have only to maintain 1 Server for the whole Network. When you use this method you will not resolve the name at your local host with a local file. You're going to ask a service "DNS" for the IP which belongs to the Name. This is way more work than with local files and i can only recommend this if you have to manage a lot of Hosts.
    But maybe your router has already this function. In this case search on youtube on "how to set up DNS with ROUTER EXAMPLE". <(i did this for my private home network at it works very well and with just a little time effort.

dunxd
  • 9,632
  • 22
  • 81
  • 118
Harrys Kavan
  • 402
  • 1
  • 5
  • 19
1

You need to either setup a local DNS server on one of the machines and configure all of them to use that DNS server, or edit the hosts file of each one to include the names of all of them.

You can edit the hosts file on Windows and Linux systems, but I am not sure about smart phones.

Khaled
  • 36,533
  • 8
  • 72
  • 99
1

Another solution would be to configure your dhcp-server to assign always the same IP to a device or more likely to the same mac address.

Simon Strasser
  • 227
  • 1
  • 8
1

You can use host file to resolve the hostname to the ip. But for using this you need to assign fix ip address to the devices on the network. For ex. for resolving archlinux to its ip, add following entry in the hosts file.

192.168.1.x archlinux

Use the ip address of archlinux in above statement in place of 192.168.1.x. Hosts file in linux is located at /etc/hosts and in windows it is located at C:\windows\system32\drivers\etc\hosts. Append the hosts file on rest of the devices accordingly.

Cloudmeteor
  • 449
  • 2
  • 7