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

$ 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

 

 

Reference:

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

Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s