Changing hosts file in Ubuntu

34,920

/etc/hosts (or it's equivalents on other OS's) is used to resolve hostnames to some ip without asking to dns servers.

You can use in your /etc/hosts:

127.0.0.1 myserver.com

And then open http://myserver.com:3333 in your browser and it will connect to 127.0.0.1 to 3333 port.

You can NOT map ip addresses with /etc/hosts.

You can use iptables for this. But that's another question.

Share:
34,920
Ivanka Todorova
Author by

Ivanka Todorova

(‘‘,)

Updated on March 21, 2020

Comments

  • Ivanka Todorova
    Ivanka Todorova over 4 years

    I came here to ask you how to set up my hosts file in Ubuntu so when I go to 95.42.251.194:3333 my browser to open 127.0.0.1 .

    I tried this: 127.0.0.1 95.42.251.194:3333

    Thanks in advance!

  • Nialscorva
    Nialscorva over 12 years
    cyberciti.biz/faq/linux-port-redirection-with-iptables shows how to do the port mapping.
  • Sergey P. aka azure
    Sergey P. aka azure over 11 years
    My original answer was approved to change by other users. Originally there were: ------------------------------- You can use in your /etc/hosts: 127.0.0.1 mysuperserver ------------------------------- This is ok and works in any OS. Probably suggested change by adding port to hosts record (127.0.0.1 mysuperserver:3333) works in some OS, but it's surely does not work in linux.