DHCP Server Installation & Configuration CentOS
===============================================
Requirement:-
Package = dhcp
Service = dhcpd
Port No. = 67
Configuration File = /etc/dhcpd.conf or /etc/dhcp/dhcpd.conf
========================================================================================
1] Install required package
[root@server ~]# yum install dhcp* -y
2] Copy the new sample file and paste it under /etc directory
[root@server ~]# cp /usr/share/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
[root@dhcp ~]# cat /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "example.com"; <<----- add here your local network dns domain name
option domain-name-servers 10.20.30.80, 8.8.8.8; <<----- add here dns ip
default-lease-time 86313600; <<---- dhcp ip leases
max-lease-time 86313600;
# Use this to enble / disable dynamic dns updates globally.
ddns-update-style none;
# 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 192.168.0.0 netmask 255.255.255.0 { <<---- its depend on your dhcp server local ip, here i have 192.168.0.10
}
# 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";
#}
#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;
# }
#}
###### We can create separate single vlan or multiple vlan its depend on our network requirement.
# IT vlan 2
subnet 10.0.0.0 netmask 255.255.254.0 {
range 10.0.0.2 10.0.1.254;
option domain-name "example.com";
option subnet-mask 255.255.254.0;
option broadcast-address 10.0.1.255;
option routers 10.0.0.1;
}
## Logistics vlan 3
subnet 10.0.2.0 netmask 255.255.254.0 {
range 10.0.2.2 10.0.3.254;
option domain-name "example.com";
option subnet-mask 255.255.254.0;
option broadcast-address 10.0.3.255;
option routers 10.0.2.1;
}
## B2H&Community vlan 4
subnet 10.0.4.0 netmask 255.255.255.0 {
range 10.0.4.2 10.0.4.254;
option domain-name "example.com";
option subnet-mask 255.255.255.0;
option broadcast-address 10.0.4.255;
option routers 10.0.4.1;
}
## Floor- 5 vlan 5
subnet 10.0.8.0 netmask 255.255.252.0 {
range 10.0.8.2 10.0.11.254;
option domain-name "example.com";
option subnet-mask 255.255.252.0;
option broadcast-address 10.0.11.255;
option routers 10.0.8.1;
}
## Floor-2 vlan 6
subnet 10.0.16.0 netmask 255.255.252.0 {
range 10.0.16.2 10.0.19.254;
option domain-name "example.com";
option subnet-mask 255.255.252.0;
option broadcast-address 10.0.19.255;
option routers 10.0.16.1;
}
## FLOOR-1&LOBBY vlan 7
subnet 10.0.20.0 netmask 255.255.252.0 {
range 10.0.20.2 10.0.23.254;
option domain-name "example.com";
option subnet-mask 255.255.252.0;
option broadcast-address 10.0.23.255;
option routers 10.0.20.1;
}
## WiFi vlan 8
subnet 10.0.12.0 netmask 255.255.252.0 {
range 10.0.12.21 10.0.15.254;
option domain-name "example.com";
option subnet-mask 255.255.252.0;
option broadcast-address 10.0.15.255;
option routers 10.0.12.1;
}
## DeploymentRoom vlan 12
subnet 10.0.6.0 netmask 255.255.255.0 {
range 10.0.6.2 10.0.6.254;
option domain-name "example.com";
option subnet-mask 255.255.255.0;
option broadcast-address 10.0.6.255;
option routers 10.0.6.1;
}
:wq
service dhcpd status
service dhcpd start
service dhcpd restart
=========================================
Setting Fixed Addresses:
There may be a time when it is necessary for a workstation to be assigned a fixed address, this can be easily achieved by setting the following details in the bottom of the /etc/dhcpd.conf file.
host hostname {
hardware ethernet 00:0d:62:d7:a0:12;
fixed-address 192.168.1.5;
}
Setting Daemon Options :
The DHCP daemon can be configured with command line options by using the /etc/sysconfig/dhcpd file. For security, DHCP can be bound to an interface so the allocation of addresses are only available to the private internal network.
[bash]# vi /etc/sysconfig/dhcpd
Setting this option provides queries and assignment only through this interface.
# Command line options here
DHCPDARGS=eth1
:Wq
##
Once the service has been started the system log should be checked to see if there are any errors. Most important is the security options we viewed earlier, which was to make sure the daemon was bound to the internal interface. The following example shows a binding to eth0.
[bash]# grep dhcpd /var/log/messages
galaxy dhcpd: Listening on LPF/eth1/00:40:05:51:20:e7/192.168.1.0/24
galaxy dhcpd: Sending on LPF/eth1/00:40:05:51:20:e7/192.168.1.0/24
galaxy dhcpd: Sending on Socket/fallback/fallback-net
galaxy dhcpd: dhcpd startup succeeded
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Testing The Server:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
If the Linux client distribution you are testing uses the dhclient package from the Internet Systems Consortium, then use the following command to obtain a lease for the eth0 network device.
[bash]# dhclient eth0 (EXECUTED ON CLIENT WORKSTATION)
Windows Client:
C:\>ipconfig /release
C:\>ipconfig /renew
For Example:
Testing a Windows based DHCP client is best done from a command prompt in the DOS shell, as more information is returned to the user than the standard graphical tools.
To release and renew your windows based IP address, follow these examples (expected results are provided).
C:\>ipconfig /release
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 0.0.0.0
Subnet Mask . . . . . . . . . . . : 0.0.0.0
Default Gateway . . . . . . . . . :
C:\>ipconfig /renew
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : example.com
IP Address. . . . . . . . . . . . : 192.168.1.5
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
The following command will provide more detailed information about the leased IP address and associated network resources.
C:\>ipconfig /all
#################### TO send Log File ######
1. Edit dhcpd.conf and add this line
log-facility local7;
2. Edit syslog.conf or /etc/rsyslog.conf and append
local7.* /var/log/dhcpd.log
restart dhcpd service and rsyslog
Ref:
http://www.brennan.id.au/10-DHCP_Server.html
#### How to Exclude ip From DHCP ######
How to exclude ip address in dhcp?
my ranges are 192.168.1.2 192.168.1.20
then how do i exclude different ip's like 192.168.1.4 and 7 and 10 from the range
please help me out
Ans:
You will have to use multiple range statements
range 192.168.1.2 192.168.1.20;
range 192.168.1.23 192.168.1.30;
The above will exclude 21 and 22
subnet 192.168.1.0 netmask 255.255.255.0
{
range 192.168.1.2 192.168.1.3;
range 192.168.1.5 192.168.1.6;
range 192.168.1.8 192.168.1.9;
}
========================
for example:
if the range is 192.168.0.1 to 192.168.0.125
and i want to exclude 192.168.0.10 to 192.168.0.25 addresses not to be given
I Think for this you can use multiple ranges in dhcpd.conf
i.e.
subnet 192.168.0.0 netmask 255.255.255.0
{
range 192.168.0.1 192.168.0.9;
range 192.168.0.26 192.168.0.125;
}
So above will exclude 192.168.0.10 to 192.168.0.25 range