You are on page 1of 7

Configurando un Servidor DHCP (Ubuntu Edgy 6.

10)
10 mayo, 2007 fodsite Deja un comentario Ir a los comentarios DHCP (Dynamic Host Configuration Protocol) es un protocolo de red que asigna direcciones IP de forma automtica a clientes (nodos) de una red LAN, este protocolo es capaz de asignar los parmetros bsicos para que el equipo cliente pueda ser parte de la red en la cual se trabaja, en donde podr por ejemplo conectarse a Internet, recorrer la red LAN, etc. Vamos a configurar un servidor DHCP de manera muy bsica, pero completamente funcional. Lo que haremos ser asignar direcciones IP dentro de un rango determinado, por una cierta cantidad de tiempo, adems se asignarn parmetros como la puerta de enlace y los DNS de la red. Comenzaremos por instalar el servidor:
$ sudo apt-get install dhcp3-server

Esta es la version 3 del servidor DHCP que viene por defecto en Ubuntu y que pertenece al Internet Software Consortium (ISC). Ahora editaremos el archivo de configuracin, pero haciendo un respaldo de l por si tenemos problemas mas adelante:
$ sudo cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.bak $ sudo gedit /etc/dhcp3/dhcpd.conf

Buscamos las siguiente lineas:


# option definitions common to all supported networks... option domain-name "example.com"; option domain-name-servers ns1.example.com, ns2.example.com;

default-lease-time 600; max-lease-time 7200; Y solo debemos comentarlas insertando un # al principio de cada lnea, de tal manera que nos quede:
#option definitions common to all supported networks... #option domain-name "example.com"; #option domain-name-servers ns1.example.com, ns2.example.com;

#default-lease-time 600; #max-lease-time 7200; Ahora viene lo interesante, la configuracion del servidor, para ello supondremos que nuestra red posee los siguiente parmetros: Red: 192.168.1.0 Rango IP: Desde 192.168.1.100 hasta 192.168.1.120 Mascara de Subred: 255.255.255.0 Servidor DNS: 200.54.144.227 Dominio: ejemplo.com Puerta de Enlace: 192.168.1.1

Buscamos las siguientes lneas:


# A slightly different configuration for an internal subnet. # subnet 10.5.5.0 netmask 255.255.255.224 { # range 10.5.5.26 10.5.5.30; # option domain-name-servers ns1.internal.example.org; # option domain-name "internal.example.org"; # option routers 10.5.5.1; # option broadcast-address 10.5.5.31; # default-lease-time 600; # max-lease-time 7200; #}

La modificamos insertando los datos de nuestra red:


subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.120; option domain-name-servers 200.54.144.227; option domain-name "ejemplo.com"; option routers 192.168.1.1; option broadcast-address 192.168.1.255; default-lease-time 600; max-lease-time 14400; }

Los dos ltimos parmetros indican los tiempos de duracin que un cliente podra tener al momento que se le asigna una IP, el tiempo mximo son 14400 segundos, es decir, 4 horas. En algunos archivos de configuracin que he visto de ejemplo, indican un parmetro llamado INTERFACES, en donde se indica la interface de red en la que actuar el DHCP (eth0, eth1, wlan0), en nuestro caso no es necesario ya que el servdor DHCP se da cuenta slo quien esta haciendo las peticiones para usar el DHCP. Ahora solo nos queda guardar el archivo e iniciar el servicio:
$ sudo /etc/init.d/dhcp3-server start

Para ver si el servidor esta trabajando, puedes hacer varias cosas:


$ sudo ps aux $ sudo netstat -uap (buscar si esta bootps).

Por ultimo puedes checkear /var/log/syslog si es que en algun momento ocurrieron errores, por ejemplo, puedes ver las ultimas 100 lineas del syslog:
$ sudo tail -n 100 /var/log/syslog

Ademas en este mismo archivo puedes ver el momento en que se hacen los asignamientos de IP a los clientes. Referencias: http://es.wikipedia.org/wiki/DHCP. http://ubuntuguide.org/wiki/Ubuntu_Edgy#DHCP_Server. http://www.howtoforge.com/dhcp_server_linux_debian_sarge.

How To Set Up A DHCP Server For Your LAN

