Little Girl's Mostly Linux Blog

StaticIP


Static LAN IP

This page was last updated on October 16, 2011.

Table of Contents

Introduction

  • Impatient? Don’t want to read a bunch of stuff? Get right to it!
  • If you have a home network, it would be a good idea to set up static LAN IP addresses for your devices (computers, printers, etc.).
  • It’s important to choose valid static IP addresses that won’t conflict with your router’s settings.
  • This document hopes to make this easy for you.
  • These instructions are for Ubuntu and Kubuntu. Modifications might be required if used for any other distribution.

How To Use This Document

  • Make sure you meet the requirements in the Requirements section of this document.
  • Refer to the Further Information section for links to some pages on the internet that provide more detailed information than is available here.
  • Refer to the Questions And Answers section for the answers to questions that commonly come up.
  • Refer to the Troubleshooting section if you’ve followed the instructions on this page and you need to figure out why it’s not working.

Requirements

  • One or more computers running Ubuntu or Kubuntu 11.10 or earlier.
  • A hardware router. See the Further Information section of this document for further information on how and why to set up a hardware router.
  • An NIC for each computer or device you will be using on the network, and understanding of what an NIC is. See the Questions and Answers section of this document for an explanation.
  • An understanding of what a LAN is. See the Questions and Answers section.
  • An understanding of what an IP address is. See the Questions and Answers section.
  • An understanding of the ranges for use with Local Area Networks. See the Questions and Answers section.
  • An understanding of DHCP. See the Questions and Answers section.

Choosing A Static LAN IP Address

What you’ll be looking for

When checking your router’s settings, you’ll be looking for the number set you can choose from to assign a valid LAN IP address. The first three sets of numbers (for example: 192.168.1) must not be changed. The final set of numbers after the last period is what you’ll be working with when setting a static LAN IP. For example, the X represents the number set you’ll want to pay close attention to in choosing an IP address:

192.168.1.X

Access the router

Access your router by typing 192.168.1.1 (the router’s LAN IP) into your browser’s address bar and logging in. If your router’s LAN IP differs, check its documentation for instructions.

Check the router settings

Find the section in your router’s configuration that refers to DHCP settings. The addresses used by your router for DHCP will either be displayed by using a starting and ending address or as a range of addresses. For example, both of these routers have reserved 100 through 150 for their own use:

Starting and ending address Starting Address 192.168.1.100
Ending Address 192.168.1.150
Range of addresses Starting Address 192.168.1.100
Number of Addresses: 51

Understanding the router settings

The router has 256 numbers that can be used for IP addresses (0 through 255). As you can see from the examples, the router reserves itself some numbers to use for automatically assigning IP addresses when necessary. It also reserves the number 1 (from 192.168.1.1) for its own IP address, which you use to access the router. Routers commonly reserve 0 and 255 for use by network protocols, so it’s best to simply avoid using those. All of these numbers are not available for you to use for a valid static IP address.

The numbers reserved by the example routers above are:

  • 0
  • 1
  • 100 through 150
  • 255

Choose an IP address

Now that you know which numbers you can’t use, it’s time to choose one from those that are available. The available numbers for the example computer above would be from 2 through 99 and/or 151 through 254. A couple of examples of valid IP addresses would be:

  • 192.168.1.3
  • 192.168.1.155

If you have a stubborn router…

If your router is using 192.168.1.2 through 192.168.1.254, this leaves no valid IP addresses for you to assign as a static IP address. For example:

Starting and ending address Starting Address 192.168.1.2
Ending Address 192.168.1.254
Range of addresses Starting Address 192.168.1.2
Number of Addresses: 253

In both of these examples, the router is using 2 through 254 for DHCP, leaving no addresses for you to use. That’s not very friendly of it, so you might as well battle it.

Battle the stubborn router by freeing some IP addresses…

In this case, you’ll need to change the settings of the router to make some addresses available for yourself. The information you’ll want to change is either the Ending Address or the Number of Addresses, depending on which method your router uses to display the addresses. For example:

Starting and ending address Starting Address 192.168.1.2
Ending Address 192.168.1.200
Range of addresses Starting Address 192.168.1.2
Number of Addresses: 199

Note: You may need to reboot the router for the change to take effect – see the router’s documentation.

Then win the battle by choosing an IP address

