Home » Networking » Setting up a static IP address in Ubuntu

Setting up a static IP address in Ubuntu

Setting up a static IP address in Ubuntu is very easy!

Before getting started though I recommend doing this at the terminal itself or be within a close proximity of it.

So that if you do make an error and lose connectivity you can revert the changes easily!

Note that when setting up a static IP you should first review your network settings.

With that said lets get started.

In Ubuntu by default your /etc/network/interfaces configuration file will look like the following below.

sudo vi /etc/network/interfaces


For our example lets say we want configure our network configuration to the following (This should work on most default networks, especially home networks)

Change the line iface eth0 inet dhcp to iface eth0 inet static and add the following just below it:

address (IP address of what you want your Ubuntu machine to be)
(Default mask which in this case is the default class c subnet)
(Typically your router’s IP address)
(The network that this machine is running on)
 (A message that is sent to all out network-attached hosts to essentially find a specific address. You also receive them from other hosts)
 (DNS or Domain Name Server used for responding to queries when you are searching for a website)

Alternatively, for your dns-nameservers some people prefer to use Google’s Public DNS which is or you can easily swap to one of Googles. You can find more information regarding Google Public DNS here.

Here is a screenshot of how it should look below.


Once you save this file you should restart your networking service.

sudo /etc/init.d/networking restart


sudo service networking restart

As you can see setting up a static IP address in Ubuntu is pretty straight forward!

If you have any issues setting up a static IP please comment here or make a post on our forums.

About Tyler Bailey

Tyler Bailey is a university student who owns and runs draalin.com
  • Jordan Angelucci

    I have two dns servers and I don’t know how to write them in!

    • draalin

      I believe you can just write them right after each other on the same line like this:



    I did your steps, but, my internet connection failed. I don’t know what it was wrong.

    • draalin

      Are you sure you are using the right IP address for your default gateway? Most home routers are either or by default.

      You have to change the IP scheme depending on what yours is.

  • Andy

    sudo service networking restart

    Always gives me:

    stop: Unknown instance:
    networking stop/waiting

    Everything works… but it would be nice to know why I’m getting that message – and to fix it would be even better. This has always been the case, even when I was using dhcp, so it’s not specific to your suggested changes.

    • http://draalinhome.com/ Tyler Bailey

      I’m not sure exactly why you are getting that error. I usually run it like this:

      sudo /etc/init.d/networking restart

      Maybe it has something to do with what controls “service”?

  • Er Anuj Sharma

    i entered all the entries correctly but still it is not able to ping my gateway please help me on this…..

  • Bill May

    Wrong wrong wrong. Way to mess up a person’s internet connection idiot. Do NOT listen to this person’s instructions. They’re completely wrong.

Hi There!

If this content helped you in anyway please share it, we really appreciate it.

Don't forget to subscribe

If you would like to be informed of our new posts please subscribe!