I want to set a dns record that my browser will use, but I don't have root access, so I can't modify /etc/hosts. I need to do this for testing vhosts with apache, whose dns hasn't yet been set up. I have access to firefox, and chrome, so if there's a plugin that could facilitate it; or other options are helpful.

update: the alternative to overriding the dns is probably modifying the HTTP headers, if the correct ones are sent to apache, the correct content should be returned.

  • 1
    The last line is unclear. Also, wouldn't this fit more in SF?
    – tshepang
    Feb 4, 2011 at 8:40
  • @tshepang ... no because I need to do this on a linux desktop? Feb 4, 2011 at 10:03
  • 1
    Still not so clear. What does "or other options are helpful" mean exactly? Don't make me guess.
    – tshepang
    Feb 4, 2011 at 10:53
  • 3
    @tshepang I don't know what I'm looking for... if I knew why would I be asking? there might be options that I haven't considered. I feel like you're asking me to explain how apache virtual hosts, http, and dns work together. Feb 6, 2011 at 5:20
  • I think you're looking for this: unix.stackexchange.com/a/104511/135943
    – Wildcard
    Jul 3, 2017 at 21:42

9 Answers 9


I was looking for a way to run a program with modified DNS resolution for testing purposes. For me, the solution was using the HOSTALIASES environment variable:

$ echo "foo www.google.com" >> ~/.hosts
$ HOSTALIASES=~/.hosts wget foo

See hostname(7).

(Side note: In the example the HOSTALIASES environment variable only affects the wget process. Of course, you can export HOSTALIASES to have it take effect for all subprocesses of the current shell.)

  • 1
    really this should be like +10k, unfortunately I can only give you +1 Nov 21, 2012 at 22:03
  • I agree! +10k!! Sep 21, 2013 at 16:45
  • 3
    Thanks a lot! The example should prepend export in most cases: export HOSTALIASES=~/.hosts. Apr 26, 2014 at 22:04
  • 9
    it seems only support hosts to hosts alias, not IP and hosts can not contain ".".
    – netawater
    Apr 16, 2015 at 5:26
  • Is there the same solution for Windows?
    – Akceptor
    Jun 9, 2017 at 7:39

You can write a wrapper around the libc function to resolve hostnames and look them up in a different file than /etc/hosts. Then run any application you'd like to use your hosts file with

LD_PRELOAD=wrapper.so firefox

I think the best way to do this would be to set up a SOCKS5 proxy and tell firefox to send the DNS requests over the SOCKS5 proxy (network.proxy.socks_remote_dns). You could set up a socks5 proxy with openssh fairly easily (the -D option) and have a remote host running with a custom /etc/hosts, or something like DNSMasq for more complex DNS settings. Effectively, though, this is pushing the configuration of the DNS settings to a system you can make system-wide changes to.

  • easier said than done, considering the great firewall that's been erected to block us from ssh-ing out... Feb 6, 2011 at 5:21

Check out following question at superuser:


If the discussed options and the SO link are not viable solutions then check out:


Especially check out:


It sounds like this addon could help - but I depends on its actual implementation.

  • unfortunately much like the op in that question none of these seem viable. Feb 4, 2011 at 10:28
  • @xenoterracide - I updated my answer - perhaps the redirector add-on is an option? Feb 4, 2011 at 19:38
  • I don't think so from the way it's worded.. what I really need to do is modify the HTTP headers that are sent... as an alternative option to hacking around using hosts Feb 6, 2011 at 5:14
  • I poked around the SO solution (TamperData) but I didn't see how to modify the host in that. I wonder if the live http headers thing really does allow me to modify headers, it says it's a viewer. Feb 6, 2011 at 5:18
  • I think the Modify Headers extension listed down a bit in the SO one works... if you use Host hostname... in it... not yet tested... outside of breaking sites using it. Feb 6, 2011 at 5:32

To test vhosts, you might set the Apache server as the proxy in Firefox. The name you entered will be forwarded to Apache. This will break browsing other sites so set the proxy back when you are done.


I needed something similar for ssh, scp etc. for a server which keeps changing IP every couple weeks (and our IT has a couple weeks delay in setting the host). I solved it using a special variable for this server: export FOO='131.227.aaa.bbb and then I can do just ssh bar@$FOO and I change the IP in my ~/.bashrc any time it changes...


overlayfs + chroot : )

problem: mount requires root access



mkdir -p $D/{upper,work,merged}
mount -t overlay overlay -o lowerdir=/,upperdir=$D/upper,workdir=$D/work $D/merged

echo ' myhost' >>$D/merged/etc/hosts

chroot $D/merged wget http://myhost/

It is possible to override dns resolution in google chrome in windows, mac and linux without root/admin access. All we need to do is to start google chrome process with a switch and supply the required DNS entries there.



Unlucky not, you cannot, except you write your own internet browser.

If you have to do some tests you need a test machine, whatever is a virtual machine or a real one, so you have to ask your Unix admin (or hosting provider) how you can put in place a development environment.

You can also install a VM on your PC, install a Linux distribution, Apache and test your changes (it's not as hard as it sounds)


To better explain, each application is written using the standard libraries, this way nobody has to rewrite the low level library and functions like the gethostbyname().

These functions normally are set to use file (/etc/hosts) and DNS, so, unlucky, if you need that your browser will resolve a name than the one is set in the /etc/hosts you don't have too many alternatives.

  1. You can set up your own DNS server and ask who has root rights to change the /etc/resolve.conf
  2. You can install a proxy server like DeleGate and set some rules for your VirtualHost
  3. Ask sudo rights on that customer host
  4. Change the behavior of the application you are using to test the connection (I guess the browser), for example https://addons.mozilla.org/en-US/firefox/addon/switchhosts/
  • 4
    -1 worded poorly and patronizing. I AM the hosting provider, and it's the damn customers site on our server that I need to test. We have a network boot linux that I do not have admin access to, and I don't believe I can boot a VM on it. Feb 4, 2011 at 10:01
  • @xenoterracide there is not too much to say. It's really not feasible what you are asking for, except you change the way a SOCKET is created.
    – tmow
    Feb 4, 2011 at 13:01
  • 1
    @xenoterracide BTW, there wasn't any intention to offend.
    – tmow
    Feb 4, 2011 at 13:08
  • well as the hosting provider... I have "sudo rights" actually, I have real root on every box, and full access to everything... except my desktop (eyeroll) but if they haven't wanted to change their nameservers yet.. I can't help that... Feb 6, 2011 at 5:02
  • 1
    with LD_PRELOAD you can 'override' specific 'low level' functions and do what you want, eg. telling the program about your own '/etc/hosts' on open() and any other low level call .. as long as dynamic loading of code is invovled (.so)
    – akira
    Feb 6, 2011 at 5:34

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.