0

Is there a way to add a local hostname/ip mapping on the fly on the commandline? (Thus, editing /etc/hosts would not be a good solution in this case )

Something in the vain of:

HOSTS=127.0.0.2=localsignificanthostname;127.0.0.3=otherspecialhostname ping localsignificanthostname
  • I wonder, why you do not ping the IP address instead. – FedonKadifeli Sep 15 at 10:46
  • ping might be a stupid example in hindsight. For applications which do HTTP requests, the hostname is of vital importance. Curl for example does have a separate host option which you can pass along such that curl knowns which host header to send, not all applications have this. – hbogert Sep 15 at 10:57
  • 1
    OK, I see. The closest thing I found is this: unix.stackexchange.com/questions/483167/… – FedonKadifeli Sep 15 at 11:02
  • 1
    nope. just add them to /etc/hosts. or run a local name server. or rely on the crappy and unreliable avahi daemon. – cas Sep 15 at 11:03
1

You did not specify the OS, but in Linux you can use unshare(1):

# unshare -m sh -c "mount -B /tmp/fakehosts /etc/hosts; ping localsignificanthostname"

requires root, namespaces and reasonably recentish kernel (which you usually have).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.