In both of these examples, the router is now using 2 through 200 for DHCP. It’s also using 0, 1 and 255 for its own purposes. This leaves 201 through 254 available for you to use. Examples of valid IP addresses for this computer are:

  • 192.168.1.201
  • 192.168.1.250

Assigning a static LAN IP address

Now that you’ve chosen an IP address, you can assign it in Ubuntu or Kubuntu.

  1. Back up the /etc/network/interfaces file:

    • Type this command in a terminal window:
    • sudo cp /etc/network/interfaces /etc/network/interfaces`date +%b-%d-%Y~%T`
    • Press the Enter key.
    • Note: This will create a backup copy of the interfaces file with the current date and time added to the name.

  2. Open the interfaces file in an editor by typing one of these commands:

    • GNOME users
      • Type this command in a terminal window:
      • gksudo gedit /etc/network/interfaces
      • Press the Enter key.

    • KDE users:
      • Type this command in a terminal window:
      • kdesudo kate /etc/network/interfaces
      • Press the Enter key.
  3. Look for the following lines inside the file:
  4. auto eth0
    iface eth0 inet dhcp
    

    Note: eth0 is the default device in Ubuntu. Yours may, for example, be listed as eth1.

  5. Delete the second line, leaving just the first one, so it looks like this example:
  6. auto eth0
  7. Replace the line you deleted with these lines, substituting the IP address you chose for the one in the “address” line in this example:
  8. iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    

    Note: Substitute your router’s IP address for the one used here in the “gateway” line if it differs from the example.

  9. The resulting file should look something like this:
  10. auto lo
    iface lo inet loopback
    address 127.0.0.1
    netmask 255.0.0.0
    
    auto eth0
    iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    
  11. Save the file and exit the editor.
  12. Restart your network in one of these ways:
    • Reboot the computer.
    • Type this command in a terminal window and provide your password when asked:
      sudo service network-manager restart
    • Type this command in a terminal window and provide your password when asked:
      sudo stop network-manager

      Then type this command in a terminal window and provide your password when asked:

      sudo start network-manager

Appendix

Further Information

Questions and Answers

What is an NIC?
NIC stands for Network Interface Card. This is an expansion card that can be inserted into a computer (or which comes as part of the motherboard of a computer) and is used to connect the computer to a network.

What is a LAN?
LAN stands for Local Area Network, which basically means two or more computers or devices connected together locally (in a building or buildings) by hardware and software.

What is an IP address?
Each computer or device on a LAN is assigned a number so that it can be located in the network. This number is known as an IP address. IP addresses in a LAN can be randomly assigned by your router or manually assigned by you.

What are the benefits of using a static LAN IP address?
There are many benefits to using a static LAN IP address, but for the purposes of this document the benefit is that you can define a specific address to each computer or device on your network so that it can always be found at that address. As a result, you can use its address in configuration files once and have it work from then on.

What are the ranges used in Local Area Networks, and why do I need to know this?
There are three IP address ranges for use with Local Area Networks. The first one is the most popular, and is used in the examples in this document. If you use one of the others, please make the appropriate substitutions:
  • 192.168.0.0 through 192.168.255.255
  • 172.16.0.0 through 172.31.255.255
  • 10.0.0.0 through 10.255.255.255
What is DHCP?
DHCP stands for Dynamic Host Configuration Protocol. It’s a network protocol that enables, for the purposes of this document, your router to automatically assign IP addresses.

I have a question that hasn’t been asked here. How do I ask it?
If you use the contact address at the top of this document, you will receive a reply via email and your question may be added to this section.

Troubleshooting

  • Make sure that you meet the requirements in the Requirements section of this document.
  • Make sure you understand the items discussed in the Questions and Answers section of this document and have applied that understanding when following these instructions.
  • If your router’s IP address ranges were different from the one used in the examples, make sure you properly substituted the correct numbers for those used in the examples.
  • Verify that your hardware has been properly installed and is properly connected.
  • If you disabled DHCP in your router as part of setting up a static IP, you’ll need to enable DHCP to connect to the internet if you boot with a Live CD or install a new version of Kubuntu or Ubuntu. Note that enabling DHCP will not interfere with the static IP you set up.
  • If you need further help, see my GettingHelp page.



Obligatory Happy Ending

And they all lived happily ever after. The end.

Back to top

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: WordPress Classic. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.