home January 01, 2017

Fake or Change the HostID


If you have every had to move a license server to another machine or reload your current license server then you might have run into this problem. The new system is up, but the FlexLM or other license manager will not start. This is probably because your hostid on the new machine is different from the old one.

You can call up your authorized license company every single time you want to change your own environment, or you can modify your hostid on the new box to look like the old one.

In our example we have a deprecated sparc machine we will call, "old_sparc" and we want a linux box called, "new_linux" to have the same hostid.

1. What is the hostid of the original machine?

We first need to know what the hostid of the old box (old_sparc) is. Execute hostid on old_sparc:

root@old_sparc# hostid
728b7432

2. Compile and run "change_hostid.c"

This is a dead simple c program built to take the target hostid of the old machine and make a compatible /etc/hostid file. It calls the function sethostid to complete this task. The /etc/hostid file will be made and read on the new machine. Copy and paste the following code onto the new linux/solaris/irix machine in a text file called "change_hostid.c".

#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
if(argc < 2)
{
fprintf(stderr,"Single argument: Target hostid\n",argv[0]);
return 1;
}
sethostid(
strtoul(argv[1],NULL,16) );
return 0;
}

Now, compile the code with the following command. Once the code is compiled you can move and run it to any compatible OS.

root@new_linux# gcc change_hostid.c -o change_hostid

3. Change the hostid of the new machine

To set the hostid on "new_linux" to be the same as "old_sparc" we need to run change_hostid as root with the single argument of the target hostid. The reason we need to be root is the script will want to write to /etc/hostid. For example, lets verify the original hostid, then change it with "change_hostid" and then look at the new hostid.

root@new_linux# hostid
a8c33405
root@new_linux# ./change_hostid 728b7432
root@new_linux# hostid
728b7432

What about setting the hostid on reboot?

You will notice the file /etc/hostid will now have a string in it. This string is used to calculate the hostid on the new machine to get the target hostid. When the system is rebooted the system will read the contents of /etc/hostid and set the hostid to 728b7432.

Thats it. All done.