How to a Set Static IP in Ubuntu

Some recent changes to Ubuntu have changed the way we set a static IP in Ubuntu 12.04 and 12.10. Previously we could change the /etc/resolv.conf file adding in our static IP details. But due to some internal changes I’m finding it more stable to make changes in the graphical interface…. nm-connection-editor, as these new changes are overwriting the file with some generated content.

UPDATE: I have written some instructions on how to set a static IP in a more ‘Linux’ fashion. Check them out here (for wired connections only)

What do I need to set up a static IP?

You need to add some details which you may not know of the top of your head:

  • Your chosen IP
  • Netmask
  • Gateway
  • DNS Server

Where can I find these details?

Your chosen IP

Your router will most likely have a reserved range of IPs for static use, every domestic router I’ve used has reserved 100 – 200 (though you may have to check your router manual if you find its not).

Netmask, Gateway and DNS Server

Enter the following command in a terminal

nm-tool

The output will list the details of your network interfaces, wireless and wired. In the section of the [Wired] interface there are some IPv4 Settings that will look something like below:

IPv4 Settings:
    Address:         192.168.1.67
    Prefix:          24 (255.255.255.0)
    Gateway:         192.168.1.254

    DNS:             192.168.1.254
  • Address – current IP address
  • Prefix – the address inside the brackets is the netmask
  • Gateway – this is the gateway, otherwise known as the default gateway
  • DNS – is your current DNS server

Setting the Static IP

To the set the static IP run this command in a terminal:

nm-connection-editor

Ubuntu 12.04 Static IP - Netword Connections

This will open the graphical network manager as seen below. If you have more than one connection, select the one you want to apply the static IP to, then click Edit.

This will open the Editing Wired dialog. It is in this box that we need to enter the information we found earlier. In the box below you can see my default settings before applying my static IP. Each of the values can be edited by clicking on them.

Ubuntu 12.04 Static IP - Editing Wired Connections

I’ve applied my changes, clicked save, nothing has changed?

Easy answer: Restart your computer
My answer: Enter the following few commands without the need to restart We need to restart some networking services to make sure we are using the most recent settings:

sudo service resolvconf restart
sudo service networking restart

If restarting these services has no effect go ahead and try a restart.

Now try the following again to make sure your changes are in effect:

nm-tool

The output should reflect the static IP settings we retrieved earlier.

Hope this post helps you guys, any questions….. you know what to do.

  • Andrei Tanasuca

    I know it is a bit offtopic but i would like to know if you have a solution for nm-applet to startup for other than main account.
    Do you think a .dmrc file is the answer and controlling the session with session?

    Thank you

    • http://www.sudo-juice.com/ Gareth Parmar

      Weird problem, I’ve noticed this has randomly disappeared for a few people. What version of Linux are you using? and which desktop environment? When you run ‘nm-applet’ in a terminal does it appear in your notification area?

      • http://www.facebook.com/andreitanasuca Andrei Tanasuca

        I think a “nm-online” solution will do the trick.
        Thank you for your answer

  • http://ludovicurbain.blogspot.be/ Ludovic Urbain

    Well, my conclusion is ubuntu is a piece of shit. No fucking way a distrib has any right to replace the use of /etc/network/interfaces . I’m shocked and disgusted, won’t buy again.

    • http://www.sudo-juice.com/ Gareth Parmar

      I do kind of agree, one of my attractions in the first place was the ability to customize it like this, now they want to stop this! The other reason was because it was quite lightweight, which is also becoming an issue!

    • John

      You can turn it off. In /etc/NetworkManager/NetworkManager.conf set managed=true. Then proceed with interfaces resolv.conf etc.

      • http://www.sudo-juice.com/ Gareth Parmar

        Great stuff, defo worth noting!

      • http://ludovicurbain.blogspot.be/ Ludovic Urbain

        Sure. I can also just put ubuntu in the trash and not have to turn off a dozen dozen useless tools.

  • Brian

    Each time I switch to manual configuration, the save button “grays out” and I can’t save anything. Anyone have this happen?

    • me

      yes. I had this exact problem. I fixed it by editng /etc/network/interfaces .. and rebooting.

  • http://www.facebook.com/profile.php?id=767031456 Brendan White

    worked a charm – thanks dude.

  • rtalcott

    Thank you!

  • http://twitter.com/ACBoros A C Boros

    I’m having a heck of a time getting a static IP set on a new Ubuntu 12.04 LTS server. I’ve done what you said in this article but, it isn’t working. When I try to run the sudo service networking restart command, I get the wait/stop response but, not a restart.

    I’ve rebooted and that hasn’t helped either.

    If I try to edit the NetworkManage.conf file, to change the manage false to true, I cannot save the file.

    If I click on Connection Information (Ubuntu Desktop GUI) I get an error, “Error displaying connection Information. No valid active connections found.” I still have access to the Internet.

    Any thoughts on where to go from here are welcome. I’ve been struggling with this on and off for several days now.

  • OMAR OROZCO

    Thanks!! I was fighting with the /etc/network/interfaces, but even when I managed to get static IP, I lost my internet access !!! but with your method everything is OK

  • H Gudsen

    After fighting with network/interfaces I found this post and it worked for me. But does someone know how to do the same from command line? I have a server that might be upgraded to 13.04, so I’d like to know how to solve the problem not having access to X.

  • http://www.facebook.com/daren.humphries.90 Daren Humphries

    Great guide! It seems like Ubuntu is alot easier to port forward than windows… at least that’s my opinion. Thanks!

  • Dennis Blewett

    Worked great. I needed the DNS information, which I was not putting in the graphical NetworkManager. Riddle solved. Case closed.

  • Pingback: Internet over wireless while connected to a LAN network

  • CommanderMan0

    This was super helpful, thank you!