-   Red Hat (
-   -   Centos 6 - machine does not know it's own hostname (

yanom 07-17-2012 11:06 PM

Centos 6 - machine does not know it's own hostname
So I've got this Centos 6 machine running. it's got openssh-server and the firewall is open on port 22. It's hostname is mycentos. I've found that most linux systems seem to know their own hostname, and are contactable by hostname:


root@foobar:~# ssh foobar
and be able to work like that. my machine doesn't know it's own hostname!

yanom@mycentos:~ $ ssh mycentos
ssh: Could not resolve hostname mycentos: Name or service not known
yanom@mycentos:~ $

I can connect to it by ip address, though:

yanom@mycentos:~ $ ssh
and that works. Going to another computer on the same network, I can connect by the IP address, but not by the "mycentos" hostname.

This machine also has an apache web server running, and I've confirmed that the web server is reachable by "" by not by "http://mycentos"

cliffordw 07-18-2012 01:21 AM

Hi there,

Connecting locally and remotely work a little differently.

To connect locally your machine can look up its own hostname in the /etc/hosts file. On most Linux systems, if you use the system setup tools to change the hostname (like yast on opensuse, or setup on centos), it also changes the /etc/hosts entry for you. If you changed the hostname manually, though (for example by editing /etc/sysconfig/network on centos), the /etc/hosts file would not be updated as well. You can fix this by editing the /etc/hosts file and adding an appropriate entry, like this:
Code:  localhost.localdomain localhost mycentos
Once you have done this, "ssh mycentos" should work from the local machine.

For connentions from another computer on the same network, the other computer also needs a way to translate the name (mycentos) to its IP address ( If you are running a Domain Name Server (DNS), the best thing to do is to add an entry for this host to the DNS. If not, you will have to add this entry to the hosts file of the other computer.

Good luck!

All times are GMT -5. The time now is 05:15 AM.