Create a DHCP server in a Linux operating system

Source: Internet
Author: User

 

DHCP is the abbreviation of Dynamic Host Configuration Protocol. Its function is to dynamically allocate IP addresses for network connections. It allows the client computer to automatically obtain network settings from the network server. The DHCP server makes it easy for the network administrator to add or delete network nodes in the management network or reconfigure the network, without the need to manually assign IP addresses. Setting up a DHCP server on a Linux host is more cost-effective than Windows NT. This document uses redhat7.2 as an example to describe how to use Linux to create a DHCP server and how the network administrator manages the DHCP server.

Setting up a DHCP server in a Linux operating system is very simple. You only need to master a few simple commands and edit the/etc/DHCPD. conf file, so you can quickly create a DHCP server. In fact, the operation is not more complex than Windows NT. The specific operation is as follows:

1. How to Establish a DHCP service.

(1) install DHCP server software

# Mount/mnt/CDROM
# Rpm-IVH/mnt/CDROM/RedHat/RPMS/DHCP-2.0pl5-8.i386.rpm

(2) configure the DHCP server/etc/DHCPD. conf file. You can copy an example file DHCPD. conf. sample from the/usr/share/doc/DHCP-2.0pl5 directory and modify it based on this file.

The following is just an example. For more information, see man DHCPD. conf. the DHCP server is in the 192.168.101.0 network segment.

Subnet 192.168.2.0 netmask 255.255.255.0 {
# $ Finance Section
Range 192.168.2.10 192.168.2.254;
Default-lease-time 43200;
Max-lease-time 86400;
Option broadcast-address 192.168.2.255;
Option subnet-mask limit 255.0;
Option routers 192.168.2.1;
# Option NetBIOS-name-servers 192.168.101.10;
}

Subnet 192.168.3.0 netmask 255.255.255.0 {
# $ Office
# Range dynamic-BOOTP 192.168.3.10 192.168.3.254;
Range 192.168.3.10 192.168.3.254;
Default-lease-time 43200;
Max-lease-time 86400;
Option broadcast-address 192.168.3.255;
Option routers 192.168.3.1;
Option subnet-mask limit 255.0;
# Option NetBIOS-name-servers 192.168.101.10;
}

Subnet 192.168.101.0 netmask 255.255.255.0 {
}

Note: # indicates the beginning of a line, indicating a comment. Each subnet indicates a dynamic address setting.

Range: the range of the lease address. It can contain discontinuous multi-segment addresses.

Default-lease-time: the default lease time, in seconds.

Max-lease-time: the maximum lease time, in seconds.

You can also include some options, such:

Broadcast-Address: broadcast address.

Routers: the default route or gateway.

Subnet-mask: Subnet Mask.

NetBIOS-name-servers: If Windows NT exists in the network, you can specify the address of the WINS server.

There are also many parameters. For example, you can specify an IP address for the MAC address of a specific hardware. For specific operations, see man DHCPD. conf.

In addition, because the DHCP server in this example is in the 192.168.101.0 network segment, an empty subnet must be specified.

Note: If the DHCP service and DHCP client are in different network segments, the network must have an IP router with the DHCP relay agent function, transfers DHCP information from one CIDR block to another. Generally, smart switches have the DHCP proxy function. You only need to set the IP address of the DHCP server in the switch.

If the hardware of the IP router does not support the DHCP relay proxy function, you must install the DHCP relay proxy program on the machine that acts as the IP router and enable the IP forwarding function, the dhcp rpm package also provides the dhcrelay command. For more information, see man dhcrelay.

(3) create the/var/lib/DHCP/DHCPD. Leases file.

# Touch/var/lib/DHCP/DHCPD. Leases

Note: For various GNU/Linux Release versions, the creation of DHCPD. leases may be in different directories. The directory of the DHCPD. Leases file must be determined based on different release versions.

(4) activate the DHCP service, execute the ntsysv command, select DHCPD, select OK to exit, and automatically start the DHCP service the next time you start the system. You can also manually execute the following command for testing:

/Etc/rc. d/init. d/DHCPD start # Start the DHCP service.
/Etc/rc. d/init. d/DHCPD stop # disable the DHCP service.

Benchmark Test

Select a client, enter windows, and set the IP address to automatically obtained. After restarting, run winipcfg/all

Check whether the DHCP service is correctly set.

Ii. How to manage the DHCP service:

After the DHCP server is set up, it is very important for the network administrator to better manage the DHCP service, although the network administrator can view the DHCPD. the leases file understands the allocation of Client IP addresses and other information, but when there are many machines in the network, it is obviously not a very good method.

In practice, I found that by using the dhcpstatus tool, I can use a web browser to understand the usage and allocation of DHCP servers.

The procedure is as follows:

(1) download and install the dhcpstatus software.

Download http://prdownloads.sourceforge.net/DHCPstatus/DHCPstatus_0.60.tar.gz

# Tar xzvf dhcpstatus_x.xx.tar.gz-C/tmp

(2) read the install file in the installation directory carefully. The procedure is as follows:

(A) Create a library directory.

# Mkdir/usr/local/dhcpstatus
# Cd/usr/local/dhcpstatus

(B) decompress the tar file of the Library to the/usr/local/dhcpstatus directory.

# Tar xvf/tmp/dhcpstatus_x.xx/libraries.tar

A dhcpstatus directory and a dhcpstatis. ini file will be created.

(C) modify and edit the dhcpstatus. ini file based on the specific settings of the DHCP server. The main parameters are:

Title = DHCP subnet Information
Leases_file =/etc/DHCPD. Leases
Changed:
Title = xxxx dhcp subnet Information
Leases_file =/var/lib/DHCP/DHCPD. Leases
# Note: The leases_file parameter must be modified based on the Linux release version.

(D) If DHCPD is created above. the conf file does not include the information such as/"# $ Finance Section/". It is best to add it to dhcpstaus. the CGI script reads/etc/DHCPD. CONF file to obtain this information. Note that $ cannot be omitted.

(E) install the scripts file and copy the dhcpstatus. cgi file under the scripts directory to the cgi-bin directory of the web service:

# Cp/tmp/dhcpstatus_x.xx/scripts/dhcpstatus. cgi/var/www/cgi-bin
# Cp/path/to/dhcpstatus_x.xx/scripts/dhcpstatus/usr/local/bin
Modify #! /Usr/local/bin/perl-W is #! /Usr/bin/perl-W

(F) To create a browser homepage, add the following code:

<P align =/"center/">
<A href =/"cgi-bin/dhcpstatus. cgi/"> DHCP subnet status </a>
</P>

(G) for security, you can create a password for the Web server. Take Apache 1.3.20 with redhat7.2 as an example:

* Modify/etc/httpd/CONF/httpd. conf:

<Directory/"/var/www/html/">
Options indexes followsymlinks
AllowOverride none
Order allow, deny
Allow from all
</Directory>
Changed:
<Directory/"/var/www/html/">
Options indexes followsymlinks
AllowOverride authconfig
Order allow, deny
Allow from all
</Directory>

* Create A. htaccess file in the/var/www/html directory with the following content:
Authname/"DHCP status access /"
Authtype basic
Authuserfile/var/www/html/. htpasswd
Require valid-user

* Run the htpasswd command to create a. htpasswd file in the/var/www/html directory.

Htpasswd-BC/var/www/html/. htpasswd admin xxxx

XXXX indicates the password, and more management users can be added. For specific operations, see man htpasswd.
Documentation.

(H) Start the HTTPd service,/etc/rc. d/init. d/httpd restart

With the above settings, the network administrator can easily manage the DHCP service and understand the usage and allocation of DHCP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.