Version 1.0 Author: Falko Timme <ft [at] falkotimme [dot] com> Last edited 09/20/2006 This tutorial describes how to set up a DHCP server (ISC-DHCP) for your local network. DHCP is short for "Dynamic Host Configuration Protocol", it's a protocol that handles the assignment of IP addresses, subnet masks, default routers, and other IP parameters to client PCs that don't have a static IP address. Such computers try to find a DHCP server in their local network which in turn assigns them an IP address, gateway, etc. so that they can connect to the internet or other computers from the local network. In this short guide I will show how to set up a simple DHCP server (ISC-DHCP) on a Debian Sarge (3.1) system whose sole purpose is to assign IP adresses, a gateway, DNS servers, etc. to client computers from the local network that don't have a static IP address. You can use such a DHCP server in your home network, your office, etc., for example if your router doesn't come with a built-in DHCP server. If you set up such a DHCP server, please make sure you don't already have another one in your LAN as this might result in conflicts. Of course, one can imagine much more complicated DHCP setups, but these are outside the scope of this document. I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 Preliminary Note
This is the current situation:

I'm using the network 192.168.0.0, subnetmask 255.255.255.0, broadcast address 192.168.0.255. My gateway to the internet is 192.168.0.1; on the gateway there's no DHCP server.. My ISP told me the DNS servers I can use are 145.253.2.75 and 193.174.32.18. I have a pool of 30 IP addresses (192.168.0.200 - 192.168.0.229) that can be dynamically assigned to client PCs and that are not already in use.

I have an unused Debian Sarge server with the hostname server1.example.com on the IP address 192.168.0.100 which will act as my DHCP server.

2 Installing The DHCP Server


Now let's install our DHCP server on our Debian Sarge system:

apt-get install dhcp3-server

You will be asked a few questions: On what network interfaces should the DHCP server listen? <-- eth0

Please configure the DHCP server as soon as the installation finishes. <-- Ok The version 3 DHCP server is now non-authoritative by default <-- Ok At the end of the installation you will see errors like these: Generating /etc/default/dhcp3-server... Starting DHCP server: dhcpd3 failed to start - check syslog for diagnostics. invoke-rc.d: initscript dhcp3-server, action "start" failed. That's ok because we did not have the chance yet to configure our DHCP server.

3 Configuring The DHCP Server


Now we must configure our DHCP server. We must tell it from which IP range it should assign IP addresses to requesting clients, which gateway it should assign, which DNS servers, etc. The configuration file for our DHCP server is /etc/dhcp3/dhcpd.conf. Currently it contains a sample configuration which we copy to /etc/dhcp3/dhcpd.conf_orig for future reference:

cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf_orig cat /dev/null > /etc/dhcp3/dhcpd.conf

With the last command we have emptied /etc/dhcp3/dhcpd.conf so that we can place our own configuration in it which we do now:

vi /etc/dhcp3/dhcpd.conf

The file should look like this:

ddns-update-style none; option domain-name-servers 145.253.2.75, 193.174.32.18; default-lease-time 86400; max-lease-time 604800; authoritative; subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.200 192.168.0.229; option subnet-mask 255.255.255.0; option broadcast-address 192.168.0.255; option routers 192.168.0.1; }

I explain the configuration options here:

ddns-update-style: You can tell the DHCP server to update a DNS server if the IP address of a server in your LAN has changed (because it has been assigned a different IP by DHCP). As we do not run servers in our LAN or always give them static IP addresses (which is a good idea for servers...) we don't want to update DNS records so we set this to none.

option domain-name-servers: This tells the DHCP server which DNS servers it should assign to a client. You can specify more than one DNS server here, seperated by commas.

default-lease-time, max-lease-time: A client can tell the DHCP server for how long it would like to get an IP address. If it doesn't do this, the server assigns an IP address for default-lease-time seconds; if it does, the server grants the requested time, but only up to max-lease-time seconds.

authoritative: If this is not set this means that if a client requests an address that the server knows nothing about and the address is incorrect for that network segment, the server will _not_ send a DHCPNAK (which tells the client it should stop using the address.) We don't want this so we set authoritative.

subnet: The subnet to use. netmask: The netmask to use. range: Tells the DHCP server from which range it can assign IP addresses to clients. In our example it's from 192.168.0.200 to 192.168.0.229 (30 IP addresses).

option broadcast-address: The broadcast address to use. option routers: Tells the DHCP server the gateway address it should assign to requesting clients. In our case the gateway is 192.168.0.1.

If you are not sure about your personal network settings (network, netmask, broadcast address, etc.), visit www.subnetmask.info where you can calculate your settings. You see, this is a very simple and basic configuration, but it's enough to make our DHCP server functionable. Now let's start it:

/etc/init.d/dhcp3-server restart

Afterwards you can check the output of

ps aux

to see if DHCP is running. You should also see it in the output of

netstat -uap

which should resemble this one:

Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 *:bootps *:* 2185/dhcpd3 udp 0 0 *:868 *:* 1964/rpc.statd udp 0 0 *:871 *:* 1964/rpc.statd udp 0 0 *:sunrpc *:* 1553/portmap
You can see that DHCP is running on the bootps UDP port which translates to port 67 UDP (run

grep bootps /etc/services

and you will see that bootps means port 67). Finally you can check /var/log/syslog if any errors occurred during the DHCP server start. To see the last 100 lines of /var/log/syslog, for example, run

tail -n 100 /var/log/syslog

4 How Can I See That My DHCP Server Is Working OK?


To see if your DHCP server is working as expected, boot another PC (Windows, Linux, MAC, ...) in your LAN that doesn't have a static IP address. Wait a few seconds, and in /var/log/syslog on the DHCP server you should see that the DHCP server assigns an IP address to your PC. For example, in this excerpt of /var/log/syslog, a client PC named matze has been assigned the IP address 192.168.0.229: Sep 19 16:01:26 server1 dhcpd: DHCPDISCOVER from 00:0c:76:8b:c4:16 via eth0 Sep 19 16:01:26 server1 dhcpd: DHCPOFFER on 192.168.0.229 to 00:0c:76:8b:c4:16 (matze) via eth0 Sep 19 16:01:27 server1 dhcpd: DHCPDISCOVER from 00:0c:76:8b:c4:16 (matze) via eth0 Sep 19 16:01:27 server1 dhcpd: DHCPOFFER on 192.168.0.229 to 00:0c:76:8b:c4:16 (matze) via eth0 Sep 19 16:01:31 server1 dhcpd: DHCPDISCOVER from 00:0c:76:8b:c4:16 (matze) via eth0 Sep 19 16:01:31 server1 dhcpd: DHCPOFFER on 192.168.0.229 to 00:0c:76:8b:c4:16 (matze) via eth0 Sep 19 16:01:31 server1 dhcpd: Wrote 1 leases to leases file. Sep 19 16:01:31 server1 dhcpd: DHCPREQUEST for 192.168.0.229 (192.168.0.100) from 00:0c:76:8b:c4:16 (matze) via eth0 Sep 19 16:01:31 server1 dhcpd: DHCPACK on 192.168.0.229 to 00:0c:76:8b:c4:16 (matze) via eth0

The DHCP server writes all current IP address "leases" to the file /var/lib/dhcp3/dhcpd.leases so you should also find the lease there:

vi /var/lib/dhcp3/dhcpd.leases

# All times in this file are in UTC (GMT), not your local timezone. This is # not a bug, so please don't ask about it. There is no portable way to # store leases in the local timezone, so please don't request this as a # feature. If this is inconvenient or confusing to you, we sincerely # apologize. Seriously, though - don't ask. # The format of this file is documented in the dhcpd.leases(5) manual page. # This lease file was written by isc-dhcp-V3.0.1 lease 192.168.0.229 { starts 2 2006/09/19 14:01:31; ends 3 2006/09/20 14:01:31; binding state active; next binding state free; hardware ethernet 00:0c:76:8b:c4:16; uid "\001\000\014v\213\304\026"; client-hostname "matze"; }

5 Links

ISC-DHCP: http://www.isc.org/index.pl?/sw/dhcp/ dhcpd.conf configuration options: http://www.bind9.net/dhcpd.conf.5 Network Calculators: http://www.subnetmask.info

You might also like