Adding hostname and its IP into its own /etc/hosts file
Adding hostname and its ip into its own /etc/hosts file
Say I created hostname: >hostnamectl set-hostname server1.test.com Let say it IP address is 192.168.200.100 Is there a valid reason to include into its own /etc/hosts file like so: 192.168.200.100 server1.test.com What use case by server1.test.com would need server1.test.com's IP address to be in server1.test.com's /etc/hosts? Addendum: Pinging itself does not count as a good use case. |
Yes, there are reasons.
There are utilities that may look up an IP number before a network is even initialized, and frequently what they will do is use the hostname under the assumption that it also has been assigned an IP number. There is an assumption being made that the "hostname" must be the same as the "network name". This IS a convention, but it doesn't have to be true. My host has many addresses- 192.168.0.8, 192.168.1.3 (currently), 192.168.122.1 (for communicating with virtual machines) Yet none of these are given my hostname other than 192.168.0.8. 127.0.0.1 is given "localhost"... as is ::1 (IPv6 local host). No names HAVE to be put in /etc/host file. I do it because I copy the /etc/host to other systems so that they can contact each other by a commonly understood name. But that "commonly understood name" does NOT have to be the same as the "hostname". This COULD be done by a name server - but then the assumption is that the name server is always available... (not necessarily true). So I just copy the /etc/hosts file around. This works only because I have very few systems to do it with (3 physical, and sometimes 3 active virtual systems). |
Hosts files for lan computers tend to have all the computers with the same hosts file. Makes it easier to maintain.
You'd put the local name in the local hosts file maybe for some lookup tasks that refer back to the host. Could be quite a few. |
Here's a example of a "real" /etc/hosts file:
Code:
cat /etc/hosts Officejet is an Ethernet connected HP printer that serves everything on the LAN (note that it's fixed-IP too, you don't want a printer running DHCP if you don't have to). The "public servers" are frequently-used addresses -- why? because you don't go though a DNS lookup to get there quickly (/etc/hosts is the first place looked at for and address). Every machine on the LAN has and identical /etc/hosts file (yeah, the local machine address is there too -- doesn't matter and can be handy). Works just fine (for... well, decades). Hope this helps some. |
@tronayne:
Thank you. Quote:
Please provide some examples. Thanks. |
We have /etc/hosts mapping of IP and its hostname.
But this hostname do not have to be the same as that created by hostnamectl. Thus in this case you can have 2 different hostnames, if you have host's IP in the host's /etc/hosts points mapped to some arbitary name other than those created via hostnamectl. When is hostname (created by hostnamectl) ever used and by whom? Thanks. |
Quote:
There may also be a networking use, but I don't know what it is. |
Quote:
Code:
cat /etc/resolv.conf So, the named servers are those and the no named are those addresses in /etc/hosts. The way things work is that, when you enter a name of an external device the first place that's looked at is /etc/hosts then, if your network daemon is active, the first nameserver in /etc/resolv.conf, if that's not available, the next nameserver is looked at (after a long delay from the first). You don't want to have a bunch of nameservers -- most DNS servers have two addresses and if one fails the other is tried; you sit for a long time waiting for a long list of nameservers to be examined if one or more are not available, so use reliable nameservers in your /etc/resolv.conf file. I have that list pretty much for the laptop being used somewhere or other and I know the DNS server addresses of places I go with it. You would, most likely, need only two nameserver entries in your file (and you do not what LAN servers in /etc/resolv.conf. Hope this helps some. |
You got me interested.
Quote:
Quote:
|
L3Comm = 4.2.2.2
is reliable. |
The l3 resolvers are at 4.2.2.1-6
4.2.2.2 is used mostly because it is easy to type, but they probably appreciate when people spread out on the resolvers and aren't just using one of the 6 over and over. |
@szboardstretcher:
Quote:
Is it DNS? "l3" is short name for what? What is "-6" in "4.2.2.1-6" for? Thanks. |
The company "Level3 Communications" has DNS name resolvers that are located in the ip address range that starts at 4.2.2.1 and goes to 4.2.2.6.
Writing 4.2.2.1-6 is practical networking shorthand for saying 4.2.2.1 to 4.2.2.6 |
Quote:
Keep in mind that it's 22,236 miles up, 22K down, do something, 22K back up and 22K down to me. Quote:
Thanks for the interest. Hope this helps some. |
If I had sat connection, I'd make the 50 or so common sites in hosts file and be sure edit that into a good hosts blocking file. You don't need all those ad's tearing up your bandwidth.
http://winhelp2002.mvps.org/hosts.htm You can speed up lookups as most systems go to hosts file first to resolve an IP. Local lookup is much faster than web searches. You can speed up good sites and block bad sites or trivial ad sites. |
All times are GMT -5. The time now is 01:10 PM. |