Posted by: isaraffee | April 10, 2010

Setting IP address on Ubuntu

Setting IP address on Ubuntu

To set a temporary IP address on Ubuntu type

# ifconfig eth0 netmask broadcast up

Verify the network connections.

# ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:16:d3:43:12:02

inet addr: Bcast: Mask:

inet6 addr: fe80::216:d3ff:fe43:1202/64 Scope:Link


<output truncated for brevity>

Test the configuration by pinging its IP address

root@ismail-laptop:~# ping

PING ( 56(84) bytes of data.

64 bytes from icmp_seq=1 ttl=64 time=0.054 ms

64 bytes from icmp_seq=2 ttl=64 time=0.039 ms


— ping statistics —

2 packets transmitted, 2 received, 0% packet loss, time 999ms

rtt min/avg/max/mdev = 0.039/0.046/0.054/0.010 ms

This IP address will be gone once you reboot the machine. To set the IP address permanently follow these steps.

Setting IP address on Ubuntu via Configuration file

If the Ubuntu Server installer has set your server to use DHCP, you will want to change it to a static IP address so that people can actually use it.

Changing this setting without a GUI will require some text editing, but that’s classic linux, right?

Let’s open up the /etc/network/interfaces file. I’m going to use vi, but you can choose a different editor

sudo vi /etc/network/interfaces

For the primary interface, which is usually eth0, you will see these lines:

auto eth0
iface eth0 inet dhcp

As you can see, it’s using DHCP right now. We are going to change dhcp to static, and then there are a number of options that should be added below it. Obviously you’d customize this to your network.

auto eth0
iface eth0 inet static

The auto directive identifies the network interface to be configured, in this case the loopback adapter as noted by the lo label.

Auto lo

Without the auto directive, the specifiied interface is not activated the next time you type the /etc/init.d/networking restart or the ifup -a commands.

iface lo inet loopback

The auto lo directive also need the directive shown above. The iface directuve applies Ipv4 networking as defined by the inet directive (Ipv6 would be configured with inet6), along with the loopback address, to the loopback adapter lo.

If you are using DNS to resolve IP addresses to machine names, you may want to add the DNS server (name servers) by editing the resolv.conf file:

sudo vi /etc/resolv.conf

On the line ‘nameserver’ replace the x with the IP of your name server.

Now we’ll just need to restart the networking components:

sudo /etc/init.d/networking restart


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: