"Linux" DHCP server build!

Source: Internet
Author: User
Tags ack get ip

Experimental topology

System version: CentOS6.5 64-bit system

650) this.width=650; "title=" 277) Y9[5ql}1pwegh ' (onpb.png "alt=" wkiol1aahpjgti-maaa462dqm7a681.png "src=" http:// S4.51cto.com/wyfs02/m01/79/be/wkiol1aahpjgti-maaa462dqm7a681.png "/>

Experimental requirements

C1 and C2 Get IP addresses through DHCP

DHCP server reserved addresses separately for C3


Configuration steps

[[email protected] ~]# mount/dev/cdrom/mnt //Mount CD to mnt directory

Mount:block Device/dev/sr0 is write-protected, mounting read-only

[[email protected] ~]# rpm-ivh/mnt/packages/dhcp-4.1.1-38.p1.el6.centos.x86_64.rpm //install DHCP service


The DHCP server network card must have a static IP address, the local address is: 192.168.10.250/24


DHCP configuration file under the/ETC/DHCP/DHCP directory

[Email protected] ~]# cd/etc/dhcp/dhcpd.conf


Because the configuration file does not have any configuration content, you can view the configuration file by using the Cat command to view the configuration template path

[email protected] dhcp]# cat dhcpd.conf

#

# DHCP Server Configuration file.

# See /usr/share/doc/dhcp*/dhcpd.conf.sample

# See ' Mans 5 dhcpd.conf '

#

[Email protected] dhcp]#


Copy the template to the current directory with the CP command, overwriting the dhcpd.conf file

[Email protected] dhcp]# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample./dhcpd.conf

CP: Do you want to overwrite "./dhcpd.conf"? Yes

[Email protected] dhcp]#

[[email protected] dhcp]# cp dhcpd.conf Dhcpd.conf.bak //configuration file backup before modifying configuration

[Email protected] dhcp]# grep-v "^#" dhcpd.conf > dhcpd1.conf

Filter the comment lines that begin with "#" in the configuration file and append them to a new file

[Email protected] dhcp]# grep-v "^$" dhcpd1.conf > dhcpd2.conf

Filter filtered files to filter out blank lines at a time and append to new files

[[Email protected] dhcp]# mv dhcpd2.conf dhcpd.conf //Rename the filtered file dhcpd.conf overwrite the original file

MV: Do you want to overwrite "dhcpd.conf"? Yes

[Email protected] dhcp]#


Use the Vim editor to open the dhcp.conf file, delete the redundant sample lines in the file and keep one copy.

----------------------------------- The modified configuration file ---------------------------------------


Default-lease-time 600; //minimum lease, unit of seconds

Max-lease-time 7200; //maximum lease

Subnet 192.168.10.0 netmask 255.255.255.0 { //network segment and mask to be assigned

Range 192.168.10.100 192.168.10.200; //Assigned address range

Option Domain-name-servers 1.1.1.1,2.2.2.2; //dns Server address if there are multiple addresses separated by ","

Option routers 192.168.10.1; //Default gateway

Option broadcast-address 192.168.10.255; //broadcast address

}

Host C3 { //host is optionally named after the hostname to be reserved

Hardware Ethernet 54:89:98:87:5a:28; //To keep the MAC address of the device separated by the ":" Format

Fixed-address 192.168.10.199; //To keep the IP address of the host

}


If you want to create multiple address pools, copy and paste the subnet field below.

------------------------------------------------------------------------------------------


To enable the DHCP service by using the service command

[[Email protected] dhcp]# service DHCPD start

Starting dhcpd: [ OK ]

[Email protected] dhcp]#

Note: Address segments within the address pool must have a section and the physical network card in the same network segment otherwise it won't start.

-------------------------------------------------------------------------------------------

View Client Addresses


650) this.width=650; "Title=" d}% (9_hsot[zru]l8pm[7xx.png "alt=" wkiom1aaktod_p63aabrabe0uhs134.png "src="/HTTP/ S4.51cto.com/wyfs02/m01/79/bf/wkiom1aaktod_p63aabrabe0uhs134.png "/>

650) this.width=650; "title=" Jwq1ygzt}) ap~ $C $lcs8rlo.png "alt=" wkiom1aakxjqu6y2aabnut8esag505.png "src="/HTTP/ S1.51cto.com/wyfs02/m02/79/bf/wkiom1aakxjqu6y2aabnut8esag505.png "/>

You can see that the address that the customer segment gets is all within the address pool range.

650) this.width=650; "title=" vk7f) ex1_3@z34htdq{syri.png "alt=" wkiol1aak9nyrf6saabm4anchto511.png "src="/http S3.51cto.com/wyfs02/m02/79/be/wkiol1aak9nyrf6saabm4anchto511.png "/>

C3 Gets the address that we manually reserved
------------------------------------------------------------

There are 4 DHCP messages for each:

Discover

Offer

Request

Ack


View DHCP 4 messages by crawling BOOTP messages

650) this.width=650; "title=" 77p4%hgiepeejto4py ' Fd53.png "alt=" wkiol1aalsmj70lhaabcfuw2cou760.png "src=" http:/ S2.51cto.com/wyfs02/m00/79/be/wkiol1aalsmj70lhaabcfuw2cou760.png "/>

4 messages from a DHCP server that can be seen by 4 messages for 2 unicast and 2 broadcasts and built under Microsoft are 4 broadcast messages!

650) this.width=650; "Title=" o@wcb6ek]n9) 6 ' mw{y0~%l5.png "alt=" wkiol1aanbkrceysaabukwynbxo620.png "src="/HTTP/ S3.51cto.com/wyfs02/m01/79/be/wkiol1aanbkrceysaabukwynbxo620.png "/>

By grabbing discover, you can see that the IP address of the three layer is "0.0.0.0" when the client does not have an address.

the port number for the four-tier DHCP message is: Server 67, client

650) this.width=650; "title=" 5x7~9b94ni) x6fd1y$[k% ' u.png "alt=" wkiom1aanfmb0xdmaab7bdyhdjs842.png "src=" http:/ S4.51cto.com/wyfs02/m00/79/bf/wkiom1aanfmb0xdmaab7bdyhdjs842.png "/>


650) this.width=650; "title=" _1~]41) p[v@) UN (}u (]ro{r.png "alt=" wkiom1aanl-rjvucaabx_yrozfc624.png "src="/HTTP/ S1.51cto.com/wyfs02/m01/79/bf/wkiom1aanl-rjvucaabx_yrozfc624.png "/> As can be seen from the request message, although it is a broadcast message, but the client has identified its own choice of DHCP server who

650) this.width=650; "title=" Untitled. png "alt=" Wkiol1aanffqbbqoaacwp6pbhlw907.png "src=" http://s1.51cto.com/wyfs02/M00 /79/be/wkiol1aanffqbbqoaacwp6pbhlw907.png "/>

This is the ACK message, the offer message has given the client all address information, but only after receiving an ACK, the information client can be used.


How DHCP works:

First, the client sends discover broadcast message, looks for the DHCP server!

Second, the DHCP received will send an offer message to respond to the client and assign an address to the client (the address of the client is not actually used), it can be understood that the server is asking the client this address you want?

Third, (if there are more than one server, the client uses only the first address received) the client will send a request broadcast message to ask for this address, because it is broadcast also told other servers I chose who.

Iv. The DHCP server responds to an ACK message after it receives a response to the client saying that I know you will use this address! (This is the only time the client can use this address)

This article is from the "Sunj" blog, make sure to keep this source http://sunjie123.blog.51cto.com/1263687/1735629

"Linux" DHCP server build!

Related Article

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.