About the hosts file

My question: Is it allowable to have an entry in my hosts file that has the hostname and ip address of my computer in it?

Example: My computer’s hostname is ASU-X99 and it’s ip address is 10.111.10.5
Can that entry be added to the hosts file on this computer without causing problems? Especially if it is below the 127.0.0.1 entry?

The reason for my question is:
I have 5 openSUSE systems, a NAS and 3 printers on my network. I am in the habit of doing updates to all the computers in my network from my computer using ssh to log into each of them, using ssh bart@<hostname>, and using zypper up. I should say that all devices except mobile phones have reserved addresses.

I have been having very inconsistent results using hostnames as often I get a name or service not known response. All seems well if the entries are in the hosts file of the various computers, but I would like to use the same file for all the computers, giving me one central point for management, rather than got to each one if/when I need to make a change.

My router (TP-Link 7602) does not have a DNS server in it.

Bart

Hi
I normally just have localhost tied to 127.0.0.x and hostname against the static ip address… I just have a localhosts text file and just append to /etc/hosts on machines.

Not completely sure I understand. Do you mean there is an entry:
127.0.0.1 localhost

and another at:
192.168.1.x <your local hostname>

?

Bart

Refer

man 5 hosts

@montana_suse_user,

I can confirm it doesn’t do any harm if a host’s own hostname and IP is listed in it’s “/etc/hosts”. I have a similar setup / approach. I don’t use only one file but being lazy I just copy the full list of hosts into the file / the YaST dialog when doing a fresh install. That’s my habit since many years and I have never had any issue that I could think of being related to it.

That is rather normal. And the sequence is of no importance.

Then, you’ll have to setup a DNS server for your LAN – assuming that, it’s a small private LAN, a «Raspberry Pi» or, something similar, will be more than sufficient for your needs.

  • Trying to maintain consistent ‘/etc/hosts’ files across all hosts in a network is and, always was, a Sisyphus
    task and, doomed to error …

Does that work: How to Change the DNS servers on the wireless router and DSL modem router (New UI) | TP-Link Deutschland ?

The local network here consists of several hosts and all of the openSUSE machines have this single identical configuration file:

**erlangen:~ #** cat /etc/systemd/network/20-wired.network     
[Match] 
Name=e* 

[Network] 
DHCP=yes 
Domains=fritz.box 
**erlangen:~ #**

Each of them has a unique static hostname:

**erlangen:~ #** hostnamectl  
 Static hostname: erlangen 
       Icon name: computer-desktop 
         Chassis: desktop  
        Location: home 
      Machine ID: 94f3af277bac4a8eb57da425c9677379 
         Boot ID: 799357efba7f4566bd72611875e7810e 
Operating System: openSUSE Tumbleweed                 
     CPE OS Name: cpe:/o:opensuse:tumbleweed:20220423 
          Kernel: Linux 5.17.4-1-default 
    Architecture: x86-64 
 Hardware Vendor: Micro-Star International Co., Ltd. 
  Hardware Model: MS-7C56 
**erlangen:~ #**

The above is all I need to check.

How does this relate to the OP’s questions in any way?

*@dcurtisfra

Sisyphus ?

rotfl!

You can tinker with /etc/hosts. It’s worse than Sisyphus! There are more elegant solutions to your problem. I go with a pristine /etc/hosts (zero output from “rpm -V netcfg”). Static host names are defined in /etc/hostname of each host. That’s all.

I have 5 openSUSE systems, a NAS and 3 printers on my network. I am in the habit of doing updates to all the computers in my network from my computer using ssh to log into each of them, using ssh bart@<hostname>, and using zypper up. I should say that all devices except mobile phones have reserved addresses.

I have been having very inconsistent results using hostnames as often I get a name or service not known response. All seems well if the entries are in the hosts file of the various computers, but I would like to use the same file for all the computers, giving me one central point for management, rather than got to each one if/when I need to make a change.

All hosts know their names and get their addresses from the router via DHCP. That works best with all routers in the LANs I have ever seen. No inconsistencies observed since switching and sticking to hostnames only. No changes necessary. All Linux hosts use systemd-networkd / systemd-resolved with a single identical configuration file.

The minimal configuration works flawlessly since three years, even with many hosts sharing the same MAC address (native tumbleweed, leap, fedora, ubuntu, arch, manjaro and others running consecutively on the same hardware). To my knowledge there is a single caveat: Make sure the router never tries to assign the same network address to a given MAC address (uncheck “always assign the same network address”).

BTW:

**erlangen:~ #** systemd-analyze critical-chain network.target                              
network.target @447ms 
└─**systemd-resolved.service @394ms +53ms**
  └─**systemd-networkd.service @297ms +92ms**
    └─**systemd-udevd.service @240ms +56ms**
      └─**systemd-tmpfiles-setup-dev.service @228ms +7ms**
        └─**kmod-static-nodes.service @222ms +3ms**
          └─systemd-journald.socket 
            └─system.slice 
              └─-.slice 
**erlangen:~ #**

Routers learn the hostnames at the time of the DHCP lease. However, local hostname resolution is down to the router. Not all domestic routers are capable of this, and it has NOTHING to do with the network management framework in use.

Obviously my TP-Link router is one of those. So, instead of messing with the host files on everything, can I set up a dns server on my server (openSUSE 15.3) using just the wizard? I read that whole document several times and it seems like it should work, however, as I get further into the document I find so many things of which I have no understanding. I’m a little afraid to just try it as I certainly don’t want to effect anything else on the internet side.

Bart

Honestly, for a small home network I would consider just using Avahi hostname resolution. Just make sure hosts with active firewalls allow mdns. It uses the configured hostname with .local top level domain by default eg laptop2.local

https://wiki.archlinux.org/title/Avahi

It’s what I use in my home network and no explicit configuration needed.

Are you sure? From the top post:

My router (TP-Link 7602) does not have a DNS server in it.

Are you meaning the tp link ER7206?

Greek mythology –

  • Punishment by having to roll a heavy boulder up a hill –
    Catch 22 – when near the top of the hill, the boulder rolls back down to the bottom of the hill.
  • Repeat – forever …

Yes. That’s what I have. It does not have DNS capabilities.

Bart

Yup! Was new to me. I looked it up and that’s what I found. It’s absolutely amazing what one can learn on this forum!

Bart

Hi
But you must be able to configure external DNS? I use openDNS, you could always look at running pihole?

I found that those processes are running on my machines. And, before I changed the router and switch, with no changes to my computers, it used to work just fine. I could reach all my devices by hostname. So, I’m going to start a new thread with full confidence that we can get my system working correctly.

Bart