Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Red Hat This forum is for the discussion of Red Hat Linux.


  Search this Thread
Old 07-17-2012, 10:06 PM   #1
Registered: Apr 2011
Distribution: Ubuntu
Posts: 51

Rep: Reputation: 2
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"
Old 07-18-2012, 12:21 AM   #2
Registered: Jan 2012
Location: South Africa
Posts: 501

Rep: Reputation: 189Reputation: 189
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!


centos, firewall, hostname, ip address, ssh

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't contact machine by its hostname laredotornado Linux - Newbie 1 05-03-2011 08:58 AM
Can't Ping Linux CentOS 5.3 Machine to XP SP2 Windows Machine Moderns Linux - Networking 20 11-04-2009 12:33 AM
CentOS machine + XP machine = XP invisible for Linux achtung_linux Linux - Networking 10 08-18-2006 03:16 AM
How do i use a hostname given by No-IP as my machine name? z-vet Linux - Networking 3 10-22-2004 08:06 PM
How to get another machine's hostname? afpe Linux - Networking 4 01-27-2003 07:59 PM > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 04:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration