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 255.255.255.0
, 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
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
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 seanwragg.com on March 18, 2008.