Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

11664

June 5th, 2008 11:00

how to change the hostid

Dears,

I would like to change the hostid for my linux machine from: 007f0100 to:a8c090a3.
so how can i do this. the system recovered from a crash and this is a licensing issue.

36 Posts

June 5th, 2008 13:00

I would like to change the hostid for my linux
machine from: 007f0100 to: a8c090a3.


Try (as root)

echo -e -n "\0243\0220\0300\0250" > /etc/hostid

It worked for me.

46 Posts

June 5th, 2008 13:00

I love you Michael, you are the boss. looooool

I was opening a case with EMC but they didn't know any thing about it.

lool, you are my man.

Message was edited by:
osama khreisha

1 Rookie

 • 

5.7K Posts

June 6th, 2008 04:00

Do you care to explain why this works ? I don't follow.....

36 Posts

June 6th, 2008 08:00

Do you care to explain why this works ? I don't follow.....


Rather than just pointing to the source code, let me describe how I figured it out.

According to the original poster, running "hostid" returns a funny looking value: 4 bytes, two of which are 0 and the other two are a decimal 127 and 1. This has the smell of an IP address, in this case that of the loopback address, 127.0.0.1.

If I run hostid on my workstation (Ubuntu 7.10) I get something slightly different: 007f0101 or the equivalent of 127.0.1.1 which is a little stranger but also seen in my /etc/hosts and is paired with the cannonical name of the workstation.

So the next question is "whence does 'hostid' get this information?". One easy way to try to answer the question is to run "strace" and look at the system calls "hostid" makes. The tail end of the trace looks like this:

open("/etc/hosts", O_RDONLY) = 3
fcntl64(3, F_GETFD) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
fstat64(3, {st_mode=S_IFREG|0644, st_size=532, ...}) = 0
mmap2(NULL, 4096, ...) = 0xb7cf1000
read(3, "127.0.0.1 localhost me\n127.0.1.1"..., 4096) = 532
close(3) = 0
munmap(0xb7cf1000, 4096) = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...}) = 0
mmap2(NULL, 4096, ...) = 0xb7cf1000
write(1, "007f0101\n", 9) = 9
close(1) = 0
munmap(0xb7cf1000, 4096) = 0
exit_group(0) = ?

A little playing around with the contents of /etc/hosts shows that the "hostid" command does indeed take the IP address of the canonical name of the host and use it as the hostid.

But something used for licensing might well be individualized by some distributions, so I went to an RHEL-based server and tried it. It seemed to work the same way. And here is where I got lucky ... just to verify it was doing much the same thing I ran another strace on the RHEL machine:

$ strace hostid 2>&1 | grep open
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
open("/lib/tls/libc.so.6", O_RDONLY) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
open("/etc/hostid", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/etc/hostid", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/etc/resolv.conf", O_RDONLY) = 3
open("/etc/nsswitch.conf", O_RDONLY) = 3
open("/etc/ld.so.cache", O_RDONLY) = 3
open("/lib/libnss_files.so.2", O_RDONLY) = 3
open("/etc/host.conf", O_RDONLY) = 3
open("/etc/hosts", O_RDONLY) = 3
$

That's when I noticed the reference to /etc/hostid, and that it comes before opening of files associated with a gethostbyname() call. A little playing around by creating that file and varying its contents verified its use.

Still the question remains, is the use of /etc/hostid unique to the hostid command? It turns out, checking the source, that the hostid command just calls gethostid() for its information. So there's no magic in the hostid command itself, it's all in the library call, gethostid(). The source for which, I did not peruse, having spent enough time already.

2.8K Posts

June 6th, 2008 09:00

Michael, using octal (and not hex) while echoing the new value to the hostid file gave your answer a touch of magic ;-)

Nice explanation !!

36 Posts

June 6th, 2008 12:00

Michael, using octal (and not hex) while echoing the
new value to the hostid file gave your answer a touch
of magic ;-) Nice explanation !!


LOL. It's only because I couldn't remember if bash's builtin echo supported anything more than octal escapes.

2.8K Posts

June 9th, 2008 02:00

I googled a little .. and run some tests with cygwin and colinux ..

delcos@ITTGDELCOSL1C ~
$ echo -e -n "\x78\x78"
xx


:D

1 Rookie

 • 

20.4K Posts

June 9th, 2008 04:00

colinux ...how cool is that, how's its performance ?

2.8K Posts

June 9th, 2008 06:00

perf..what ?? :D

I use it instead of vmware since it's lighter .. but it isn't faster :D .. at least IMHO :D
No Events found!

Top