Linux Configuration DHCP Server Concise tutorial Detailed

Source: Internet
Author: User
Tags centos

DHCP Introduction

function Introduction

DHCP is a protocol based on UDP that works at the application level and is used to automatically assign IP addresses.
Application Example: There are 10 people in an office, each day to work with their own notebook, so each time to manually configure the IP address, so it is simply not the computer to do the thing is it. Therefore, DHCP came into being, it can automatically assign IP addresses to clients connected to the network according to the configuration of the server.
The services provided

1. Provide IP address and subnet mask
2. Provide the IP address corresponding to the network address and broadcast address
3. Default gateway Address
4.DNS server Address
A popular explanation

There are six people in your dorm room (corresponding to the client), everyone needs to sleep with the bed (corresponding to the IP address), so everyone will need a bed to go back to the bedroom. In this way, every time you go back to the dormitory, you need to have a bed (corresponding to the network administrator) need to assign him a bunk, which is very troublesome.
Now there is a "Dynamic Bed allocation system" (corresponding to the DHCP server), each of you get back to the bedroom will receive a note, the note said you can use which bed, this is much simpler.
Then maybe xiaoming (corresponding to a particular client) is a neat freak and needs a fixed bed (corresponding to a device that requires a fixed IP, such as a printer or a server that provides some services). So "Dynamic bed allocation system" can add a rule "called Xiao Ming's people to assign to his third bed", it solved the problem.
Lease time

The IP assigned to the client by DHCP is assigned as a lease. When the client is connected to the network, DHCP assigns an IP to the client, and if the client is still using the IP when the lease time is up, it can renew it and continue using the current IP instead of the new one.
Build DHCP service under CentOS 7.x

0X00 Install DHCP Service

Use Yum, rpm, source code and other methods to install
Yum Install DHCPD
0X01 Configure Server network services

First we want to configure the local network as a static address, and restart the network Service
VIM/ETC/SYSCONFIG/NETWORK-SCRIPTS/ENP0S3
Here enp0s3 is My network card, you need to modify this to your network card, and also In the previous version of CentOS 7.x, the ETHX was used in the naming method.
Modify the following
Bootproto=static #之前很有可能是dhcp, now we modify it to static
onboot=yes       # It may have been no before, yes, that is, when you open the Network service, start the NIC
ipaddr=192.168.233.1 #配置文件中可能没有这个, add this line yourself if you don't have it
# The IP address here can be customized, but the last one is best 1, This makes it easy to identify the
and then restart the Network service, and if the configuration file is correct, you can start the
systemctl restart Network.service
This time we check to see if IP has become the static IP we set.
Ifconfig ENP0S3
0X02 Configure the DHCP service

Configuration file here
vim/etc/dhcp/dhcpd.conf
Open There will be three lines of comments, we first learn to configure the time we can ignore it, only the service really run up and come into effect we will further study is it.
Add the following at the end of the configuration file
#设置DHCP于DNS服务器的动态信息更新模式. The initial class can ignore this option, but the global setting must have this option, otherwise the DHCP service will not start successfully.
Ddns-update-style Interim;
#下面开始分配子网, the network segment is the 192.168.233.0 subnet mask is a 255.255.255.0
#不能理解网段和子网掩码的可以去网上查一下. Simply said that the network segment specified the allocation of IP segments (assigning which section of IP to the client), the subnet mask specified the size of the network segment
Subnet 192.168.233.0 netmask 255.255.255.0 {
    Range 192.168.233.100 192.168.233.199; #分配给客户机的IP从192.168.233.100 start to 192.168.233.199
    option routers 192.168.233.2; #设置网关
     Default-lease-time 600; #默认租约时间
    max-lease-time 7200; #最大租约时间
}
0x03 assign specific addresses to specific customers

As mentioned above, if you have a device in the same network that requires a fixed IP, we can also assign him a fixed IP through DHCP. (for example, the one with a neat freak)
Let's start by saying how DHCP recognizes hosts:
DHCP by accessing the customer's network card MAC address to judge the customer, so if your machine has two network cards, and two network cards are connected to the Internet, then DHCP will think that there are two devices connected to the network, and give your machine to allocate two IP
MAC address is not "apple address" ...
MAC address is "Physical address", each card in the factory will have a unique global MAC address, MAC address is a 48-bit 2-digit number, usually expressed as six segment two hexadecimal.

Let's continue to modify the DHCP configuration file and append the following after the configuration
Host Client_c {#有一个主机, called Client_c
Hardware Ethernet 08:00:27:5e:04:27; #MAC地址是08:.: 27 Network card
Fixed-address 192.168.233.123; #分配给它192.168.233.123 IP
}
This configuration, whenever, as long as this client_c access to the network, then it gets the IP is fixed this one, and will not change
And then restart the DHCP service.
Systemctl Restart Dhcpd.service
Okay, so this is the basic configuration 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.