Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

howto change the hostid under linux.

Status
Not open for further replies.

shemo

Advanced Member level 4
Joined
Apr 26, 2002
Messages
105
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
709
linux hostid

there has been talk under solaris but not much under linux
 

Pigi_102

Member level 1
Joined
Nov 14, 2007
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,643
hostid linux

take a look at:



and exactly where it states:

#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(0x11223344);
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);
}

HTH

Pigi
 

tsinghua

Full Member level 4
Joined
Dec 30, 2003
Messages
222
Helped
23
Reputation
46
Reaction score
3
Trophy points
1,298
Activity points
1,111
linux change hostid

In Linux, hostid is the MAC of NIC.
You can change it using ifconfig.
ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
 

Pigi_102

Member level 1
Joined
Nov 14, 2007
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,643
change hostid linux

tsinghua said:
In Linux, hostid is the MAC of NIC.
You can change it using ifconfig.
ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx

this is not ( completely ) true.
Mac is only used to compute the hostid by using it in some operation ( as can be read in hostid.c)
on my machine I have:
topolinux root /tmp >ifconfig -a | grep -i hwaddr
eth0 Link encap:Ethernet HWaddr 00:D0:59:B5:7A:4A
wifi0 Link encap:UNSPEC HWaddr 00-20-E0-9D-D5-31-77-6C-00-00-00-00-00-00-00-00
wlan0 Link encap:Ethernet HWaddr 00:20:E0:9D:D5:31
topolinux root /tmp >hostid
007f0143
topolinux root /tmp >

As you can see there is no direct relation between mac and hostid.
With the code I've posted you can take control of your hostid.
The code compute the contents that should be written in /etc/hostid to get the value you want:

topolinux root /tmp > ls -l /etc/hostid
/bin/ls: cannot access /etc/hostid: No such file or directory
topolinux root /tmp >gcc -o sethostid sethostid.c

topolinux root /tmp >./sethostid
current hostid is: 7f0143
if result is zero - success! (0)
current hostid is: 11223344 ;-PPPppppp
topolinux root /tmp > hostid
11223344
topolinux root /tmp > >ls -l /etc/hostid
-rw-r--r-- 1 root root 4 Nov 24 00:05 /etc/hostid
topolinux root /tmp >

HTH

Pierluigi
 

BigBoss

Advanced Member level 5
Joined
Nov 17, 2001
Messages
5,112
Helped
1,529
Reputation
3,056
Reaction score
1,376
Trophy points
1,393
Location
Turkey
Activity points
30,746
linux hostid change

If we could change the hostid of a computer,we can also use a existing license file that is created for another machine ?? So, we change the hostid of our computer and borrow a license file of another machine ???

I don't think so easy..
 

calibre

Newbie level 5
Joined
Jun 13, 2006
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,336
linux host id

Dear bigboss, you can try it, i have copied another license by changed another machine hostid, now it seems that the license is ok
 

suresh_kvja

Member level 3
Joined
Jul 28, 2007
Messages
66
Helped
4
Reputation
8
Reaction score
3
Trophy points
1,288
Location
India
Activity points
1,585
hostid in linux

Its easy :)

follow

ifconfig eth0 down
ifconfig eth0 hw ether 00:00:00:00:00:00 (new MAC ID)
ifconfig eth0 up

write these three commands in a file and make it executable and execute this file if you want to change your MAC ID

I think this solves :)




BigBoss said:
If we could change the hostid of a computer,we can also use a existing license file that is created for another machine ?? So, we change the hostid of our computer and borrow a license file of another machine ???

I don't think so easy..
 

yakc

Newbie level 1
Joined
Mar 11, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,299
/etc/hostid

Pigi_102 said:
take a look at:



and exactly where it states:

#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(0x11223344);
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);
}

HTH

Pigi


Hi Pigi:

How come I can not compile the above code:

gcc -o changehostid changehostid.c
changehostid.c: In function ‘main’:
changehostid.c:9: error: stray ‘\342’ in program
changehostid.c:9: error: stray ‘\200’ in program
changehostid.c:9: error: stray ‘\235’ in program
changehostid.c:9: error: ‘current’ undeclared (first use in this function)
changehostid.c:9: error: (Each undeclared identifier is reported only once
changehostid.c:9: error: for each function it appears in.)
changehostid.c:9: error: expected ‘)’ before ‘hostid’
changehostid.c:9: error: stray ‘\’ in program
changehostid.c:9: error: stray ‘\342’ in program
changehostid.c:9: error: stray ‘\200’ in program
changehostid.c:9: error: stray ‘\235’ in program
changehostid.c:11: error: ‘a8c06602’ undeclared (first use in this function)
changehostid.c:12: error: stray ‘\342’ in program
changehostid.c:12: error: stray ‘\200’ in program
changehostid.c:12: error: stray ‘\235’ in program
changehostid.c:12: error: expected expression before ‘if’
changehostid.c:12: error: stray ‘\’ in program
changehostid.c:12: error: stray ‘\342’ in program
changehostid.c:12: error: stray ‘\200’ in program
changehostid.c:12: error: stray ‘\235’ in program
changehostid.c:15: error: stray ‘\342’ in program
changehostid.c:15: error: stray ‘\200’ in program
changehostid.c:15: error: stray ‘\235’ in program
changehostid.c:15: error: expected ‘)’ before ‘hostid’
changehostid.c:15: error: stray ‘\’ in program
changehostid.c:15: error: stray ‘\342’ in program
changehostid.c:15: error: stray ‘\200’ in program
changehostid.c:15: error: stray ‘\235’ in program

Seems it can not find the function, gethostid and sethostid. I can man gethostid and sethostid. Any trick.

Thanks.

Yakc
 

R00KIE

Full Member level 3
Joined
Jan 19, 2003
Messages
150
Helped
23
Reputation
46
Reaction score
3
Trophy points
1,298
Location
Portugal
Activity points
1,255
change linux hostid

Well, so far I've only seen the hostid being the same as the mac address of the first network card (usually eth0) and thats what goes into the license files .... doing what suresh_kvja said usually does the trick.
 

nhereveri

Newbie level 1
Joined
Dec 16, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,284
Please check my code and post any issue in Modificar identificador de host | hereveri.cl.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>

int main(int argc, char *argv[]) {
  int base, status;
  char *str, *endptr;
  long id;
  if(argc < 2) {
    fprintf(stderr, "Usage: %s hostid [base]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  str = argv[1];
  base = (argc > 2) ? atoi(argv[2]) : 16;
  errno = 0;
  id = strtol(str, &endptr, base);
  if ((errno == ERANGE && (id == LONG_MAX || id == LONG_MIN)) || (errno != 0 && id == 0)) {
    perror("strtol");
    exit(EXIT_FAILURE);
  }
  if (endptr == str) {
    fprintf(stderr, "No digits were found\n");
    exit(EXIT_FAILURE);
  }
  status = sethostid(id);
  if(status == 0) fprintf(stdout, "Host id changed to 0x%x\n", id);
  else {
    perror("sethostid");
    exit(EXIT_FAILURE);
  }
  return 0;
}
Thanks in advance!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top