Linux Crumbs

How To and Why Set Up a Static IP Address on GNU/Linux


This tutorial explains what a static IP address is, and why to use one. It also outlines how to set up a static IP address on GNU/Linux.

The steps in this tutorial have been tested on kubuntu 12.04, mythbuntu 12.04, and mythbuntu 14.04, and should work with many other GNU/Linux distributions.

This tutorial assumes that your computer is on a private home network that is connected to the Internet via a router.


What is a Static IP Address?

A static Internet Protocol Address (IP address) is a fixed location at which a computer can be contacted on a network.

This fixed location must be unique on the network so that network traffic meant for the computer is sent only to that computer. This is similar to the way your home address is unique, so that your postal mail is delivered only to your home address.

Why Use a Static IP Address?

A static IP address is needed when a computer is to provide a service to other computers. Examples of services are a web page server, a MythTV backend server, and a calendar and address server.

In order for other computers to reliably contact the service on the computer, the computer must have a unique static (unchanging) IP address.

Advantages of a static IP address are:

  • Can provide services for other computers because computer is accessible at a known, unchanging IP address
  • Faster boot because no time spent waiting for a dynamic IP address

Disadvantages of a static IP address are:

  • More difficult to move computer to other networks because the computer network configuration will require changing
  • Requires more knowledge of networking to support

If other computers do not rely on services from your computer, or you often move your computer and use it on different networks, then staying with a dynamically assigned IP address is probably best.

Acquiring Network Information

Before we can set up a static IP address, we need to determine some information about your computer and the network to which the computer is connected.

The items that we will need to set up a static IP address are:

  • Network interface name
  • Network your computer is on
  • Gateway address
  • Network mask
  • Broadcast address
  • A range of addresses set aside for static IP addresses

Fortunately much of this information can be readily determined.

  1. Open a terminal window.

    In the K Desktop Environment (kubuntu) use menu option: K -> System -> Konsole (Terminal)

    In XFCE (mythbuntu) use menu option: Applications -> System -> Xfce Terminal

    TIP:   Opening a terminal in other desktop environments

    You can often open a terminal window using the following steps:

    a) Press Alt+F2 to open a run command prompt
    b) Enter "xterm" without the quotes

  2. Enter the network routing information command.

    sudo netstat -rn

    Following is a sample of output from this command:
    Kernel IP routing table
    Destination Gateway Genmask Flags MSS Window irtt Iface UG 0 0 0 eth0 U 0 0 0 eth0 U 0 0 0 eth0

  3. Determine the required networking details.

    From the netstat -rn output we can learn the following:

    eth0 - network interface name - gateway address and address to use for Domain Name Server address (same as home router IP address) - network provided by the home router (the first three numbers match the gateway) - network mask (a class C network for up to 254 devices) - broadcast address (replace the last 0 in the network with a 255)

    The above values are colour coded to help later when placing these values in the network interfaces file.

    TIP:   Other Private Class C Networks

    Private class C networks start with 192.168. Many home routers commonly use 192.168.1.x addresses, but values from 0 to 254 can be used (not just 1).

    For example is a valid class C network address on the private network

  4. Choose a static IP address.

    To learn the range of IP addresses set aside by the router for static IP addresses, refer to your router documentation or login to your home router to check these settings. In general these are IP address outside of the range that is dynamically assigned by your home router.

    From my experience with Linksys and D-Link routers, addresses with a last number of 51 to 64 have been outside the range of dynamically assigned addresses and are safe to use as a static IP address.

    Choose a number that will be unique on your network (no two computers can use the same IP address).

    For example, I chose the following static IP addresses for two different computers on my home network. - My desktop computer - My MythTV personal video recorder

Setting Up Static IP Address

We are now ready to set up the static IP address on the computer. For this example I used the network information determined above and the following IP address: - static IP address.

  1. Create a backup of your existing network configuration.

    In a terminal window, enter the following commands:

    cd /etc/network
    sudo cp -p interfaces interfaces.backup

  2. Edit the /etc/network/interfaces file to define a static IP address.

    TIP:   Use any text editor you prefer.

    Many text editors are available.

    kate is commonly used with KDE desktops
    gedit is often used on GNOME desktops
    leafpad is a graphical editor I install and use on XFCE desktops
    nano is an editor often available on all GNU/Linux distributions.

    Edit the file with a command similar to the following:

    sudo nano /etc/network/interfaces

    and make the content like the following lines.

    Remember to replace the values with the ones you determined above.

    ---------- begin /etc/network/interfaces ----------
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    # The loopback network interface
    # Note:  These two lines are the only lines needed for a
    #        dynamically assigned (DHCP) IP address.
    auto lo
    iface lo inet loopback
    # The primary network interface
    auto eth0
    iface eth0 inet static
    metric 0

    ---------- end /etc/network/interfaces ----------

    Save file and exit editor.

  3. Release the current IP address from the network interface.

    sudo ip addr flush eth0

  4. Restart the networking service.

    Either use one of the following commands or reboot:

    sudo /etc/init.d/networking restart


    sudo systemctl restart networking.service

  5. Verify the IP address is correct.

    sudo ifconfig eth0

    Following is a sample of output from this command:
     eth0     Link encap:Ethernet  HWaddr bc:ae:c5:e1:4b:f1
              inet addr:  Bcast:  Mask:
              inet6 addr: fe80::beae:c5ff:fee1:4bf1/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:54384 errors:0 dropped:0 overruns:0 frame:0
              TX packets:32697 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:77236077 (77.2 MB)  TX bytes:2463869 (2.4 MB)
  6. Test you can access the Internet.

    In a terminal window enter:


    Use CTRL+C to cancel the ping commmand.

    Sample output follows:
    PING ( 56(84) bytes of data.
    64 bytes from ( icmp_req=1 ttl=46 time=95.3 ms
    64 bytes from ( icmp_req=2 ttl=46 time=94.9 ms
    --- ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1001ms
    rtt min/avg/max/mdev = 94.974/95.164/95.355/0.362 ms

    NOTE:   Cannot ping the google server?

    If the ping command cannot contact the google server and indicates packet loss, then something is wrong with the network configuration.

    If you are unable to resolve the problem, you can restore the backup you made earlier in /etc/network/interfaces.backup and reboot to return to your previous network configuration.


While setting up a static IP address, I found the following references useful:

Medusa Deception novel on sale now
News   Documentation     Copyright (c) 2013-2018 Curtis Gedak

Get GParted at Fast, secure and Free
	Open Source software downloads Valid HTML 4.01! Correct CSS! Privacy policy