Configure IP address on Ubuntu Linux from CLI

Configure IP address on Ubuntu Linux from CLI

Suppose we need to configure following IPv4 paratmeters:

IP address:

First we need to identify our interface. Parameter “-a” command will show all interfaces even if they are down.

ifconfig -a

We will use interface ens160. Ip configurations needs to be done with super user privilages. Following command will set Ip and netmask:

sudo ifconfig eth1 netmask broadcast

Short form of the command could also be used. But it will set the default mask for the IPv4 address class which is for A class IP address. In our case we useĀ  C class mask –

sudo ifconfig ens160

To set default gateway use following command:

sudo route add default gw

If you need to static route to some network( that is not reachable throught gateway this can be done as follows:

sudo route add -net netmask gw

To check routing table use following command. Option “-n” will display routes in numeric format.

netstat -rn
Comments are closed.