在linux平台上如何修改hostid

我们知道hostid作为一台主机的唯一标示符(hostname本身可能重复),而许多付费软件通过鉴别hostid发给相关的license.

hostname的修改较为简单,只需要修改/etc/sysconfig/network中的hostname并重启即可。

hostid的修改就不那么方便了,下面介绍一种方法:

编辑一个c文件,是的之后你还需要修改它,就叫做host.c吧!

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

int main() {
long id,res;

// get real (default) hostid
id = gethostid();
printf("current hostid is: %x\n",id);
// set new hostid if is superuser
res = sethostid(0xa090d01);                    //括号内填入你想要的hostid
if (res == 0) printf("if result is zero - success! (%d) \n",res);
// check if it is changed....
id = gethostid();
printf("current hostid is: %x ;-PPPppppp\n",id);
}

之后我们需要编译它

[root@pmsora ~]# cc host.c
[root@pmsora ~]# ./a.out                   //编译后运行
current hostid is: a090d01
if result is zero - success! (0)
current hostid is: a090d01 ;-PPPppppp
[root@pmsora ~]# hostid
0a090d01                                         //hostid正确修改了

注意运行编译好的目标文件时必须使用root用户。



Posted

in

by

Tags:

Comments

Leave a Reply

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