Skip to content
Advertisement

Change hostname to null in linux [closed]

I downloaded elf file on the server but, it checks whether the file is executing on the server or not. By debugging it with gdb and i found that there is a ‘gethostname’ function and if the function returns 0 the file stop with the message ‘Running on an illegal host’. Searching from internet ‘gethostname’ return -1 when the hostname is null. So how can i change my hostname to return -1 and execute the program? or is there any ways to return -1 without changing my hostname to null?

Advertisement

Answer

If you know which hostname is accepted by the “elf file”, you can change the hostname of your system with the “hostname” command.

If you don’t want to change the hostname globally, you can run your program in a LXC container into which you can change the hostname.

If running a container is heavy or difficult, you can run your “elf file” in a brand new UTS namespace with a command like “unshare” :

      $ sudo unshare -u /bin/bash  # Run a bash in a new UTS namespace 
      # hostname foo   # Change hostname in the new UTS namespace
      # ... Run your program ...
      # exit  # exit the shell and go back to original UTS namespace
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement