Hostname keeps changing

Hi there,

I run the Core Dstro with a number of extra packages installed with the help of (B)LFS. I have a strange problem: my hostname 'corelinux' changes at random times to '-f' ...???

I've searched allmost every script now, but can't find any hostname-changing-commands...

Help? Please?

Who is Participating?
Ok. Just got it.

the hostname version from core-utils sucks. It's a very basic one. Juste recompiled it and checked the source.

Get the nettools :

They're the ones bundled with most distribs.

Your system will feel much better after that.
have you checked your /etc/hostname file ?
or /etc/hosts ?
edit your /etc/sysconfig/network file & put

HOSTNAME= 'corelinux'


then #hostname corelinux

reboot your system
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

I'd have a look at your dhcp client. Most probably, it's invoking a script post lease issuance.

Which dhcp client are you using ?
alingAuthor Commented:

'/etc/hosts' file: localhost corelinux

exerpt from '/etc/rc.d/'
# setup network [internet connections go in]
hostname corelinux
ifconfig lo
route add -net netmask lo

exerpt from '/etc/rc.d/'
# setup network
ifconfig eth0 netmask up
route add -net dev eth0
route add default gw

I don't use a DHCP  client nor RedHat so I also dont have a /etc/sysconf...

I do have this prompt occasionally :-)

[root@-f] ~ > hostname

Hope to help you helping me with this...

Ok. Change the following in your /etc/hosts :<tab>corelinux

And get rid of the second line.

I don't know if this will solve your problem, but it can't be bad.

Some script somewhere is trying to get your fqdn hostname using "hostname -f".
And, for a reason I don't know, it's in fact setting your hostname to "-f"...

Does it happen after you start a new X environment ?

You can try the following command to narrow the search :

find /etc/ | xargs grep -- "hostname -f"
Agree with Alf666 that should be change the name of your linux box with the IP is for local loop.
> I do have this prompt occasionally :-)
sounds like you have an alias or function which is mal-programmed
please post results of:
  set|grep hostname
  alias|grep hostname
alingAuthor Commented:

find /etc/ | xargs grep -- "hostname -f" -> no result
set|grep hostname && alias|grep hostname -> no result

I've looked at the hostname man pag ( and none of the command line options work with my hostname binary. For example: hostname -d sets the hostname to '-d' instead of returning a value...

Perhaps things will change if I mak a fresh install of Coreutils-5.0?
Yes. There is also a chance you have multiple hostname commands on your system.
If you have installed locate, try :

locate hostname

This definitely explains why your hostname changes to "-f" sometimes.
Lots of scripts (including XFree startup scripts) use the hostname command to know who they are.
alingAuthor Commented:
Result of locate hostname:


I'll compile/install today, maybe that will fix things up...

That shoud definitely.
I don't know where that hostname command comes from, but it's suspicious.
alingAuthor Commented:

Here's how I reinstalled coreutils:

coreutils-5.0 (
- tar zxvf coreutils-5.0.tar.gz
- cd coreutils-5.0
- ./configure && make && make install
- mv /usr/local/bin/* /bin -f

(I didn't use the --prefix=/ to be shure that the current binaries are overwritten)

[root@corelinux] / > hostname
[root@corelinux] / > hostname -f
[root@corelinux] / > hostname
[root@corelinux] / >

As you'll see, no results here... ;-(
if hostname -f does not return a FQDN, then there is none configured
what contains your /etc/resolv.conf
ahoffmann : Nope. This specific version of hostname does not accept any argument (I checked the sources). If you "hostname -f", then your hostname IS "-f" :-(

Hence the proposal to use a proper version.
alingAuthor Commented:

EE has proven worthy again!

I did had some probs compiling net-tools...

Quote from google search about compiling net-tools on kernel 2.6.x:

Net-tools' make process aborts with a missing declaration about the variable
"x25_address". That is because in the header file <linux/x25.h> there used to
be a typedef for this variable. Nowlonger it does not, being replaced by a
structure of the same name. This problem is easily worked around by acting as
follows: the file x25_sr.c in the lib/ subdirectory of the net-tools suite is
the source of the problem. In line 80 it uses the sizeof() operator to get
the size of the structure x25_address included from the "#include
<linux/x25.h>" line. The workaround I used was to add a line

struct x25_address x25_address_priv

to the beginning of the relevant function, X25_setroute() and change the line
80 use of sizeof(x25_address) to sizeof(x25_address_priv). This gives
sizeof() a structure named x25_address_priv of type x25_address which solves
the problems. compiled and installed correctly and replaced my bogus version of hostname...

hostname -f now returns my hostname!!!

Thank you all for contributing to this Q! The points go to Alf666 for pointing out the net-tools package...


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.