LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   Centos 6 - machine does not know it's own hostname (https://www.linuxquestions.org/questions/red-hat-31/centos-6-machine-does-not-know-its-own-hostname-4175417306/)

yanom 07-17-2012 10: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:

Code:

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

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:
Code:

yanom@mycentos:~ $ ssh 192.168.1.70
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 "http://192.168.1.70" by not by "http://mycentos"

cliffordw 07-18-2012 12: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:

127.0.0.1  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 (192.168.1.70). 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 06:42 AM.