How to Configure Network with static and dhcp in Linux.

A static ip is an IP address that configured for a device instead of one provided by a DHCP server,called static because it does not change or a dynamic IP address which does change.Static IP addresses is mostly used to eliminate the network traffic associated with DHCP/DNS.

A dynamic IP address is automatically assigned to each connection, or of a network like laptop or phone.A DHCP server provide IP address,called dynamic because it will be different connections to the network.


Start,Enable & Stop Network Manager

systemctl start network-manager
systemctl enable network-manager
systemctl stop network-manager

Check supported interface.

ifconfig -a

Check status of the interface.

ifconfig eth0

Setup DHCP using CLI

echo “iface eth0 inet dhcp” >>/etc/network/interfaces

To bring up network Interface.

ifconfig eth0 up
ifup eth0

To setup static IP, subnet mask, broadcast address.

ifconfig eth0 ip-address
ifconfig eth0 netmask subnet-mask
ifconfig eth0 broadcast broadcast-ip-address

Check the IP address,netmask & broadcast ip address.

ifconfig eth0

Here is the command output.

Fig 2

We need to setup Gateway address for the interface.Add default Gateway route to eth0.

route add default gw gateway-ip-address eth0

Check the configure

route -n

Here is the command output.

Fig 2

Another way to setup static ip in DHCP network.

echo -e “iface eth0 inet dhcp\n address ip-address\n netmask subnet-mask\n gateway

If network interface is not up so we needs to bring up.

ifconfig eth0 up
ifup eth0

Now we can using ping command to check network connection.

ping ip-address

Setup nameserver / DNS.If we are getting a DNS error than we needs to assign DNS servers manually.

echo “nameserver server-dns-ip\n nameserver another-server-dns-ip″ >>/etc/resolv.conf

example: echo “nameserver\n nameserver″ >>/etc/resolv.conf



Leave a Reply