Configure your network card with a static address

Static IP addresses are useful when you never want the IP address to change.  Server’s are commonly configured with a static IP address and not DHCP.  DHCP can decide that one day it wants to change the IP address of your server or computer.  And if you have other computers that rely on that address never changing it will cause user’s to think that the server is down and not working.  In a business enviroment, this can cause all sorts of extra work for anyone in IT.  Other reasons for using static IP’s would be strict control over your network, or maybe your router doesn’t support DHCP.  I won’t go into too many of those details as it would cause me to stray away from the scope of this guide.

So lets see how to set a Static IP Address,

  1. From the command line, open the interfaces configuration file with your favorite text editor (I like to use nano, but you can use which ever you like)
  2. $ sudo nano /etc/network/interfaces
  3. Within nano you will see something similar to the following contents
  4. # 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
    auto lo
    iface lo inet loopback
     
    # The primary network interface
    auto eth0
    iface eth0 inet dhcp
  5. By default Ubuntu configures your network card with DHCP as it is the most common method.  But to set it to static we must remove the lines currently referring to etho.
  6. # 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
    auto lo
    iface lo inet loopback
     
    # The primary network interface
    ***REMOVE THIS LINE*** ---> auto eth0
    ***REMOVE THIS LINE*** ---> iface eth0 inet dhcp
  7. With the two lines removed, linux will not know what to do with your network card so it won’t do anything if we leave it like this.  So lets add our static network configuration so Linux will know what to do with it.
  8. auto eth0
     iface eth0 inet static
     address 192.168.1.100
     gateway 192.168.1.1
     netmask 255.255.255.0
     network 192.168.1.0
     broadcast 192.168.1.255
  9. Now, the important thing to remember here is that this information depends on your network.  If you are unsure of what numbers to enter you should ask.  Whether it be by posting a comment here, I can try to help you figure out what settings you might need.  Or if you are at work, ask someone in your IT department.

    • The wrong information here wont really break anything, but it can definitely prevent your computer/server from connecting and communicating on the network.

    • The numbers I’ve used here are commonly used on most routers.Once you have entered the proper information, save and exit out of your text editor. (Nano save is Ctrl+O exit is Ctrl+X)
  10. Restart the networking service
  11. $ sudo /etc/init.d/networking restart
  12. Test your configuration, see if you can browse the internet, network, ping another computer etc. You should now be happily using your newly configured static IP address

Pages: 1 2 3 4

Tags: