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

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.