LinuxForum.Fans
Тема

[Решено] установка и настройка dhcp3-server на debian

Автор: Linux777 9 сообщений 4573 просмотров
#321444

Нашел похожую статью, но на дистрибутиве Redhat-CentOs Не запускается DHCP сервер поэтому решил отделить топик по дистрибутиву.

Вообщем поначалу тоже была проблема запуска стартового скрипта

text
 /etc/init.d/isc-dhcp-server restart
 * Stopping ISC DHCP server dhcpd                                           [fail]
 * Starting ISC DHCP server dhcpd                                            [fail]
 * check syslog for diagnostics                                                                             

Посмотрел логи /var/log/syslog и понял причина всему ненастроенный интерфейсы:

Показать
May 23 10:59:07 Monitoring dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
May 23 10:59:07 Monitoring dhcpd: Copyright 2004-2010 Internet Systems Consortium.
May 23 10:59:07 Monitoring dhcpd: All rights reserved.
May 23 10:59:07 Monitoring dhcpd: For info, please visit https://www.isc.org/software/dhcp/
May 23 10:59:09 Monitoring dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
May 23 10:59:09 Monitoring dhcpd: Copyright 2004-2010 Internet Systems Consortium.
May 23 10:59:09 Monitoring dhcpd: All rights reserved.
May 23 10:59:09 Monitoring dhcpd: For info, please visit https://www.isc.org/software/dhcp/
May 23 10:59:09 Monitoring dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
May 23 10:59:09 Monitoring dhcpd: Copyright 2004-2010 Internet Systems Consortium.
May 23 10:59:09 Monitoring dhcpd: All rights reserved.
May 23 10:59:09 Monitoring dhcpd: For info, please visit https://www.isc.org/software/dhcp/
May 23 10:59:09 Monitoring dhcpd: Wrote 0 leases to leases file.
May 23 10:59:09 Monitoring dhcpd:
May 23 10:59:09 Monitoring dhcpd: No subnet declaration for eth1 (192.168.2.2).
May 23 10:59:09 Monitoring dhcpd: ** Ignoring requests on eth1. If this is not what
May 23 10:59:09 Monitoring dhcpd: you want, please write a subnet declaration
May 23 10:59:09 Monitoring dhcpd: in your dhcpd.conf file for the network segment
May 23 10:59:09 Monitoring dhcpd: to which interface eth1 is attached. **
May 23 10:59:09 Monitoring dhcpd:
May 23 10:59:09 Monitoring dhcpd:
May 23 10:59:09 Monitoring dhcpd: No subnet declaration for eth0 (192.168.0.2).
May 23 10:59:09 Monitoring dhcpd: ** Ignoring requests on eth0. If this is not what
May 23 10:59:09 Monitoring dhcpd: you want, please write a subnet declaration
May 23 10:59:09 Monitoring dhcpd: in your dhcpd.conf file for the network segment
May 23 10:59:09 Monitoring dhcpd: to which interface eth0 is attached. **
May 23 10:59:09 Monitoring dhcpd:
May 23 10:59:09 Monitoring dhcpd:
May 23 10:59:09 Monitoring dhcpd: Not configured to listen on any interfaces!

нашел статью http://mydebian.ru/install-dhcp-server-on-debian-6/ и не одну http://www.fullautomatic.ru/index.php/debian-ubuntu-rhel-centos/60-20 после чего настраиваю конфиги. Как понял из статей, это нормальное явление для первого запуска dhcp.

собственно после указания интерфейса, на котором будет работать дхсп, настаиваем конфиг /etc/dhcp/dhcpd.conf (в примере дефолтный конфиг)

Показать
# Sample configuration file for ISC dhcpd for Debian
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

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

default-lease-time 600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

#subnet 10.254.239.32 netmask 255.255.255.224 {
# range dynamic-bootp 10.254.239.40 10.254.239.60;
# option broadcast-address 10.254.239.31;
# option routers rtr-239-32-1.example.org;
#}

# 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;
#}

# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

#host passacaglia {
# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.fugue.com";
#}

# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {
# hardware ethernet 08:00:07:26:c0:a5;
# fixed-address fantasia.fugue.com;
#}

# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" {
# match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}
:

#321450

Отредактировал конфиг и перезапустил сервер. Ошибок нет

text
/etc/dhcp# /etc/init.d/isc-dhcp-server start
 * Starting ISC DHCP server dhcpd                                                                                                        [ OK ]

Поясню, что надо отредактировать в конфиге и выделю жирным

Показать
# Sample configuration file for ISC dhcpd for Debian
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers 8.8.8.8, 8.8.4.4; Задать DNS-сервера

default-lease-time 32400;
max-lease-time 604800;
Задать время аренды 32400 и 604800 - на 9 часов и неделю в секундах

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative; сделаем его единственным (авторитетным) для нашей сети

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

# subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
# }


# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.


subnet 192.168.0.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.0.1 192.168.0.254; здесь задаем сеть, маску, широковещательный адрес и роутер
option broadcast-address 192.168.0.255;
option routers 192.168.0.2;
deny unknown-clients; говорим серверу, что делать с неизвестными клиентами. В данном случае им будет отказано в обслуживании
}

как я понял это для динамической раздачи адресов, именно этот участок конфига отвечает, поэтому дали все параметры

о чем сказано - allows BOOTP clients to get dynamic addresses, что означает разрешить клиентам получать динамические IP


# 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;
#}

# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

#host passacaglia {
# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.fugue.com";
#}

# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.

а тут привязываю статическую адресацию :) как я потом понял это и есть резервирование, т.е. чтобы жестко привязать по IP и MAC

host PIN {
hardware ethernet 00:ХХ:42:ХХ:22:ХХ;
fixed-address 192.168.0.ХХ;
}



host RMN {
hardware ethernet 00:ХХ:92:ХХ:05:ХХ;
fixed-address 192.168.0.ХХ;
}


host MVL {
hardware ethernet 78:ХХ:3c:ХХ:ec:ХХ;
fixed-address 192.168.0.ХХ;
}


host SNN {
hardware ethernet c8:ХХ:a9:ХХ:3f:ХХ;
fixed-address 192.168.0.ХХ;
}


host GNE {
hardware ethernet 00:ХХ:21:ХХ:70:ХХ;
fixed-address 192.168.0.ХХ;
}


host VSV {
hardware ethernet f0:ХХ:97:ХХ:76:ХХ;
fixed-address 192.168.0.ХХ;
}


host FSA {
hardware ethernet 00:ХХ:21:ХХ:70:ХХ;
fixed-address 192.168.0.ХХ;
}


# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

#class "foo" {
# match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}

#shared-network 224-29 {
# subnet 10.17.224.0 netmask 255.255.255.0 {
# option routers rtr-224.example.org;
# }

# subnet 10.0.29.0 netmask 255.255.255.0 {
# option routers rtr-29.example.org;
# }
# pool {
# allow members of "foo";
# range 10.17.224.10 10.17.224.250;
# }
# pool {
# deny members of "foo";
# range 10.0.29.10 10.0.29.230;
# }
#}

еще одна пару полезных ссылок http://testino.ru/main/linux/106-ustanavlivaem-dhcp-server-na-debian-i-ubuntu.html и http://www.unix.ck.ua/content/nastroika-dhcp-servera

#321465

Единственное, я пока не понял, как сделать резервированные адреса, которые нельзя раздавать? например сервер, принтер, самба и д.р. какой параметр в конфиге за это отвечает?

аа. все я понял это и есть резервирование, когда привезка к маку и айпи идет.

host GNE {
hardware ethernet 00:ХХ:21:ХХ:70:ХХ;
fixed-address 192.168.0.ХХ;
}

host VSV {
hardware ethernet f0:ХХ:97:ХХ:76:ХХ;
fixed-address 192.168.0.ХХ;
}

host FSA {
hardware ethernet 00:ХХ:21:ХХ:70:ХХ;
fixed-address 192.168.0.ХХ;
#321469

для отдельных айпи привязку по маку.

text
host cinnamon {
  hardware ethernet 00:0D:87:B3:AE:A6;
  fixed-address 192.168.1.5;
}

Лучшая ссылка
http://wiki.debian.org/DHCP_Server

#321470
text
host cinnamon {
  hardware ethernet 00:0D:87:B3:AE:A6;
  fixed-address 192.168.1.5;
}

ага, я уже сам додумался. а то ссылок куча. начитался)

#321471

И вот еще важно, если надо узнать, какие адреса выдались и узнать их статус, идем сюда


/var/lib/dhcp/dhcpd.leases

собственно залез просмотрел

/var/lib/dhcp# cat dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.1.1-P1

lease 192.168.0.ХХ {
starts 4 2013/05/23 12:03:53;
ends 4 2013/05/23 21:03:53;
cltt 4 2013/05/23 12:03:53;
binding state active;
next binding state free;
hardware ethernet 00:ХХ:42:ХХ:22:ХХ;
client-hostname "IgorBOOK-E8310";
}
server-duid "\000\001\000\001\0310\233\317\000\033!\320y\307";
text
о чем можно сказать, что все работает, выдает адреса, пишет срок аренды и т.д.

для перезапуска службы выполним

/etc/init.d/isc-dhcp-server restart
* Stopping ISC DHCP server dhcpd [ OK ]
* Starting ISC DHCP server dhcpd [ OK ]

Ну, на этом думаю настройка закончена. Осталось проверить на тестовой машине, предварительно включить получение адресов автоматически и попробовать зелесть в интернет.

если кому надо, можно указать сервер времени

option ntp-servers 192.129.129.129 (айпи выдуманный);
#321472
"Kettler⇓" написал:
для отдельных айпи привязку по маку.

host cinnamon {
hardware ethernet 00:0D:87:B3:AE:A6;
fixed-address 192.168.1.5;

кстати, если у меня диапазон адресов зарезервированы

с 192.168.0.1 по 192.168.0.29
с 192.168.0.50 по 192.168.0.60

как прописать целый ряд? тупо по одному же резервировать с ума сойдешь, да и не вариант, каждому адресу айпи и мак прописывать. наверняка есть возможность ряд записать?


кстати, пока лазил по инету, нашел еще одну фичу, оказывается можно вебморду GUI прикрутить к DHCP. круто!! http://webdhcpdns.labs.libre-entreprise.org/index-en.html

Причем она еще и ДНС мониторит :)

#321527
"Linux777⇓" написал:
кстати, если у меня диапазон адресов зарезервированы
с 192.168.0.1 по 192.168.0.29
с 192.168.0.50 по 192.168.0.60
как прописать целый ряд? тупо по одному же резервировать с ума сойдешь,

Тут скорее надо от обратного плясать, те выделять range исключая зарезервированные адреса.
Выдрал кусок рабочего конфига, надеюсь он пояснит:

text
option domain-name-servers 192.168.0.1;
option ntp-servers 192.168.0.1;
ddns-update-style interim;
option routers 192.168.0.1;
authoritative;
option broadcast-address 192.168.0.255;

subnet 192.168.0.0 netmask 255.255.255.0 {

host XXX1 { hardware ethernet xx:xx:xx:xx:xx:xx; fixed-address 192.168.0.xx; } host XXX2 { hardware ethernet xx:xx:xx:xx:xx:xx; fixed-address 192.168.0.xx; } ... ...

pool { # диапазон адресов для клиентов range 192.168.0.100 192.168.0.110; option subnet-mask 255.255.255.0; option broadcast-address 192.168.0.255; # сказать клиентам, чтобы отдали адрес в секундах # default-lease-time 21600; # забрать адрес самому в секундах # max-lease-time 28800; }

pool { range 192.168.0.200 192.168.0.240; option routers 192.168.0.1; option subnet-mask 255.255.255.0; option broadcast-address 192.168.0.255; }

}

Мак адреса arp`ом ловить на сервере, их уж наверное только руками....

#321611
"zenon⇓" написал:
Тут скорее надо от обратного плясать, те выделять range исключая зарезервированные адреса.

Получается, согласно условию моему

"zenon⇓" написал:
кстати, если у меня диапазон адресов зарезервированы
с 192.168.0.1 по 192.168.0.29
с 192.168.0.50 по 192.168.0.60

range 192.168.0.30 192.168.0.49 (т.е. это реальные адреса для раздачи дхцп) а резервированные (с 0.1-0.29 я не пишу в range).
ну проще говоря, что резервируешь, то не пишешь в range. вроде бы так?

Войдите или зарегистрируйтесь, чтобы ответить.