GNU/Linux Network Configuration Adding IP to an interface


Example

An IP address to an interface could be obtained via DHCP or Static assignment


DHCP If you are connected to a network with a DHCP server running, dhclient command can get an IP address for your interface

$ dhclient <interface>

or alternatively, you could make a change to the /etc/network/interfaces file for the interface to be brought up on boot and obtain DHCP IP

auto eth0
iface eth0 inet dhcp

Static configuration(Permanent Change) using /etc/network/interfaces file

If you want to statically configure the interface settings(permanent change), you could do so in the /etc/network/interfaces file.

Example:

auto eth0 # Bring up the interface on boot
iface eth0 inet static 
    address 10.10.70.10
    netmask 255.255.0.0
    gateway 10.10.1.1
    dns-nameservers 10.10.1.20
    dns-nameservers 10.10.1.30

These changes persist even after system reboot.


Static configuration(Temporary change) using ifconfig utility

A static IP address could be added to an interface using the ifconfig utility as follows

$ ifconfig <interface> <ip-address>/<mask> up

Example:

$ ifconfig eth0 10.10.50.100/16 up