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.

What I need is to configure a Linux machine, so that when user of that machine goes to www.somesite.com he/she is redirected to, say, 127.0.0.1.

What is the best way to achieve it?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Linux has the same host file. Just edit:

/etc/hosts

Depending on your system a command like this will open up that file:

$ sudo nano /etc/hosts

Just put lines like this in there and save:

<IP>    <HOSTNAME> <SHORTNAME #1> <SHORTNAME #2> ....

For example:

192.168.1.1    www.anothersite.com wwwanother
share|improve this answer
    
How to achieve the reverse? –  Acute Sep 2 '13 at 16:53
1  
That file will convert www.anothersite.com or wwwanother to 192.168.1.1 which is what you are looking for. –  Drav Sloan Sep 2 '13 at 17:42
    
should I restart after editing the hosts file? –  Acute Sep 2 '13 at 21:22
    
You should flush your dns cache blog.sudobits.com/2012/07/12/… and restart your browser. But reboot is another option. –  fclad Sep 3 '13 at 4:46
1  
@fclad installing the nscd made the things work. –  Acute Sep 3 '13 at 7:37
show 1 more comment

If you want to override entries on more than one machine, then you could set up a DNS proxy such as Unbound or DNSmasq.

share|improve this answer
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.