-   Linux - Networking (
-   -   Hostname -i not showing up correctly (

newbie14 12-26-2012 06:47 PM

Hostname -i not showing up correctly
We have modified our /etc/hosts to something like this
Code:  localhost localhost.localadmin gyapp
and when we run hostname -i we get hostname: Unknown host. Have restarted the network service yet the same.

NevemTeve 12-27-2012 04:42 AM

'hostname -i' doesn't seem to return
What do you really want to achieve with this?

newbie14 12-27-2012 10:04 AM

Dear Nevem,
What I want to do is to monitor a java application remotely. The java application running via a wrapper. So I followed this link where it talks possible the hostname issue. So this is what I want to do and stuck with the hostname thing.

Shadow_7 12-27-2012 10:26 AM




$ hostname --all-ip-addresses

return the same information as

$ hostname -i


Lennie 12-27-2012 10:53 AM

Which distro are you running? The hostname is set in 2 files, /etc/hosts and one more, which can be different on different distros, but often /etc/hostname.

To give you an example, this is what I have in Salix:

/etc/hosts                localhost
192.168.1.xx                salix.mydomain salix

If you don't have static ip you can use instead. (It is not recommended to put your hostname on


newbie14 12-27-2012 11:16 AM

Dear Lennie,
Mine is centos 6.3 and my current /etc/hosts shows as below
Quote: localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

Lennie 12-27-2012 11:43 AM

That looks ok, but you also need to add a line with your hostname.
Code: yourhostname
In addition to that you need another file for your hostname. Do you have /etc/hostname? I don't have CentOS (or something based on it) so I can't check which file it uses.

Edit: Here I found out the file you also need to change is /etc/sysconfig/network.

NevemTeve 12-27-2012 01:19 PM

So you don't know your own IP-addr?
Try 'ifconfig' or 'route -n'.

newbie14 12-27-2012 06:44 PM

Dear Lennie,
You mean to say just add a new line and put this yourhostname ? I have checked there is no /etc/hostname.

newbie14 12-27-2012 06:45 PM

Dear Nevem,
I know my ip address that is not a problem at all. The issue is the hostname. What will this hostname be applied to? So any one can just put the host name instead of the ip will be able to connect to the machine?

Shadow_7 12-27-2012 10:09 PM

That's kind of how microsofts netbeau(sp?) works. Any computers with the same workgroup name can mount each others shares and swap files, without the other person even knowing it.

/etc/hostname is what gets modified on some systems by an interface named hostname.

$ man hostname

If it differs for your distro, the man page probably hints as to what it is called on your system under FILES towards the bottom of the man page. Man as in manual. The /etc/hosts file is more of a localized DNS lookup table. But not everything uses it, so it depends on "what" you are trying to do.

Lennie 12-28-2012 02:50 AM

Did you see the edit in my previous post? The page I linked to shows some example. You should use /etc/sysconfig/network instead of /etc/hostname. You can give whatever name you want to your system. The only important thing is that it is the same in /etc/hosts (the last line, which you need to add) and in /etc/sysconfig/network.

newbie14 12-28-2012 06:37 AM

Dear Shadow,
My problem is I need to link remotely to the machine via the visual jvm tool to monitor the java application. Do you think the hostname could be a problem?

newbie14 12-28-2012 06:39 AM

Dear Lennie,
Sorry I missed that will try the link and it looks complete hopefully that will be helpful to solve my other problem of the visual jvm. Thank you.

Shadow_7 12-28-2012 06:09 PM

I'm not familiar with the jvm tool you're referencing. But is the routing okay? Can you ping one and it can ping you. Which are icmp packets.

# route -n
# netstat -r

If you can't do that much then there probably is a firewall in the way. Or other issues if you get stuff like host unreachable. You really can't work on getting the jvm working if the basic networks are not connected. Honestly I don't see why hostname would be the problem. Unless you have multiple instance running in virtualization and need to isolate only one of them. From the linked to content you seem to referencing the tool by IP:PORT.

On rare occassion when my ISP DNS's (and/or others) suck, I have had to put the IP and hostname of the external site in my local hosts file. The IP alone is not sufficient if there are multiple sites hosted at that same IP address. Which is common in webhosting, without paying extra. Although this approach is more of a hack than the way you "should" do things. (In a perfect world my ISPs dns servers wouldn't suck).

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