DHCP server setup under Linux

Source: Internet
Author: User
Tags ack

1. What is DHCP

DHCP is the Dynamic Host Configuration Protocol, where the DHCP server can dynamically assign IP addresses, subnet masks, gateways, and DNS information to clients. It is mainly used for dynamically assigning IP addresses to all computers in the LAN.

2. dhcp-Work Flow

1) The DHCP client sends the DHCP Discover packet in the LAN, and every computer with the TCP/IP protocol installed in the LAN can receive the packet, and the computer is discarded by the DHCP server only to respond.

2) When DHCP receives a DHCP Discover packet, it picks up an IP address from the address pool that has not yet been leased, and then attaches other related settings to the network segment in the form of a DHCP offer broadcast.

3) If there are multiple DHCP servers in a local area network, these DHCP servers will respond to the client after receiving the DHCP Discover packet, the client only accepts the information provided by the first DHCP offer received, and then sends the DHCP in a broadcast manner. Request data Packet, requesting the server to assign a change address. The client also sends an ARP broadcast packet, queries whether there are other clients on the network using the IP address, if the IP address is found to be occupied, sends a DHCP decline packet to the server, rejects the receiver DHCP offer, and re-broadcasts the DHCP Discover data packets.

4) When the DHCP server receives DHCP request information from the client, it sends a DHCP ACK packet containing the IP address and other settings to the client, which is also sent as a broadcast, and the lease is formally in effect. The DHCP server that is not selected wants to reclaim the IP address that was issued.

5) After each time the DHCP client logs on to the network, it does not need to send the DHCP Discover discovery information, but instead sends the DHCP request information directly containing the IP address assigned to it the previous time. When the DHCP server receives this information, it attempts to have the DHCP client continue to use the original IP address and to answer a DHCP ACK acknowledgment message. If this IP address is no longer available to the original DHCP client, the DHCP server answers a DHCP nack denial message to the DHCP client. When the original DHCP client receives this DHCP Nack denial information, it must resend the DHCP Discover discovery information to request a new IP address.

6) The DHCP server leases the IP address to the DHCP client generally has a lease period, after the expiry of the DHCP server will recover the leased IP address. If the DHCP client wants to extend its IP lease, it must update its IP lease. DHCP clients automatically send information to the DHCP server to update their IP leases when the DHCP client starts and the IP lease period is over half.


Let's look at how to build a DHCP server on centOS6

First you need to install a DHCP package

[[email protected] yum.repos.d]# yum install dhcp-y &[1] 2251

After installation, there are a few files that need attention.

/etc/dhcp/dhcpd.conf #dhcpd服务的配置文件

/var/lib/dhcpd/dhcpd.leases #租约数据库文件, information about the lease is kept here.

/ETC/SYSCONFIG/DHCPD #配置dhcp服务监听的端口

/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample #dhcpd服务的配置文件样例


In the configuration link is mainly to/etc/dhcp/dhcpd.conf this file for the relevant configuration, in order to save trouble, you can directly copy the/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample, and then make the corresponding changes.

Examples of/etc/dhcp/dhcpd.conf

 #全局配置option  domain-name  "baby.com";option  domain-name-servers 114.114.114.114;default-lease-time 600;max-lease-time 7200;option  routers 192.168.10.1;log-facility local7; #局部配置 to service a specified network segment subnet 192.168.10.0 netmask  255.255.255.0 {   range 192.168.10.199 192.168.10.255;   option  routers 192.168.10.1;   option broadcast-address 192.168.10.255;     #该网段中, bind the IP address for the specified client    host local1 {       hardware ethernet 00:0c:29:82:43:8a;      fixed-address  192.168.10.119;   }} #为指定客户机绑定IP地址host  local2 {       hardware ethernet 00:0c:29:83:65:3c;      fixed-address  192.168.10.120;   } 

Common parameters:

Option Domain-name #域名搜索列表 similar to search in/etc/resolv.conf

Option Domain-name-servers #域名服务器地址, multiple words separated by commas

Option Routers #网关

Option Broadcasst-address #广播地址

Option Subnet-mask #子网掩码

Default-lease-time #默认租约期限, generally this entry takes effect (in seconds)

Max-lease-time #最大租约期限 (in seconds)

Log-facility #日志存储文件

Range start_ip end_ip #地址池 (multiple range can be specified in subnet, but multiple range defined IP ranges cannot be duplicated)


General statement:

Subnet NETWORK netmask MASK {...} #局部配置, services for a specified network segment

Host hostname {...} #为指定客户机绑定IP地址 (this is usually written in subnet)
Parameters in Host:

Hardware Ethernet #mac地址
Fixed-address #为其绑定的ip地址

After configuring the above information, it is best to specify the port that the DHCPD service listens on in/ETC/SYSCONFIG/DHCPD, and after the configuration is complete, you can use the related commands to check the configuration correctly.

[Email protected] yum.repos.d]# service DHCPD Configtestsyntax:ok

If the display Syntax:ok, it means that the configuration does not exist syntax errors, if the error, according to the prompt correction.

[[email protected] yum.repos.d]# service dhcpd force-reloadshutting down  dhcpd:                                         [  OK  ]Starting dhcpd:                                               [  ok  ][[email protected] yum.repos.d]# ss -tunpl....udp    UNCONN     0      0              *:67             *:*       users: (("DHCPD", 2441,7) .... 

Service has been started, look at the effect:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/3F/wKiom1VB6z-AvWKsAAA7clDaIS0668.jpg "title=" V} Z8X9SU6RC0_QY2PAT@WRN.png "alt=" Wkiom1vb6z-avwksaaa7cldais0668.jpg "/>

[[Email protected] ~]# ip addr show eth02: eth0: <broadcast, multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state up qlen 1000     link/ether 00:0c:29:17:01:eb brd ff:ff:ff:ff:ff:ff     inet 192.168.10.199/24 brd 192.168.10.255 scope global eth0     inet6 fe80::20c:29ff:fe17:1eb/64 scope link         valid_lft forever preferred_lft forever[[email protected] ~]# ip  route list192.168.10.0/24 dev eth0  proto kernel  scope  Link  src 192.168.10.199 169.254.0.0/16 dev eth0  scope link   metric 1002 default via 192.168.10.1 dev eth0 [[email  Protected] ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-scriptsearch baby.comnameserver  114.114.114.114

The client's configuration is consistent with the settings in the server-side configuration file, and then another client, whose IP address is bound to its MAC address

[[Email protected] ~]# IP addr Show eth02:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU qdisc pfifo_fast State U P qlen link/ether 00:0c:29:82:43:8a brd ff:ff:ff:ff:ff:ff inet 192.168.10.119/24 BRD 192.168.10.255 Scope Globa L eth0 inet6 fe80::20c:29ff:fe82:438a/64 scope link Valid_lft forever Preferred_lft forever

Ok................

DHCP server setup under Linux

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.