Skip to content
Chandan Kumar

Static IP on Ubuntu

ubuntu, network, linux1 min read

I tried these steps on Ubuntu 12.04. It may differ for other Linux versions.

Introduction

Sometimes you may want to setup OS instances with static ip. Doing this on Ubuntu is quite simple. Static IP implies that IP address of the machine does not change. Everytime you bootup you have same IP address associated. When you assign static IP to any machine, make sure that you select an IP that is not assigned to any other machine. You may run in to network issues if two machines have same IP address.

How you do this on Ubuntu?

Before you start making these changes make sure that you take a backup of your existing config For example

cp /etc/network/interfaces ~/interfaces.bak

Copy interfaces file to your home folder.

You would need to modify /etc/network/interfaces file, after setting up static ip it would look something like below after changes

1# This file describes the network interfaces available on your system
2# and how to activate them. For more information, see interfaces(5).
3# The loopback network interface
4auto lo
5iface lo inet loopback
6# The primary network interface
7iface eth0 inet static
8 address 192.168.1.151
9 netmask 255.255.255.0
10 gateway 192.168.1.1

Here it is assumed that you are on a network in range of 192.168.1.xxxx and you are setting static ip of 192.168.1.151. You can use whatever value fits your need

Once you are done making changes restart network.

1sudo /etc/init.d/networking restart

Verify this using ifconfig. IP address should be what you have assigned in the interfaces file. If it is not the case, check for typos.

At this point of time you may not be able to connect to any server out of your network. You can verify this by pinging. For example

1ping google.com

Most probably /etc/resolve.conf file may not have nameserver verify this by

1sudo cat /etc/resolv.conf

To fix this on Ubuntu 12.04 you would need to modify /etc/resolvconf/resolv.conf.d/base and add name server entry

1nameserver 8.8.8.8

You can replace 8.8.8.8 with nameserver address of your choice.

More info on setting up name server.

Comments

Copyleft. WTH
Theme by LekoArts