How to set static IP on Ubuntu

Did you ever have a need to set a static IP address on a Ubuntu box? Well, here's how to do it:
1) edit file /etc/network/interfaces
2) change your file to look something like this:

auto eth0
iface eth0 inet static
        addresss 192.168.1.8
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        gateway 192.168.1.1

If you want to go back to DHCP, simply change it back to:

auto eth0
iface eth0 inet dhcp

Please note, that after you make any modifications to the interfaces file, you have to restart your networking by invoking:

sudo /etc/init.d/networking restart

or

sudo invoke-rc.d networking restart

Comments