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

draalin-setting-up-a-static-ip-2

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 192.168.1.100 (IP address of what you want your Ubuntu machine to be)
netmask 255.255.255.0
(Default mask which in this case is the default class c subnet)
gateway 192.168.1.1  
(Typically your router’s IP address)
network 192.168.1.0 
(The network that this machine is running on)
broadcast 192.168.1.255
 (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-nameservers 192.168.1.1
 (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 8.8.8.8 or 8.8.4.4 you can easily swap 192.168.1.1 to one of Googles. You can find more information regarding Google Public DNS here.

Here is a screenshot of how it should look below.

draalin-setting-up-a-static-ip-1

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

sudo /etc/init.d/networking restart

or

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. Follow me on
  • 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:

      dns-nameservers 8.8.8.8 8.8.4.4

  • ROMEL

    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 192.168.0.1 or 192.168.1.0 by default.

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

      • Terreurhaas

        most of the home addresses are 192.168.1.* only some use the 0.* namespace in my experience. (Sorry to comment a dead thread, just felt like responding my experiences)

  • 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.

  • Brandon

    Does this work for a school network as well?

    What is the command line to actually change this and configure it?

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

    address 192.168.1.100 (IP address of what you want your Ubuntu machine to be)
    netmask 255.255.255.0 (Default mask which in this case is the default class c subnet)
    gateway 192.168.1.1 (Typically your router’s IP address)
    network 192.168.1.0 (The network that this machine is running on)
    broadcast 192.168.1.255 (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-nameservers 192.168.1.1 (DNS or Domain Name Server used for responding to queries when you are searching for a website)

    Thanks

  • Pingback: Setting up ubuntu server 14.01 with LAMP for WordPress | 3am Coder()