how to configure a static IP address on Ubuntu Server

From Sharkysoft Wiki
Jump to: navigation, search

After a fresh install of Ubuntu Server, your system's network interface will probably be configured for DHCP. However, if you're setting up a server, you'll need to have a static IP address. This article shows you how to reconfigure your network interface to use a static IP address.


tips and disclaimers

This procedure...

  • ...was tested on Ubuntu Server 12.10. (It was adapted from an out-of-date procedure used on prior Ubuntu versions.)
  • ...requires root access.
  • ...might be easier if you can copy and paste from this article. For this reason, you should consider remote shelling into your server from the computer that you are reading this guide on.
  • ...contains example values that you must adjust for your own circumstances. Don't blindly copy!

Step 1: Record current name servers.

Since your system is currently configured for DHCP, your DNS servers have probably already been configured. However, after you update your system to use a static IP address, that configuration will be lost. Therefore, before you switch to a static IP address, you should note the addresses of your current DNS servers.

To do this, have a look at contents of your /etc/resolv.conf file:

cat /etc/resolv.conf

Jot down the address (or addresses) after the nameserver label. You'll need these in Step 3.

Step 2: Specify the static IP address and network.

To specify a static IP address, edit the file /etc/network/interfaces.

sudo nano /etc/network/interfaces

Look for the definition of the primary interface, which is usually called eth0. Its current configuration might look something this:

# The primary network interface
auto eth0
iface eth0 inet dhcp

Change the parameter "dhcp" to "static". Then, immediately underneath that line, insert the following lines, which are required to fully specify your static configuration. (Make sure you adjust parameters, as necessary, for your particular network.)


For information about these and other configuration directives applicable in this file, consult the man page by issuing the command,

man interfaces

Keep /etc/network/interfaces open in your editor for the next step.

Step 3: Configure DNS.

Below the new configuration directives you just added, include the following:


Substitute the name server addresses you recorded in Step 1, separated by a space. Also substitute your preferred DNS search suffixes (or just omit the line entirely, if you don't want any).

Step 4: Double-check and save.

When you are finished editing interfaces, it will probably look something like this:

# 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 static


Don't fret if a few things outside of the area where you edited (for eth0) are different. Just make sure the important parts are right.

If you are satisfied with your edits, save the file and exit the editor.

Step 5: Restart networking.

Now it's time to apply your changes by restarting your network. Do this by issuing the following command:

/etc/init.d/networking restart

This will cause the file you edited to be re-read. It will also cause /etc/resolv.conf to be regenerated.

Step 6: Confirm results.

You can confirm that your static IP address went into effect by issuing the following command:


In the command output, you should see, among other things, your static IP address.

Next, test network connectivity by pinging a popular domain:


(Use Ctrl+C to quit pinging.)

Finally, inspect the contents of your resolv.conf file:

cat /etc/resolv.conf

The contents of this file should have been regenerated. Verify that your DNS information is there.

Personal tools