Change Linux Host ID

Are you know how to Change Linux Host ID ?

The host address, or the host ID portion of an IP address, is the portion of the address used to identify hosts (any device requiring a Network Interface Card, such as a PC or networked printer) on the network. The network ID, by contrast, is the portion of the address that refers to the network itself (wikipedia). We can check Host ID in our computer with command :

toto@toto-laptop:~$ hostid

This Host ID is default from my computer. We can change Linux Host ID manually. This is my code to Change Linux Host ID. Copy this code and save as ChangeLinuxHostId.c :

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

int main(int argc, char **argv)
  int id,res;
  int newid;

  sscanf(argv[1], "%x", &newid);

  // get default hostid
  id = gethostid();
  printf("Current Host ID is: %x\n",id);

  // login as super user and change host id
  res = sethostid(newid);
  if (res == 0)
    printf("succes change Host ID \n");
    printf("fail change Host ID \n");

  // check if it is changed....
  id = gethostid();
  printf("New Host ID is: %x\n",id);


We can compile this C/C++ Code Change Linux Host ID (ChangeLinuxHostId.c) with command :

gcc ChangeLinuxHostId.c -o ChangeLinuxHostId

We can running this C/C++ Code Change Linux Host ID as superuser. This is sample output when we Change Linux Host ID from above code :

toto@toto-laptop:/home/toto$ sudo ./ChangeLinuxHostId 0x007f0500
Current Host ID is: 7f0100
succes change Host ID
New Host ID is: 7f0500

This is output when we try to check our new Linux Host ID :

toto@toto-laptop:~$ hostid

This is a simple method how to Change Linux Host ID with our code program. If you have any other method, please share.

source :

Add a Comment

Your email address will not be published. Required fields are marked *