Aliases in /etc/hosts

  • Thread starter Deleted member 9563
  • Start date
D

Deleted member 9563

Guest
I have a hosts file with a long list of aliases that I use on my local network. It works in Linux so I thought I could do the same in FreeBSD, and according to the way I read the manual it should be so. Apparently I am wrong, because I cannot ping any alias. The networking is functional otherwise. Here is the top of my hosts file for GIN:

Code:
::1                          localhost localhost.lan.cgs
127.0.0.1               localhost localhost.lan.cgs
192.168.1.119           GIN.lan.cgs GIN
192.168.1.119           GIN.lan.cgs.
192.168.1.102           CDX  CDX
192.168.1.103           TOP  TOP
192.168.1.122           CDY  CDY

I suspected it had something to do with FreeBSD's craving for having a FQDN but filling in the bogus "lan.cgs" does not help either.
 
Code:
-rw-r--r--  1 root  wheel  213 Oct 29 00:45 hosts
I thought of that, but if it was wrong I don't suppose that networking would work properly.
 
Put the entries with the same IP address on the same line.
 
OJ said:
Code:
192.168.1.119           GIN.lan.cgs GIN
192.168.1.119           GIN.lan.cgs.

Those should all be on the same line, as noted by SirDice.

Code:
192.168.1.102           CDX  CDX
192.168.1.103           TOP  TOP
192.168.1.122           CDY  CDY

What are those doubled names supposed to do?
 
wblock said:
Those should all be on the same line, as noted by SirDice.

OK, but that is the way the OS installer put it. I'll put them on the same line.

What are those doubled names supposed to do?

I simply did it the way it works in Linux, which seemed sensible because the FreeBSD handbook says:

[Internet address] [official hostname] [alias1] [alias2] ...
So I have then: the address, the hostname, and the alias. In my case because I use simple three letter host names, it is convenient to use the same as alias.

What should I do?

Here is my new test for /etc/hosts and I also added a "real world" address to see what that would do. However I can still not ping anything in the list.

Code:
::1                     localhost localhost.lan.cgs
127.0.0.1               localhost localhost.lan.cgs
192.168.1.119           GIN.lan.cgs GIN

 192.168.1.102 CDX
 192.168.1.103 TOP
 192.168.1.122 CDY
 69.90.46.148  holyroodgen.net hg
 
OJ said:
I simply did it the way it works in Linux, which seemed sensible because the FreeBSD handbook says:
[Internet address] [official hostname] [alias1] [alias2] ...

So I have then: the address, the hostname, and the alias. In my case because I use simple three letter host names, it is convenient to use the same as alias.

Yes, but the alias is a different name for the same host. For example:
Code:
192.168.1.1    superman clarkkent reporternerd

What should I do?

Here is my new test for /etc/hosts and I also added a "real world" address to see what that would do. However I can still not ping anything in the list.

ping can be broken in many ways. /etc/hosts only affects DNS. Does ping resolve the hostname in the first line?
Code:
% ping freebsd.org
PING freebsd.org (69.147.83.40): 56 data bytes

Then your hosts settings are working and the ping problem is something else. Often that's a firewall.
 
wblock said:
Yes, but the alias is a different name for the same host. For example:
Code:
192.168.1.1    superman clarkkent reporternerd

OK, so I guess all that is needed to resolve a name using /etc/hosts is to have a number and a name.

ping can be broken in many ways. /etc/hosts only affects DNS. Does ping resolve the hostname in the first line?
Code:
% ping freebsd.org
PING freebsd.org (69.147.83.40): 56 data bytes

Then your hosts settings are working and the ping problem is something else. Often that's a firewall.

Looking at my testing /etc/hosts file, I can ping holyroodgen.net, but I can't ping "hg". I can ping any name like google.com, and also any number. I just can't ping any of my (intended) aliases.

If then my hosts settings are correct how would I go about diagnosing the problem? These machines are all inside the same router/firewall, although on different switches. The aliases I use work just fine using the same format for /etc/hosts file when deployed on several Linux computers. It is just the two FreeBSD systems which are not working. Is there a firewall in FreeBSD which I should be looking at?
 
Here's what happens:

Code:
[ole@GIN]/home/ole$ ping CDX
ping: cannot resolve CDX: Unknown host
[ole@GIN]/home/ole$ ping hg
ping: cannot resolve hg: Unknown host

Edit: Oops, I forgot that CDX just got replaced. Anyway, the others give the same output. Just to show that there is indeed a connection; using numbers I get this:
Code:
[ole@GIN]/home/ole$ ping 192.168.1.122
PING 192.168.1.122 (192.168.1.122): 56 data bytes
64 bytes from 192.168.1.122: icmp_seq=0 ttl=64 time=0.777 ms

[ole@GIN]/home/ole$ ping 69.90.46.148
PING 69.90.46.148 (69.90.46.148): 56 data bytes
64 bytes from 69.90.46.148: icmp_seq=0 ttl=50 time=34.109 ms
 
Here is what /etc/hosts looks like now:

Code:
::1                     localhost localhost.lan.cgs
127.0.0.1               localhost localhost.lan.cgs
192.168.1.119           GIN.lan.cgs GIN

192.168.1.101 SCO
192.168.1.103 TOP
192.168.1.122 CDY
69.90.46.148  holyroodgen.net hg

It works!!! I'm surprised the original one didn't work, but now that I have something that works, I can make adjustments from there. Alls good now and I can paste in the rest of the list. Thanks wblock! :)
 
Back
Top