Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
1  
The last line is unclear. Also, wouldn't this fit more in SF? –  Tshepang Feb 4 '11 at 8:40
    
@tshepang ... no because I need to do this on a linux desktop? –  xenoterracide Feb 4 '11 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 '11 at 10:53
2  
@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. –  xenoterracide Feb 6 '11 at 5:20
add comment

6 Answers

up vote 18 down vote accepted

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

share|improve this answer
    
really this should be like +10k, unfortunately I can only give you +1 –  xenoterracide Nov 21 '12 at 22:03
    
I agree! +10k!! –  Anders Hansson Sep 21 '13 at 16:45
add comment

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.

share|improve this answer
add comment

Check out following question at superuser:

http://superuser.com/questions/184643/override-dns-in-firefox

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

http://superuser.com/questions/100239/hostname-override-in-firefox

Especially check out:

https://addons.mozilla.org/en-US/firefox/addon/redirector/

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

share|improve this answer
    
unfortunately much like the op in that question none of these seem viable. –  xenoterracide Feb 4 '11 at 10:28
    
@xenoterracide - I updated my answer - perhaps the redirector add-on is an option? –  maxschlepzig Feb 4 '11 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 –  xenoterracide Feb 6 '11 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. –  xenoterracide Feb 6 '11 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. –  xenoterracide Feb 6 '11 at 5:32
add comment

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.

share|improve this answer
    
easier said than done, considering the great firewall that's been erected to block us from ssh-ing out... –  xenoterracide Feb 6 '11 at 5:21
add comment

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
share|improve this answer
4  
Most usefully, make your wrapper redirect the opening of /etc/nsswitch.conf to ~/.nsswitch.conf, and make a ~/.nsswitch.conf that queries your DNS databases. –  Gilles Feb 4 '11 at 23:49
add comment

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)

Update

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/
share|improve this answer
2  
-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. –  xenoterracide Feb 4 '11 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 '11 at 13:01
1  
@xenoterracide BTW, there wasn't any intention to offend. –  tmow Feb 4 '11 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... –  xenoterracide Feb 6 '11 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 '11 at 5:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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