Showing posts with label static IP. Show all posts
Showing posts with label static IP. Show all posts

Tuesday, April 27, 2010

How to Set a Static IP in Linux Ubuntu Debian

We may require to configute a static IP address in our linux system. It is the easiest if you arterunning Ubuntu / debian distro.

Open up terminal and edit the 'interfaces' file in sudo mode
sudo nano /etc/network/interfaces

You would see the following lines
auto lo
iface lo inet loopback

replace the contents with the following:
auto lo eth0
iface lo inet loopback

iface eth0 inet static
address xxx.xxx.xxx.xxx(your static ip address)
netmask xxx.xxx.xxx.xxx(your network netmask)
gateway xxx.xxx.xxx.xxx(the gateway ip)

Save the file (Ctrl+O) and exit (Ctrl+X)

The ethusually the default network adapter. In a few cases it may be eth1.

I usually also change the nameservers to OpenDNS nameservers
sudo nano /etc/resolv.conf

replacing the contents with:
nameserver 208.67.222.222
nameserver 208.67.220.220

After that it is time to restart networking
sudo /etc/init.d/networking restart

Reboot your PC and check the ip with the command
ifconfig

Friday, October 9, 2009

Configuring Static ip address in Linux (ubuntu/debian)

Like most desktops, mine was connecting to network using DHCP. While it is nice and automatic, it is often clumsy as the ip address (of the Desktop) usually changes after every reboot.

If you have only command-line access, here is a simple way to assign a static ip address (in my case it is 192.168.1.3) to your desktop. Make sure you consult your site administrator before doing that, as ip address and gateway ip address may vary.

There are two files that must be configured /etc/network/interfaces and /etc/resolv.conf.

Open /etc/network/interfaces in your favorite editor (mine being nano).? What you will most likely see is this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp

The last line is what you need to edit (and add to.) To configure eth0 (your network device) for a static IP address that last line should resemble:

iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1


Naturally you will need to change the last three lines to reflect your own networking setup.

Once that file has been edited you can restart your network connection with the command:

sudo /etc/init.d/networking restart

Now Configuring DNS

That file is /etc/resolv.conf. This file is in charge of holding your DNS server addresses. Open this file up in your editor. What you need are two lines:

nameserver 208.67.220.220

nameserver 208.67.222.222