1

Many of the servers in our environment have their loop-back line in /etc/hosts configured like so:

127.0.0.1        mydevserver.testdomain.com mydevserver localhost.localdomain localhost

Normally, this is not an issue. However, we are now dealing with some external software from a vendor that calls gethostbyaddr and their installer is designed to fail if the result of hostname --ip-address is 127.0.0.1. This of course causes it to fail on our systems because the servers hostname is in the loopback line of /etc/hosts.

My question is, if I wrap the installer in a bash or perl script, is there a way to "mask" or temporarily alter the results of hostname --ip-address without changing the /etc/hosts file?

(Clarification: They are calling the gethostbyaddr() function from within their compiled binary installer. The way to get a similar result from command line is hostname --ip-address)

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
Eli
  • 716
  • 1
  • 6
  • 12
  • Things like this is why it's not uncommon to use some other `127.*.*.*` address like `127.0.1.1` instead for the FQDN of the server. I know this is not what you asked, so I'm just adding this as a comment, not an answer. – clacke Nov 25 '13 at 10:16

4 Answers4

4

One way might be to write your own gethostbyaddr() function, compile it into a library (say, libmyfunc.so), then preload it in a wrapper script so the vendor's installer uses it rather than the system gethostbyaddr() :

#!/bin/bash    
export LD_PRELOAD=libmyfunc.so
export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH

/path/to/crappy_vendor_binary $@
Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
  • An ugly way to do it, but it may be a necessity due to the ugliness of the vendor's software. – Eli Apr 23 '11 at 19:02
1

Write your own implementation of hostname that does the expected thing, put it somewhere, unshift that directory before $PATH.

daxim
  • 39,270
  • 4
  • 65
  • 132
  • Thanks, but they are calling the gethostbyaddr() function from within their compiled binary installer. The way to get a similar result from command line is **`hostname --ip-address`**. – Eli Apr 14 '11 at 00:31
1

If the really call the hostname command, then nothing is easier than that: just replace it with your own version.

Ingo
  • 36,037
  • 5
  • 53
  • 100
  • Thanks, but they are calling the gethostbyaddr() function from within their compiled binary installer. The way to get a similar result from command line is **`hostname --ip-address`**. – Eli Apr 14 '11 at 00:33
  • @Eli, then you better update your /etc/hosts. I am pretty sure there is no rational reason for your practice, is there? Since this is an installer, a temporary clean /etc/hosts would do. – Ingo Apr 14 '11 at 08:54
0

well if it's a plain BASH script, add this before the call of "hostname":
function hostname(){ echo -n; }

Matt
  • 2,790
  • 6
  • 24
  • 34