Results 1 to 7 of 7

Thread: HOWTO: Editing /etc/hosts

  1. #1
    Join Date
    Oct 2004
    Binary Land, Maryland

    HOWTO: Editing /etc/hosts

    Here is a quick how to, to edit your /etc/hosts file.
    The $ represents a line of code you may enter in a terminal.

    Open /etc/hosts with your favorite text editor. Remember to use sudo.

    Example: localhost.localdomain localhost
    Replace the <IP> with the IP of your system. If your running DHCP do not worry about editing this file. To detect your IP address run
    $ lsconfig
    Then browse for the connected interface (eth0, wlan0, etc)

    Replace the <HOSTNAME> to your systems hostname.
    To view current hostname:
    $ hostname
    To change hostname:
    $ sudo hostname 'enterhostname'
    (without quotes)
    Domain Name
    The domain name can be anything you like unless it must be resolv, which then you must use /etc/resolv.conf. But thats another issue i'll cover later!

    Alias are simply another way to combine a set of arguments. When you create a hosts file, its simply creating a list of hosts on the network, or locally. Its much easier to understand if you kept the alias the same as the hostname. It saves a lot of trouble with debugging and troubleshooting. But you are free to use whatever you like.

    That should help you out. Please comment!
    ][ My Blog ][

  2. #2
    Join Date
    Oct 2004
    Arendal, Norway

    Re: HOWTO: Editing /etc/hosts

    Nice. You can make shortcuts for webpages with alias
    Code: g
    Type ctrl+L,g,enter in firefox to go to google.

  3. #3
    Join Date
    Nov 2004
    Ankara, Turkey

    Re: HOWTO: Editing /etc/hosts

    you can do the same more practically by giving a keyword to a bookmark, in firefox.
    Just go to bookmars->manage bookmarks
    and open the bookmark's properties, entering the keyword and
    clicking OK.

    this link describes more, quick searches, which in my opinion are great:

  4. #4
    Join Date
    Dec 2006
    Mississauga, ON, CA

    Re: HOWTO: Editing /etc/hosts

    Would anyone know why this would not work on Edgy?

    I'm trying to access my webserver in my LAN, however due to my firewall I cannot use the external address, I have to use my internal address to my DMZ.

    I'd like to have my translation done like this HOST.DOMAIN = DMZ IP. It's very useful when looking at information posted on the web with the source on ur webserver.

    victor@victor-laptop:~$ cat /etc/hosts       localhost       victor-laptop    home   g
    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    ff02::3 ip6-allhosts
    The alias for google is also not working.

    I also restarted my network and logged out and back in, but no doughnut..

    sudo /etc/init.d/networking restart


    Your verbose output has been redirected to /dev/null
    User 437407 with the Linux Counter -- My Site -- My Blog

  5. #5
    Join Date
    Oct 2005

    Cool Re: HOWTO: Editing /etc/hosts

    Related links:

    What I can't find is a simple, complete best/standard practices guide on how to set the hostname for a laptop and for a box with a static IP and FQDN.

  6. #6
    Join Date
    Jan 2008

    Re: HOWTO: Editing /etc/hosts

    Should I add my static IP address in the hosts file as well as the one I use on my local network?

    Code:	localhost	mmpcubuntu	mmpcubuntu

  7. #7
    Join Date
    Sep 2010

    Re: HOWTO: Editing /etc/hosts

    The reason this line won't work: home

    is because is a private ip address & has to resolve to a public ip address. To use as the FQDN you need to enter the router's public ip address & set the router to forward port 80 traffic to your private ip address. If it's not your network (meaning that your netadmin won't give you access to the router/firewall) you can just replace with mysite.localhost and use mysite as an alias. The easiest way to access your webserver from the inside, however, is to just enter localhost in the address bar if the server is on your machine, or enter the ip ( in the address bar if it's not. The result will be the same no matter how you address it from your browser. You'll see the same thing everyone else sees.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts