2013-12-19

Servidor casero (linux) de DNS y DHCP

Si tu router es una mierda, como el mío, aunque tenga DHCP no podrás hacer cosas como:

  • asignarle (centralizadamente) a cada máquina de la red la IP que me de la gana
  • asignarle a cada IP el nombre que me de la gana, porque no tiene DNS

Sin embargo, con un servidor linux y dnsmasq no puede ser más fácil:

Instalamos dnsmasq:

$ sudo apt-get install dnsmasq


Modificamos el fichero /etc/dnsmasq.conf (pongo sólo las líneas interesantes y sus comentarios correspondients):

# If you don't want dnsmasq to read /etc/resolv.conf or any other
# file, getting its servers from this file instead (see below), then
# uncomment this.
#
# Como prefiero tener cuantos menos ficheros mejor, configuraré los servidores
# DNS en este mismo fichero (los de Google, los de R, etc...)
no-resolv

# Add other name servers here, with domain specs if they are for
# non-public domains.
#server=/localnet/192.168.0.1
server=213.60.205.175
server=213.60.205.173
server=212.51.32.254
server=8.8.8.8

server=8.8.4.4

# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
# Creo que no hay otra forma de indicarle los nombres, cuando me interesa
# dárselos yo, van a ir en el fichero /etc/hosts

expand-hosts

# Set the domain for dnsmasq. this is optional, but if it is set, it
# does the following things.
# 1) Allows DHCP hosts to have fully qualified domain names, as long
#     as the domain part matches this setting.
# 2) Sets the "domain" DHCP option thereby potentially setting the
#    domain of all systems configured by DHCP
# 3) Provides the domain part for "expand-hosts"
# Los PCs de mi red local se van a llamar xxxx.LAN.local

domain=LAN.local

# Uncomment this to enable the integrated DHCP server, you need
# to supply the range of addresses available for lease and optionally
# a lease time. If you have more than one network, you will need to
# repeat this for each network on which you want to supply DHCP
# service.
# Este es el rango de IPs que el servidor va a asignar de forma dinámica

dhcp-range=10.0.1.11,10.0.1.99,12h

# Always allocate the host with Ethernet address 11:22:33:44:55:66
# The IP address 192.168.0.60
# Esta máquina va a tener siempre esta IP, por narices

dhcp-host=00:1F:F3:42:33:FF,10.0.1.2

# Override the default route supplied by dnsmasq, which assumes the
# router is the same machine as the one running dnsmasq.
# La ip de mi router (default gateway) es 10.0.1.1

dhcp-option=3,10.0.1.1


El fichero tiene millones de opciones, pero creo que con estas llega.

Luego sólo falta modificar el fichero /etc/hosts para forzar un nombre a aquellas máquinas que no lo tienen, o nos interesa darle uno por cualquier motivo. Por ejemplo:

127.0.0.1       localhost
10.0.1.10       miservidor
10.0.1.1        cablemodem


Las asignaciones dinámicas se almacenan (por defecto) en /var/lib/misc/dnsmasq.leases, ahí podemos mirar cómo está la cosa.









No hay comentarios: