Static IP in Ubuntu

This tutorial is for anyone who wants to use a static ip instead of dhcp. Let’s face it, having a server using dhcp is a bad idea.

First we need to edit /etc/network/interfaces

$ sudo nano /etc/network/interfaces

Typically if you’re using dhcp, your file would look something like the below. Keep in mind the interfaces may be different. For example if you’re using wireless you may see wlan0 or ath0; we’re primarily just looking for the interface you want to change

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

In this case, we want to change eth0. Simply change dhcp to static and append some additional network info.

We’re going to need the IP address of that we want to use, the network mask which is typically, the network id, broadcast ip, and your gateway – which is typically your router's IP. All of which can be found using any other machine on your network: using ipconfig /all on any windows box or ifconfig on any *nix machine.

auto eth0  
iface eth0 inet static

Once you’ve made the proper changes and saved the file, can you either reboot or restart your nic

sudo /etc/init.d/networking restart

Originally published at on March 18, 2008.

Like what you read? Give Sean Wragg a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.