How to Setup Static or Dynamic IP Addresses on Debian based Linux Systems

I know that the internet is full of articles teaching you how to configure your network interface with static or dynamic IP addresses, but I promise that this article is as short as it can be and very good.

I decided to make a simple and short guide on how to setup a static or dynamic IP adress on Debian based Systems, such as: Ubuntu, Debian, Knoppix, Damn Small Linux, Linux Mint, Sparky Linux, Elive, Descent OS, Solus OS, Snow Linux, Crunchbag, etc (trust me, distrowatch knows many others Debian/Ubuntu based Linux distributions)

To make network configurations, you have to open (as root or with sudo) the /etc/network/interfaces file a text editor.

$ sudo vim /etc/network/interfaces

Set a dynamic IP address:

This is how a network having an dynamic IP address (got from a dhcp server) is configured.

auto eth0
iface eth0 inet dhcp

Explanations:

  • auto eth0 – enable at startup the eth0 interface
  • iface eth0 inet dhcp – consider that iface eth0 comes from interface eth0, inet tells you that the network configuration is IPv4 and dhcp that the dynamic ip is assigned by a dhcp server.

Set a static IP address

We have a little more work to do for configurationg a network interface with a static IP address. Edit your /etc/network/interfaces file again, so that it looks like this (these are my IP addresses, replace them with yours.) :

auto eth0
iface eth0 inet static
address 192.168.10.5
netmask 255.255.255.0
network 192.168.10.0
broadcast 192.168.10.255
gateway 192.168.10.1

Explanation:

  • auto eth0 – enable at startup the eth0 interface
  • iface eth0 inet static– consider that iface eth0 comes from interface eth0, inet tells you that the network configuration is IPv4 and static that your network interface has static ip adresses.
  • address – the network’s IP address
  • netmask – the network’s mask address
  • network – the network’s address
  • broadcast – the broadcast address
  • gateway – the gateway address

It is not necesarry to insert the network and broadcast lines in the /etc/network/interfaces file because the system calculates them from the address and the netmask fields.

So, your network interface file could also look like this, for static IP configurations:

auto eth0
iface eth0 inet static
address 192.168.10.5
netmask 255.255.255.0
gateway 192.168.10.1

Set the network’s DNS server:

To set the DNS server address, you have to edit the /etc/resolv.conf file, with root priviledges:

$ sudo vim /etc/resolv.conf

The /etc/resolv.conf file, should look like this:

name server 8.8.8.8

8.8.8.8 is Google’s private DNS address. You can replace 8.8.8.8 with another DNS address, but everything works perfect with the Google DNS.

Reboot the networking service:

All the configurations that are made in configuration files, are persistent. They don’t apply before you reboot the service, but they will not be discarded after reboot. This is how you reboot the network service, to apply the changes:

$ sudo /etc/init.d/networking restart

Share and Enjoy

  • Twitter
  • Facebook
  • Google Plus
  • Email
  • RSS
Tagged with: , , , , , , , , , , , , , , ,
Posted in The Linux and Unix Articles!
3 comments on “How to Setup Static or Dynamic IP Addresses on Debian based Linux Systems
  1. David says:

    Nice article, thanks ;

    in Set a static IP address:Explanation:second line – iface eth0 inet dhcp > iface eth0 inet static

  2. Ben says:

    You say it’s easy and short….
    But after reading a few guides, I still don’t really understand the part where you (or other guides) state ‘replace these values with your own’ and then proceed to punch in a list of meaningless numbers…

    address 192.168.10.5

    netmask 255.255.255.0

    network 192.168.10.0

    broadcast 192.168.10.255

    gateway 192.168.10.1

    WTF??? You assume I know these already, why would I need a guide?

    • Geekster says:

      “We have a little more work to do for configurationg a network interface with a static IP address. Edit your /etc/network/interfaces file again, so that it looks like this (these are my IP addresses, replace them with yours.) :”

      (these are my IP addresses, replace them with yours.)
      (these are my IP addresses, replace them with yours.)
      (these are my IP addresses, replace them with yours.)

      This was written before, but how I have colored it in red!

Leave a Reply

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

*