How to make a static IP address in Ubuntu

If you have a new install of Ubuntu/Debian, you’ll notice that eth0 is always set to “DHCP”.  While this is fine and dandy for user environments, out there in the server world, we like static IP addresses.

  1. First thing’s first…. open the /etc/network/interfaces file.

    sudo vi /etc/network/interfaces

  2. Next, you want to change the eth0 DHCP setting to Static and add your Networking:

    BEFORE:

    iface eth0 inet dhcp

    AFTER:

    iface eth0 inet static
    address 192.168.58.135
    netmask 255.255.255.0
    network 192.168.58.0
    broadcast 192.168.1.255
    gateway 192.168.58.2

  3. Restart Networking and enjoy!

    sudo /etc/init.d/networking restart

  4. [UPDATE] (Thanks Mike)

    You may lose your name-server config upon reboot, so you can add this to your static IP config in /etc/network/interfaces:

    dns-nameservers 192.168.58.2


Leave a Reply

Responses to “How to make a static IP address in Ubuntu”

  1. Mike Mackintosh (@mikemackintosh) April 15th, 2013 - 2:15 pm

    I would suggest that you also add:

    dns-nameservers 192.168.58.2

    To your static interface. When you restart that interface or reboot, you may lose your nameserver configuration in /etc/resolv.conf.