How to reach a host in the same network by hostname?

Solution 1:

Your /etc/nsswitch.conf should already have this for mDNS (avahi):

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4

Just install avahi-daemon on the machines you want talking to eachother, and you should be set to use HOSTNAME.local like this:

ssh yourmachine.local

Solution 2:

An alternative is to add an entry in your /etc/hosts file:

gksudo gedit /etc/hosts

An entry takes the form 123.123.123.123 host.domain or just 123.123.123.123 host.

If you do that, you can now for example ssh host and it will connect to 123.123.123.123

Solution 3:

I found another solution. Using the file, /etc/dhccp3/dhcient.conf There is a line starting like this, send host-name This could be modified to send host-name 'server1'

This solution look nice, but i don't know if the every machine which use the same dns will see my "server1" hostname.

Another bad side to this solution, i need to specify the hostname here and in the /etc/hosts

I just know that this file (/etc/dhcp3/dhclient.conf) is not a script, so i can't use a environnement variable to fill this line correctly.

Solution 4:

You can let dynamic DHCP add the entry in DNS, instead of yourself.