czwartek, 14 czerwca 2012

Serwer DHCP na CentOS - dnsmasq

W związku z tym, że dostałem zapytanie dotyczące uruchomienia serwera DHCP postanowiłem napisać krótki tutorial.
Serwer DHCP konfigurowałem tylko raz gdy w pracy musiałem skonfigurować serwer NAS i jedyna możliwość połączenia się z nim było przydzielenie mu adresu IP za pomocą DHCP. Na wpięcie NAS'a w sieć firmową bez wcześniejszej konfiguracji nie mogłem sobie pozwolić, routerów z DHCP pod ręką nie było więc został Linux live (CentOS 6) i dnsmasq - domyślnie obecny w tej dystrybucji.

Zmiany które wprowadziłem w pliku konfiguracyjnym:

# If you want dnsmasq to listen for DHCP and DNS requests only on # specified interfaces (and the loopback) give the name of the # interface (eg eth0) here. # Repeat the line for more than one interface. #interface= # Or you can specify which interface _not_ to listen on #except-interface= # Or which to listen on by address (remember to include 127.0.0.1 if # you use this.) #listen-address= # If you want dnsmasq to provide only DNS service on an interface, # configure it as shown above, and then use the following line to # disable DHCP on it. #no-dhcp-interface=
dodałem:
listen-address=eth0
Przeważnie chcemy udostępnić DHCP dla jednego interfejsu, tego za którym znajduje się sieć lokalna.

Zdefiniowałem zakres przydzielanych adresów IP: # This is an example of a DHCP range where the netmask is given. This # is needed for networks we reach the dnsmasq DHCP server via a relay # agent. If you don't know what a DHCP relay agent is, you probably # don't need to worry about this. dhcp-range=192.168.0.50,192.168.0.150,255.255.255.0,12h Pozostałe adresy w tym przypadku mogą być ustawione statycznie.

Przypisałem adres IP do hosta z określonym adresem IP, przydatne np. dla drukarek sieciowych oraz serwerów. # Always allocate the host with ethernet address 11:22:33:44:55:66 # The IP address 192.168.0.60 dhcp-host=11:22:33:44:55:66,192.168.0.60

Można też zmienić bramę domyślną jeżeli serwer DHCP oraz router to dwie różne maszyny: # Override the default route supplied by dnsmasq, which assumes the # router is the same machine as the one running dnsmasq. dhcp-option=3,1.2.3.4

Poniżej umieściłem również opcje, które mogą okazać się przydatne ale w moim przypadku korzystanie z nich było niepotrzebne.

# Set the default time-to-live to 50 #dhcp-option=23,50

# The following DHCP options set up dnsmasq in the same way as is specified # for the ISC dhcpcd in # http://www.samba.org/samba/ftp/docs/textdocs/DHCP-Server-Configuration.txt # adapted for a typical dnsmasq installation where the host running # dnsmasq is also the host running samba. # you may want to uncomment some or all of them if you use # Windows clients and Samba. #dhcp-option=19,0 # option ip-forwarding off #dhcp-option=44,0.0.0.0 # set netbios-over-TCP/IP nameserver(s) aka WINS server(s) #dhcp-option=45,0.0.0.0 # netbios datagram distribution server #dhcp-option=46,8 # netbios node type

# Send RFC-3442 classless static routes (note the netmask encoding) #dhcp-option=121,192.168.1.0/24,1.2.3.4,10.0.0.0/8,5.6.7.8

# Send microsoft-specific option to tell windows to release the DHCP lease # when it shuts down. Note the "i" flag, to tell dnsmasq to send the # value as a four-byte integer - that's what microsoft wants. See # http://technet2.microsoft.com/WindowsServer/en/library/a70f1bb7-d2d4-49f0-96d6-4b7414ecfaae1033.mspx?mfr=true #dhcp-option=vendor:MSFT,2,1i

# Set the limit on DHCP leases, the default is 150 #dhcp-lease-max=150

# The DHCP server needs somewhere on disk to keep its lease database. # This defaults to a sane location, but if you want to change it, use # the line below. #dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases

# Set the DHCP server to authoritative mode. In this mode it will barge in # and take over the lease for any client which broadcasts on the network, # whether it has a record of the lease or not. This avoids long timeouts # when a machine wakes up on a new network. DO NOT enable this if there's # the slighest chance that you might end up accidentally configuring a DHCP # server for your campus/company accidentally. The ISC server uses # the same option, and this URL provides more information: # http://www.isc.org/index.pl?/sw/dhcp/authoritative.php #dhcp-authoritative

# Set the cachesize here. #cache-size=150

# Normally responses which come form /etc/hosts and the DHCP lease # file have Time-To-Live set as zero, which conventionally means # do not cache further. If you are happy to trade lower load on the # server for potentially stale date, you can set a time-to-live (in # seconds) here. #local-ttl=

# Log lots of extra information about DHCP transactions. #log-dhcp

Mam nadzieję, że powyższy tutorial okazał się przydatny i uda się rozwiązać problemy z serwerem DHCP. Dnsmasq zawiera znacznie więcej opcji, opisałem jednak tylko te niezbędne do uruchomienia serwera DHCP.

Brak komentarzy:

Prześlij komentarz