Saturday, December 8, 2012

Setting up a static IP in Ubuntu 12.04+

Just about everything you read on the internets is wrong when it comes to setting up a static IP address on Ubuntu 12.04 or higher.  Take it from me, I've been there.

Here is how you do it.

Edit the /etc/network/interfaces file with root privileges.  You will want it to look like this:

auto eth0
iface eth0 inet static
address XXX.XXX.XXX.XXX (put in your static address here)
netmask XXX.XXX.XXX.XXX (for most of us this will be 255.255.255.0)
gateway XXX.XXX.XXX.XXX (this is where your default gateway goes)
network XXX.XXX.XXX.XXX (if you don't know what this is, don't bother with it)
broadcast XXX.XXX.XXX.XXX (same here, don't put this in if you don't know what it is)
dns-nameservers XXX.XXX.XXX.XXX YYY.YYY.YYY.YYY (here's the big one! all your dns servers separated by spaces.  DO NOT modify your /etc/resolv.conf file.)

Save your file, then with root privileges, type:
stop networking (obviously, this is not something you want to do from an SSH session)
start networking

...and there you go.