Watch as I awkwardly stumble through life

Ubuntu Linux convert DHCP network configuration to static IP configuration

Posted by Marius Voila on February 08, 2010 in London, U.K . — 0 comments This post contains 549 words

My friend wanted to know how to change or convert DHCP network configuration to static configuration. After initial installation, he wanted to change network settings. Further, his system is w/o GUI system aka X Windows. Here is quick way to accomplish the same:

Your main network configuration file is /etc/network/interfaces

Desired new sample settings: => Host IP address => Netmask: => Network ID: => Broadcast IP: => Gateway/Router IP: => DNS Server:

Open network configuration file

$ sudo vi /etc/network/interfaces


$ sudo nano /etc/network/interfaces

Find and remove dhcp entry:

iface eth0 inet dhcp

Append new network settings:

iface eth0 inet static

Save and close the file. Restart the network:

$ sudo /etc/init.d/networking restart

**Task: Define new DNS servers ** Open /etc/resolv.conf file

$ sudo vi /etc/resolv.conf 

You need to remove old DNS server assigned by DHCP server:


Save and close the file.

Task: Test DNS server

$ host

Network command line cheat sheet

You can also use commands to change settings. Please note that these settings are temporary and not the permanent. Use above method to make network changes permanent or GUI tool as described below.

Task: Display network interface information

$ ifconfig

Take down network interface eth0 / take a network interface down

$ sudo ifconfig eth0 down


$ sudo ifdown eth0 

**Bring a network interface eth0 up **

$ sudo ifconfig eth0 up


$ sudo ifup eth0 

Change IP address and netmask from command line

Activate network interface eth0 with a new IP ( / netmask:

$ sudo ifconfig eth0 netmask up

Display the routing table

$ /sbin/route 


$ /sbin/route -n


Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
localnet        *        U     0      0        0 ra0    *        U     0      0        0 eth0    *        U     0      0        0 eth1
default         UG    0      0        0 ra0

Add a new gateway

$ sudo route add default gw

Display current active Internet connections (servers and established connection)

$ netstat -nat

Display open ports

$ sudo netstat -tulp


$ sudo netstat -tulpn

Display network interfaces stats (RX/TX etc)

$ netstat -i

Display output for active/established connections only

$ netstat -e
$ netstat -te
$ netstat -tue


Test network connectivity

Send ICMP ECHO_REQUEST to network hosts, routers, servers etc with ping command. This verifies connectivity exists between local host and remote network system:

$ ping router
$ ping
$ ping