linux hostid


原文链接: linux hostid

我们知道hostid作为一台主机的唯一标示符(hostname本身可能重复),而许多付费软件通过鉴别hostid发给相关的license. hostname的修改较为简单,只需要修改/etc/sysconfig/network中的hostname并重启即可。 hostid的修改就不那么方便了,下面介绍一种方法: 编辑一个c文件,是的之后你还需要修改它,就叫做host.c吧!

ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:A6:A7:1C

      inet addr:192.168.233.128  Bcast:192.168.233.255  Mask:255.255.255.0
      inet6 addr: fe80::20c:29ff:fea6:a71c/64 Scope:Link

[root@pr ~]# hostid
a8c080e9

将192.168.233.128 转换成16进制就是 c0.a8.e9.80,好像找到规律了

#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

`