Setting up a static ip on ubuntu

Posted on 2009-04-16
Last Modified: 2013-11-15
I am fairly new to ubuntu and this is the first time I have had a bash installing a server.  I managed to install apache, mysql, phpadmin etc. successfully and I get the lovely "it works!" message when I go to localhost through my web browser in gnome.  

bAt the momment though the system is set to dhcp and I am aware I need it to have a static lan ip address so I can forward to it from my router which is using "dyndns" to link my dynamic ip to a domain name.

So...How do I set ubuntu to use a static IP instead of dhcp?  And what should I set my "IP address", "Subnet mask" and "Gateway address" to?

(This has ended up being a bit of a long question, ut i being new on ubuntu i wasn't sure what information would be needed, so I put in everything i could think of)
Question by:Susurrus
    LVL 35

    Expert Comment

    If this is a private network, you may not even have to reconfigure your settings. In my router, under Network > Devices and Users I'm able to edit a connected device and have it given the same IP whenever connecting.

    If your router will not do this, here are some HowTos for the reconfiguration:

    As to your questions:
    Use the IP address, Subnet and Broadcast currently in use. You will see them when issuing the "ifconfig" command.
    Your Gateway will be the network IP address of your router. It will also most likely be set as nameserver in your /etc/resolv.conf, so leave this file and nameserver settings as they are.
    Check your router's interface for more information about your network settings if needed, and adopt defaults from the tutorials in cases of doubt.

    Good luck.
    LVL 35

    Expert Comment

    I just saw that the second HowTo goes into a lot of things that are not needed for a simple DHCP -> Static reconfiguration.
    Ignore them, and follow the first one compared with this:

    Author Comment

    When I print ifconfig i get this:

    eth0      Link encap:Ethernet  HWaddr 00:11:d8:0c:aa:67  
              inet addr:  Bcast:  Mask:
              inet6 addr: fe80::211:d8ff:fe0c:aa67/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:46038 errors:0 dropped:0 overruns:0 frame:0
              TX packets:27902 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:59725040 (56.9 MB)  TX bytes:2666409 (2.5 MB)

    eth1      Link encap:Ethernet  HWaddr 00:0a:cd:0c:15:70  
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
              Interrupt:16 Base address:0xb000

    lo        Link encap:Local Loopback  
              inet addr:  Mask:
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:1854 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1854 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:100777 (98.4 KB)  TX bytes:100777 (98.4 KB)

    My connection is on eth0 but I am not sure which line contains the information I need
    LVL 1

    Assisted Solution

    edit your


    iface eth0 inet static

    address (machine ip)
    netmask (machine ip mask)
    gateway (your gateway ip)
    broadcast (your broadcat ip)
    network (your network ip)


    LVL 35

    Expert Comment

    "inet addr:  Bcast:  Mask:"

    inet addr: your IP
    Bcast: your broadcast IP
    Mask: your netmask
    LVL 35

    Accepted Solution

    For your Network IP, replace the "255" in your Broadcast IP by a "0", i.e.:

    Author Comment

    thanks!  I got there in the end.  This is proving to bee a steep learning curve

    Author Closing Comment

    Sorted me out completey.  Thanks!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
    If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now