Monday, May 25, 2009

Setting ip in debian/ubuntu server

To setup ip for debian or ubuntu server is not easy for someone who is not familiar with command line. For normal ubuntu desktop user, there is always NetworkManager applet to easily set up the network using GUI, which is very easy. There are 2 ways to setup ip for debian or ubuntu server. One will set the ip temporarily and the otehr one will permanently set the ip. I will show both :)

To set ip temporarily using ifconfig and route commands

1. Run the command below to set ip and netmask
$ sudo ifconfig eth0 netmask up
where eth0 is the name of the interface, is the netmask and up to activate the interface

2. run route command to set default gateway
$ sudo route add default gw
where is your gateway ip

3. You can check the configuration that you have setup using commands route -n to see the gateway and ifconfig to see the ip address


To permanently set up the ip and gateway, you have to edit /etc/network/interfaces. It is advisable if you backup the existing interfaces file, if it is available.

1. Backup /etc/network/interfaces
$ sudo cp /etc/network/interfaces /etc/network/interfaces.bak

2. Open the /etc/network/interfaces using your favorite text editor
$ sudo vi /etc/network/interfaces

3. Add the below setting to add ip, netmask and gateway

# The loopback interface
auto lo
iface lo inet loopback

# The first network card - this entry was created during the Debian installation
# (network, broadcast and gateway are optional)
auto eth0
iface eth0 inet static
#set your static IP below

#set your default gateway IP here
# set your netmask, network and broadcast ip below

4. Save your configuration and restart network
$ sudo /etc/init.d/network restart

5. Your debian/ubuntu server machine is now operating with the new ip. Check ip and gateway using ifconfig and route -n

No comments: