Domovské stránky Daniela Hrotka

ÚVOD | O MNĚ | O BOHU | ICT | ASTRO | SRANDA | RADIO | Hi-Fi | ODKAZY | KONTAKT

DHCP server


Autorem následujícího návodu je Kyle Symonds. Originální WWW v anglickém jazyku.


6. 2. 2006 Daniel Hrotek





Na úvod



Protokol DHCP (Dynamic Host Configuration Protocol) používáme ke konfiguraci klíčových síťových parametrů jednotlivých klientů. Jejich nastavení umožňují DHCP servery, které přidělují klientům předem definované prostředky. Pro síť typu C (do 250 hostů) to bude 192.168.0.0 s netmaskou 255.255.255.0. Tento rozsah a popis je definován v dokumentu RFC 1918.

Protokol vyvinula a spravuje ISC (Internet Software Consorcium). Dodává také příslušný software, který je šířen jako open source. Týká se to jak serverové, tak klientské části.

Jak to funguje? DHCP rozšiřuje BOOTP protokol, se kterým je zpětně kompatibilní. Klient vyšle do sítě broadcast (všesměrové vysílání) UDP požadavek DHCPDISCOVER. Servery zachytí požadavky a zašlou zprávu DHCPOFFER (opět broadcast). Klient si vybere ze všech odpovědí tu nejvhodnější a pošle DHCPREQUEST. Server, který klient oslovuje, vše buď potvrdí (DHCPACK), nebo ne (DHCPNAK). Klient si to může ještě rozmyslet (DHCPDECLINE). Po vypršení lhůty (nebo pokud klient skončí před lhůtou a pošle DHCPRELEASE) se adresa může poskytnout jinému zájemci (existují i výjimky).

Post Scriptum: Broadcast vysílá všem stanicím v síti. Multicast jen některým. Unicast - server jen jednomu příjemci.



Požadavky





Krok 1. - instalace



The ISC DHCP daemon is already on the ports tree so it's quite simple to install.

# cd /usr/ports/net/isc-dhcp3-server
# make install clean; rehash



Krok 2. - konfigurace



The first thing to do is to edit the startup script.

# cd /usr/local/etc/rc.d/
# mv isc-dhcpd.sh.sample isc-dhcpd.sh
# nano -w isc-dhcpd.sh


Look for two lines that look like “dhcpd_options“ and “dhcpd_ifaces“. Under dhcpd_options, you want -q (this eliminates a terribly annoying banner every time the server's started up. Under dhcpd_ifaces, you want to list the network device you want the DHCP daemon to listen on (pro příklad: xl0).

Save and quit. Now it's time for the server configuration.

# cd /usr/local/etc
# nano -w dhcpd.conf


My configuration looks something like the following:

ddns-update-style none;
subnet 192.168.2.0 netmask 255.255.255.0 {
            range 192.168.2.5 192.168.2.240;
            default-lease-time 144000;
            max-lease-time 192000;
            option subnet-mask 255.255.255.0;
            option broadcast-address 192.168.2.255;
            option routers 192.168.2.1;
            option domain-name-servers ip.adresa.vaseho.DNS;
            option domain-name “vase.domena.cz“;
            option netbios-name-servers 192.168.2.1;
            use-host-decl-names on;
   host muj_pocitac_v_LAN_siti {
     hardware ethernet 00:00:00:00:00:00;
     fixed-address 192.168.2.2;
     }
   host muj_dalsi_pocitac_v_LAN_siti {
     hardware ethernet 00:00:bb:bb:bb:bb;
     fixed-address 192.168.1.12;
     }
}


Most of the options should be fairly obvious what they do/set if you've done any sort of network configuration or management before, but just in case, I'll go over them. The subnet and netmask declaration are the IP and subnet you'd like to use (you have to declare this again for the range or scope you'd like your DHCP server to dish out IPs for). In this example, I use 10.10.10.x with a subnet of 255.255.255.0 so that's what it's set up as. If you're using 192.168.1.x for your network, then use 192.168.1.0 for the first line instead of my 10.10.10.0; that's fairly straightforward.

Next is the range or scope you'd like your DHCP server to dish out IPs in. This is very straightforward and I don't feel it needs any further explanation.

The max-lease-time is the lease time (in seconds) for an IP. The lease time is how long it'll be before the DHCP daemon cycles through and sees if the IP's currently in use and either renews the lease or frees the IP accordingly.

subnet-mask is straightforward. This must match the netmask declaration at the beginning.

The broadcast-address must be at the end of your range. In this example, it'd be 10.10.10.255; if you're using 192.168.1.x then it'd be 192.168.1.255.

The routers option specifies a machine/device acting as a gateway for internet access. If you don't have any, simply delete this line and pretend it doesn't exist (like for a LAN party DHCP server without Internet access).

domain-name-servers specifies DNS server IPs. This is always good to be set to some sort of DNS server, even if it's not on your internal LAN.

netbios-name-servers are the WINS servers on your network if any. If you don't have any, simply delete this line and pretend it doesn't exist.

use-host-decl-names simply let's me use the block below that's an example on how to designate a static IP based on a MAC address. If you don't need such a thing, simply delete it.

The last block is simply an example on how to designate a static IP address for something based on its MAC address. In this case, I want to have my switch use the IP 10.10.10.1 so I can telnet to it and tinker with it's configuration. This is optional and doesn't have to be in the configuration file.

Just in case:

# chmod 755 /usr/local/etc/rc.d/isc-dhcpd.sh


Then just run the following to start that puppy up:

# /usr/local/etc/rc.d/isc-dhcpd.sh start


Pakliže byste chtěli mít spuštěn DHCP server po každém startu routeru / serveru pak využijte zapište do rc.conf:

dhcpd_enable=“YES“


Konfigurační soubor naleznete:

/usr/local/etc/dhcpd.conf


Databáse propůjčených IP adres:

/var/db/dhcpd.leases



Možnosti



Pro příklad -> DHCP pro dvě různá síťová rozhraní, pak v dhcpd.conf bude uvedeno:

dhcp-range=eth0,192.168.1.1,192.168.1.255,48h
dhcp-range=wlan0,192.168.2.1,192.168.2.255,48h


Dva DHCP servery v jedné LAN:

První odpověď, která dorazí ke klientovi z jednoho DHCP serveru, si veme klient jako platnou. Obvykle je lepší nastavit, který DHCP server se stará o které MAC adresy klientů. Případně nastavit u druhého DHCP serveru podávání opožděných nabídek klientům oproti DHCP serveru prvnímu.
Můžete také prvnímu DHCP serveru nastavit jiný rozsah nabízených IP adres. Tj. první server bude například nabízet rozsah IP adres od 192.168.2.2 do 192.168.2.100 a druhý DHCP server bude nabízet rozsah IP adres od 192.168.2.101 do 192.168.2.200.

Aby si DHCP server nevšímal nějaké sítě pak v dhcpd.conf bude uvedeno:

subnet 192.168.1.0 netmask 255.255.255.255 {
     not authoritative;
   }


Přidělení IP adresy dle MAC síťové karty pak v dhcpd.conf bude uvedeno:

host muj_pocitac_v_LAN_siti {
     hardware ethernet 08:00:2b:4c:59:23;
     fixed-address 192.168.2.2;
   }
host muj_dalsi_pocitac_v_LAN_siti {
     hardware ethernet 00:00:bb:bb:bb:bb;
     fixed-address 192.168.2.3;
   }
Operační systémy
 povídání o FreeBSD začínáme s FreeBSD FreeBSD - základní kroky Sun Solaris - základní kroky Linux - základní kroky Windows - základní kroky
 
Hrátky s operačními systémy
 FreeBSD router FreeBSD ve firmě FreeBSD porty - jak na ně? vytváření FreeBSD balíčku instalace NetBSD
 
Počítačové sítě
 StarHill esej o bezdrátových sítích pasivní restranslace tvorba sítí typu ethernet Pure-FTPd + SSL + VA Samba a její nastavení Apache SSL - htaccess - PHP DHCP server Nessus
 
Lokalizace
 manuály FreeBSD RONJA Pure-FTPd nastavení Pure-FTPd
 
Software
 Visual Basic Acrobat Reader 5 a FreeBSD logovací démon - syslogd
 
Jednočipy
 programátor PIC
 
Různé
 mé konfigurační soubory