Протокол DHCP позволяет пользовательскому компьютеру (хосту) автоматически получить IP-адрес, из выделенного пула адресов.
В CentOS 5 и 6 пути до конфигов различны
Установка:
Обновляемся
yum update
Устанавливаем DHCP сервер
yum install dhcp
Переименовываем наш конфиг, на случай отката обратно
mv /etc/dhcpd.conf /etc/dhcpd.conf.old
Копируем нужный нам конфиг
cp /usr/share/doc/dhcp-ВАШ НОМЕР ВЕРСИИ/ /etc/dhcp/dhcpd.conf
У меня выглядит так
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
Правим конфиг dhcpd.conf
vi /etc/dhcpd.conf
—————-МОЙ КОНФИГ—————-
# ddns-update-style interim; ddns-update-style none; DHCPARGS=eth3; ignore client-updates; subnet 192.168.7.0 netmask 255.255.255.0 { # --- default gateway option routers 192.168.7.1; # основной шлюз option subnet-mask 255.255.255.0; # маска подсети option nis-domain "domain.org"; option domain-name "domain.org"; # доменное имя # | my | cn.ru | COMODO.COM | Google Public DNS option domain-name-servers 192.168.7.1,195.189.239.5,195.189.238.68,156.154.70.25,156.154.71.25,8.8.8.8,8.8.4.4; # днс сервера option time-offset -18000; # Eastern Standard Time # option ntp-servers 192.168.1.1; # option netbios-name-servers 192.168.1.1; # --- Selects point-to-point node (default is hybrid). Don't change this unless # -- you understand Netbios very well # option netbios-node-type 2; range dynamic-bootp 192.168.7.128 192.168.7.254; default-lease-time 21600; # время аренды max-lease-time 43200; # максимальное время аренды # we want the nameserver to appear at a fixed address host ns { next-server marvin.redhat.com; hardware ethernet 12:34:56:78:AB:CD; fixed-address 207.175.42.254; } }
—————-МОЙ КОНФИГ—————-
Теперь перезагрузите сервер DHCP (после проверки конфигурации на ошибки, если есть ошибки, вы найдете их, перечисленные в /var/log/messages), чтобы изменения вступили в силу
service dhcpd configtest chkconfig --level 3 dhcpd on
Привязываем определенный ип адрес к компьютеру. Делается в dhcpd.conf
vi /etc/dhcpd.conf
host Lega { next-server marvin.redhat.com; hardware ethernet 00:16:D4:15:D5:06; fixed-address 192.168.7.7; }
Дополнительно.
Посмотреть список адресов которые выдались:
less /var/db/dhcpd.leases
или
less /var/lib/dhcpd/dhcpd.leases
Посмотреть логи:
less /var/log/messages
Привязка к определенном интерфейсу(можно через конфиг):
cat /etc/sysconfig/dhcpd
У нас привязанно к eth1
# Command line options here DHCPDARGS=eth1
Возможные ошибки:
1. WARNING: Host declarations are global. They are not limited to the scope you declared them in.
решение:
Описания хостов должны быть выведены за пределы описания подсетей, то есть запись host… должна начинаться после закрывающей описание subnet фигурной скобки.
пример:
subnet 192.168.0.0 netmask 255.255.255.0 { ОПИСАНИЕ СЕТИ } host maximax { Описание хоста }
2. Can’t open lease database /var/db/dhcpd.leases: No such file or directory
решение: Попробуйте отключить SElinux
3.Не запускается сервер
[root@home etc]# service dhcpd start Starting dhcpd: [FAILED] В логах: Oct 15 19:48:31 home dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1 Oct 15 19:48:31 home dhcpd: Copyright 2004-2010 Internet Systems Consortium. Oct 15 19:48:31 home dhcpd: All rights reserved. Oct 15 19:48:31 home dhcpd: For info, please visit https://www.isc.org/software/dhcp/ Oct 15 19:48:31 home dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file Oct 15 19:48:31 home dhcpd: Wrote 0 leases to leases file. Oct 15 19:48:31 home dhcpd: Oct 15 19:48:31 home dhcpd: No subnet declaration for eth1 (ВНЕШНИЙ_ИП_АДРЕС). Oct 15 19:48:31 home dhcpd: ** Ignoring requests on eth1. If this is not what Oct 15 19:48:31 home dhcpd: you want, please write a subnet declaration Oct 15 19:48:31 home dhcpd: in your dhcpd.conf file for the network segment Oct 15 19:48:31 home dhcpd: to which interface eth1 is attached. ** Oct 15 19:48:31 home dhcpd: Oct 15 19:48:31 home dhcpd: Oct 15 19:48:31 home dhcpd: No subnet declaration for eth0 (ВНУТРЕННИЙ_ИП_АДРЕС). Oct 15 19:48:31 home dhcpd: ** Ignoring requests on eth0. If this is not what Oct 15 19:48:31 home dhcpd: you want, please write a subnet declaration Oct 15 19:48:31 home dhcpd: in your dhcpd.conf file for the network segment Oct 15 19:48:31 home dhcpd: to which interface eth0 is attached. ** Oct 15 19:48:31 home dhcpd: Oct 15 19:48:31 home dhcpd: Oct 15 19:48:31 home dhcpd: Not configured to listen on any interfaces! Oct 15 19:48:31 home dhcpd: Oct 15 19:48:31 home dhcpd: This version of ISC DHCP is based on the release available Oct 15 19:48:31 home dhcpd: on ftp.isc.org. Features have been added and other changes Oct 15 19:48:31 home dhcpd: have been made to the base software release in order to make Oct 15 19:48:31 home dhcpd: it work better with this distribution. Oct 15 19:48:31 home dhcpd: Oct 15 19:48:31 home dhcpd: Please report for this software via the Red Hat Bugzilla site: Oct 15 19:48:31 home dhcpd: http://bugzilla.redhat.com Oct 15 19:48:31 home dhcpd: Oct 15 19:48:31 home dhcpd: exiting.
Решение:
На CentOS 6.0 конфиг должен находиться в
/etc/dhcp/dhcpd.conf
хорошая статья, только поправь что конфиг dhcp сервера храниться в /etc/dhcp/ а не /etc/ =)