System

How to change Host ID for Linux

hostid is a command for viewing a Linux machine’s ID. Linux creates a host ID at installation, and a new installation will not have the same ID. Many licensed programs therefore tie their licenses to the host ID for protection… View the host ID with the hostid command, as shown below.

[root@Ezylinux ~]# hostid
007f0101

To change the host ID: First, you need gcc (the compiler). If it is not installed, run:

[root@Ezylinux ~]# apt-get install gcc*  //สำหรับสาย debain

or

[root@Ezylinux ~]# yum install gcc*      //สำหรับสาย red hat

Next, create a file named sethostid.c containing the code below. Change the value in sethostid to the host ID you want.

#include
#include 

int main() {
long id,res;
id = gethostid();
printf("current hostid is: %x\n",id);
res = sethostid(0x11223344);  // แก้ไขค่า 11223344 เป็นค่าที่ต้องการ
if (res == 0) printf("if result is zero - success! (%d) \n",res);
id = gethostid();
printf("current hostid is: %x ;-PPPppppp\n",id);
}

Then compile it with:

[root@Ezylinux ~]# gcc -o sethostid sethostid.c

Compilation produces a file named sethostid. Run the program with the command below.

[root@Ezylinux ~]# ./sethostid
EOF.← Back to articles