Configure basic networking ubuntu 14.04
This tutorial was written for ubuntu 14.04 server but with slight modifications applies to most of modern Linux distributions.
It describes the process of configuring your Linux systems IP address and default gateway from CLI – Command Line Interface.
There are two modes of configuration temporary and permanent. The difference being temporary will not survive reboot.
Temporary network configuration
We can use standard commands such as ip, ifconfig and route,
which are also found on most other GNU/Linux operating systems. These commands allow us to
configure settings which take effect immediately, however they are not persistent and will be lost after
a reboot.
To temporarily configure an IP address, you can use the ifconfig command in the following manner.
sudo ifconfig eth0 192.168.0.22 netmask 255.255.255.0
To verify the IP address configuration of eth0
ifconfig eth0
To configure a default gateway, you can use the route command in the following manner.
sudo route add default gw 192.168.0.1 eth0
To verify your default gateway configuration
route -n
If you require DNS for your temporary network configuration, you can add DNS server IP addresses
in the file /etc/resolv.conf.
If you no longer need this configuration and wish to purge all IP configuration from an interface without rebooting your system then run followinf command
ip addr flush eth0
Permanent network configuration
Dynamic ip
To configure your server to use DHCP for dynamic address assignment, add the dhcp method to the
inet address family statement for the appropriate interface in the file /etc/network/interfaces.
auto eth0 iface eth0 inet dhcp
By adding an interface configuration as shown above, you can manually enable the interface through
the ifup command which initiates the DHCP process via dhclient.
sudo ifup eth0
To manually disable the interface
sudo ifdown eth0
Static ip
To configure your system to use a static IP address assignment, add the static method to the inet
address family statement for the appropriate interface in the file /etc/network/interfaces.
auto eth0 iface eth0 inet static address 192.168.0.24 netmask 255.255.255.0 gateway 192.168.0.1
By adding an interface configuration as shown above, you can manually enable the interface through
the ifup command.
sudo ifup eth0
To manually disable the interface, you can use the ifdown command.
sudo ifdown eth0
We went over basic IP configuration options here , for more detailed options you will need to consult particular distro documentation.