[BLUG] Ubuntu Speed Tweak - /etc/hosts
Steven Black
blug_at_mailman.cs.indiana.edu
Wed, 21 Mar 2007 15:10:50 -0400
I can tell you why this works:
The default for Ubuntu is to have the hostname's IP address mapped to an
IP address on the localnet (127.x.x.x) but not to assign that address to
an interface.
Basically, this change is making any service that would normally grab
your IP address based upon your hostname grab the localhost IP address
instead.
You should be able to achieve the same result if you create an alias
setting lo:0 to 127.0.1.1.
If you use a fixed IP address mapping your machine name to the localhost
IP may cause your machine to not work as expected. (If you have services
you run on the machine they will be completely unavailable unless they
bind to every available address.)
The loopback interface is much faster than any physical interface. It's
also faster than trying to access an IP address that is undefined. This
is where the speed improvement is coming.
Personally, I used fixed IP addresses for any machine running Linux on a
fixed network. As such, my machine name is usually mapped to an address
on an eth port. (It makes it easier to SSH into the machine.)
Now it used to be that by default would be a mapping for the hostname to
the localhost IP address if you didn't specify a fixed IP address. This
was changed so presumably they had a reason for that change. I first
noticed this change with Ubuntu 6.06 (Dapper) so the Ubuntu bug database
may mention it. I do not believe this is in Debian's 'etch' distribution
(I didn't see it in the /etc/hosts file of the Debian etch system I
administer and I usually comment out those lines instead of deleting
them.)
Cheers,
Steven Black
On Wed, 2007-03-21 at 12:30 -0400, Simon Ruiz wrote:
> For those of you using Ubuntu, though likely not applicable ONLY those using Ubuntu, this little tweak gives your application load time a HUGE boost--that is, it makes application load times noticeably shorter.
>
> <disclaimer>I have no idea why this works</disclaimer>
>
> Edit your "/etc/hosts" file:
> $ sudo gedit /etc/hosts
>
> You should see something like this:
>
> 127.0.0.1 localhost
> 127.0.1.1 martin-laptop
> (and if your in Feisty, some lines about IPV6
>
> Now, add the following:
>
> 127.0.0.1 localhost martin-laptop
> 127.0.1.1 martin-laptop
> (Replace "martin-laptop" with your hostname)
>
> Save. Should work instantly, or sometimes on reboot.
>
> Read at Martin Albisetti's blog <http://beuno.com.ar/?p=4> (via the Ubuntu Planet RSS feed).
>
> To be perfectly honest, I didn't even notice I was taking a performance hit because the sorts of load times I got before this tweak were comparable to load times I've been used to expecting on Windows for a long time.
>
> Hope this finds you all doing great!
>
> Simón
>
>
> _______________________________________________
> BLUG mailing list
> BLUG_at_linuxfan.com
> http://mailman.cs.indiana.edu/mailman/listinfo/blug