Continue to Site

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
 

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
 

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
 

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
 

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..
 

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
 

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..
 

/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
 

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.
 

Please check my code and post any issue in **broken link removed**.
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

Back
Top