Saturday, 21 November 2009

Install and Configure quickly a DHCP Server

NOTE: These commands have been tested in Debian version unstable.

DHCP stands for Dynamick Host Configuration Protocol. This protocol allows to automatically obtain an IP address and set the network configuration.

We install a DHCP server:
#aptitude install dhcp3-server

Next step is configuring the DHCP server:
We have to set correcty the /etc/dhcp3/dhcpd.conf file.

There is a configuration file example at:
/usr/share/doc/dhcp3-server/examples/dhcpd.conf

e.g: I added these lines to my /etc/dhcp3/dhcpd.conf


subnet 192.168.1.0 netmask 255.255.255.252 {
range 192.168.1.2 192.168.1.3;
option routers 192.168.1.1;
option domain-name-servers 212.73.32.3, 212.73.32.67;
}


subnet and netmask indicate the network addresses of our network:
e.g: subnet 192.168.1.0 netmask 255.255.255.252 match 192.168.1.0, 192.168.1.1, 192.168.1.2 and 192.168.1.3 IP addresses.

range means which addresses can be returned by our dhcp server, here, it can return 192.168.1.2 and 192.168.1.3

routers indicates the gateway

domain-name-servers shows all dns addresses separated by commas.


Once we have correctly set dhcpd.conf file we restart the dhcp daemon:
#/etc/init.d/dhcp3-server restart


If everything has gone fine, we will execute in a client computer:
$sudo dhclient eth0

and the dhcp server will associate an IP adress to eth0 interface.

NOTE: dhcp3-client package provides dhclient command.
#aptitude install dhcp3-client

Sunday, 1 November 2009

Shell Script that shows Network Speed

The following shell script shows current download and upload speeds for the network interface you choose.

Copy the shell script in a file named, i.e: net_speed.sh

Then after setting execution permissions:
$ chmod a+x net_speed.sh

You can run the shell script passing as the first argument the network interface you want to monitor:
$ ./net_speed.sh eth0


You will get a line like that:
ppp0 DOWN:15 KB/s UP:880 B/s

This script works parsing /proc/net/dev file and calculating the difference between current transmitted or received bytes and their values one second ago.