Change Ubuntu System from DHCP to a Static IP Address

Sponsored Link
If Your Ubuntu System has set to use DHCP, you will want to change it to a static IP address here is simple tip

open the /etc/network/interfaces file.

sudo vi /etc/network/interfaces

If you are using DHCP for your primary network card which is usually eth0, you will see the following lines

auto eth0
iface eth0 inet dhcp

As you can see, it’s using DHCP right now. We are going to change dhcp to static, and then there are a number of options that should add and here is the example and you can change these settings according to your network settings.

auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

Restart the neworking service using the following command

sudo /etc/init.d/networking restart

You may also like...

40 Responses

  1. jj says:

    You can also view (and change) your connection w/ ifconfig. See man pages for options. ifconfig will provide current detail about your eth0 NIC before changing.

  2. 5h4rk says:

    What if I have network-manager installed (everything is commented out in /etc/network/interfaces except lo)

    How can I set up a static IP?

    Thanks

  3. admin says:

    This is a known problem right now with wireless/wired connections. You can read more about the coming solution for Feisty here: https://wiki.ubuntu.com/NetworkRoaming

  4. alixta says:

    if you use nano then you should include the -w option so the first line does not auto wrap & thus cause errors on restart.

  5. marco says:

    Hi,

    I have installed ubuntu server 7 on my box and connected to my router speedport 5020. As long as I use dhcp client, the connection to the internet works fine.
    I would like to use the box as file server with ssh, so I need a static address to it.
    The router assignes by dhcp 192.168.2.100 – 192.168.2.197, so I gave to my box the static address ending .198

    I edited my /interfaces and it looks like this
    #######################
    auto lo
    iface lo inet loopback
    auto eth0
    iface eth0 inet static
    address 192.168.2.198
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.2.255
    gateway 192.168.2.1
    ######################

    moreover I have for my resolv.conf

    ################################
    search Speedport_W_502V_Typ_A
    nameserver 192.168.2.1
    ################################

    anyway I cannot ping the ouside world, and from computers in the same network I cannot ping mx box.

    if I ping from my box a computer in the network I get “Destination host unreachable”

    It seems to me that I have done everything as in the instructions above. Does anybody any Idea of what can be wrong ?
    I am quite a beginner so I am compeltely lost …

    Regards

    Marco

  6. Joe says:

    How can I find out my own credentials to replace the address and broadcast?

  7. Joe says:

    nvm… figured it out.

  8. mike says:

    I really need help
    after changing my IP setting
    sudo /etc/init.d/networking restart just doen’t work

    Please advise

  9. Tauxz says:

    I really need help
    after changing my IP settings

    how to i save and restart.

    i tried using
    sudo /etc/init.d/networking restart but it does not restart

    pls advice me if i doing the right thing…

  10. JAM says:

    Thanks for this!
    Worked a treat πŸ˜€

    JAM

  11. Raja says:

    Documentation is good

  12. runswithscissors says:

    if you’re having problems with
    sudo vi /etc/network/interfaces
    try
    sudo nano /etc/network/interfaces

  13. Cesco says:

    I need to set a internet static ip on ubuntu. Unfortunately, my connection pass by a router that have a public ip on internet. when i set public static ip, y ubuntu computer can’t go on internet. What’s the way to resolve? Thnx

  14. admin says:

    @Cesco

    you need to make sure which DNS servers you are using in your ubuntu system

    you need to edit the following file

    sudo nano /etc/resolve.conf you need to add your isp DNS servers with the following syntax

    nameserver X.X.X.X
    nameserver X.X.X.X

    X.X.X.X – Your ISP DNS servers

    save and exit the file

  15. Cesco says:

    I’m at the start point! I’m connected with wlan0 interface configurated with an internal ip, and wlan0:0 configurated with an external ip. But network is unrecheable. πŸ™

  16. Jess says:

    Hi, I’m trying to set up a static IP to get Azureus working properly

    Using sudo nano /etc/network/interfaces

    I added the following to my /etc/network/interfaces:

    auto lo
    iface lo inet loopback
    auto wlan0
    iface wlan0 inet static
    adress 192.168.2.200
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.2.255
    gateway 192.168.2.1

    then restart using

    sudo /etc/init.d/networking restart

    During this process it gives me the following:

    * Reconfiguring network interfaces…
    Don’t seem to be have all the variables for wlan0/inet.
    Failed to bring up wlan0.

    I don’t understand what variables are missing…
    I tried the same configuration with eth0 and it gives me a similar message

    Thanks in advance to anyone who could shed some light on this problem

    Jess

  17. Jess says:

    Hi again, I came across an alternative solution!

    Just use Wicd instead of network manager, as network manager doesn’t support static IPs.

    To get Wicd just follow the instructions here

    Hope that helps

    Jess

  18. Drew says:

    Jess – in your config you’ve mispelt address “adress”. perhaps this is the source of yur original problem

  19. dodo says:

    hi i tried to fix my connection that way but i didnt succed .. i tried in kde 2.4 im newbie .. please help i put the ip netmask gateway and dns corectly but does not connect .. what should i do next .:( i tried modify that document .. but dont work .. please help .. and please email me whit some answers

  20. dodo says:

    sorry it was kde 4.2

  21. ulfr says:

    I had some trouble getting the settings to work,
    the error I made was to omit the line “auto eth0”, it is essential!
    The lines network and broadcast can safely be omitted, they are calculated automatically from the address and netmask values.

  22. Leave “auto eth0” but disable it.

    Create a new wired with the MAC from “auto eth0” and all info.

  23. Elliot says:

    awesome. worked a treat! now i’ve got my local server with no conflicts

  24. rdeschene3 says:

    Worth mentioning here is that you can specify the DNS server IP#s from opendns.com in /etc/resolv.conf if you want. Alternately, you could leave the nameserver IP# in /etc/resolv.conf as your router’s IP#, and using static DNS server IP#

    I have found opendns.com’s DNS servers to be much faster than many ISP’s, and my ISP would typically do service on their DNS servers over the weekend and our home router and it would be slow in relaying the changing DNS server IP#s

  25. D1mon says:

    It does not work with wifi DNS router.

  26. BadGirl91 says:

    Your device must coexist with other hardware and applications. ,

  27. ADreamer says:

    I cloned the recipe and tried it… only to find out that I can no longer reach the network. Then I added the lines
    dnsserver X.X.X.X
    to the ones above, and the static IP worked πŸ™‚
    thanks a lot πŸ˜€

  28. Chris says:

    For those struggling with network-manager. Just remove it.

    sudo apt-get remove network-manager

  29. Sean Ellis says:

    Using Wicd was an excellent tip. Lovely little utility. Thanks.

  30. era says:

    Please let me k now after edit the following
    sudo vi /etc/network/interfaces

    how can I save that.
    Please…
    I am a beginner

Leave a Reply

Your email address will not be published. Required fields are marked *