Set up DHCP service in CentOS7

Source: Internet
Author: User

Set up DHCP service in CentOS7

I set up the DHCP service to use CentOS 7.0.1406 with the core version 3.10.0-123. el7.x86 _ 64. The CentOS system is installed on the virtual machine, and then connected to the virtual network set up in GNS 3 through the Virtual Network Card. The entire network topology is as follows:

It doesn't matter if you don't know exactly how the CentOS System in the virtual machine is connected to the virtual network in GNS 3, just think of the PC marked as a virtual machine as a server running CentOS 7. This article only introduces how to set up the DHCP service on CentOS 7, and does not introduce the usage and network knowledge of GNS 3.

To set up the DHCP service, follow these steps:

1. Install DHCP Software

Run the following command to install the DHCP software:Yum install dhcp

After the installation is complete, you can see the dhcp. x86_64 software, as shown in. The other two software (dhcp-common.x86_64 and dhcp-libs.x86_64) is installed together.

2. Set the configuration file/etc/dhcp/dhcpd. conf

After installing the DHCP software, you need to set the configuration file/etc/dhcp/dhcpd. conf. To set the configuration file dhcpd. conf, You can first look at the file/usr/share/doc/dhcp */dhcpd. conf. example, which contains some examples and simple instructions. You can also use the command man 5 dhcpd. conf to view more details.

In my case, I set dhcpd. conf as follows:

Else ---------------------------------------------------------------------------------------------------------------------------------

[Root @ localhost ~] # Vim/etc/dhcp/dhcpd. conf

Authoritative;

Default-lease-time600;

Max-lease-time7200;

Optiondomain-name "test.com ";

Optiondomain-name-servers 114.114.114.114;

#

# Authoritative indicates that the DHCP server is the official DHCP server of the service network segment. In general, you need to set authoritative in the configuration file. If you do not set it, there may be some problems.

# Default-lease-time sets the default lease validity period, in seconds. If the client does not require a lease validity period when requesting an IP address, the DHCP server sets the lease validity period to this value.

# Max-lease-time, in seconds. In laruence's book, this value is to set the maximum lease validity period that the client can request, rather than the maximum time that the client can use an IP address. The man document also explains "Time shocould be the maximumlength in seconds that will be assigned to a lease", but I'm not sure what this means.

# Optiondomain-name: Set the domain name.

# Optiondomain-name-servers: Set the DNS server. Here, only one DNS server is set. You can also set two. For the format, see/usr/share/doc/dhcp */dhcpd. conf. example.

#

Subnet172.31.3.0 netmask 255.255.255.0 {

Range 172.31.3.10 172.31.3.200;

Option routers 172.31.3.254;

Option broadcast-address 172.31.3.255;

}

Host pc2 {

Hardware ethernet 00: 50: 79: 66: 68: 01;

Fixed-address 172.31.3.201;

}

#

Subnet172.31.1.0 netmask 255.255.255.0 {

Range 172.31.1.10 172.31.1.200;

Option routers 172.31.1.254;

Option broadcast-address 172.31.1.255;

}

Host pc4 {

Hardware ethernet 00: 50: 79: 66: 68: 03;

Fixed-address 172.31.1.201;

}

Host pc5 {

Hardware ethernet 00: 50: 79: 66: 68: 04;

Fixed-address 172.31.1.202;

}

#

# The subnet statement specifies the subnet and subnet mask.

# The range statement specifies the range of IP addresses that can be dynamically allocated.

# The option routers statement specifies the gateway address.

# Optionbroadcast-address specifies the broadcast address. I'm not sure if it is necessary to set it. In my virtual network, it can run normally without setting it. But in the actual network, I don't know if there will be any problems if I don't set it.

# The host statement can assign a fixed IP address (the value set by fixed-address) to the host with the specified MAC address (the value set by hardware ethernet ). The host is followed by a name (for example, pc2). This name can be set at will and does not need to be consistent with the actual host name, however, this name must be unique in this configuration file.

Else ---------------------------------------------------------------------------------------------------------------------------------

3. Start the dhcpd Service

After setting the configuration file, start the dhcpd service. Run the following command:Systemctl start dhcpd. service

If there is no problem, the DHCP server will be deployed. In this case, you can view the dhcpd listening port 67, as shown in:

If the service fails to be started, you can view the/var/log/messages log file (use the command cat/var/log/messages | grep dhcp ), default DHCP logs are recorded in this file. To view the allocated IP address, you can view the file/var/lib/dhcpd. leases, but it seems that only the dynamically assigned IP addresses are recorded, rather than fixed IP addresses (such as 172.31.3.201 in the preceding configuration file), even if the IP address has been allocated. As mentioned above, for more detailed configuration information about the configuration file dhcpd. conf, see the man document (use the command man 5 dhcpd. conf ). To learn more about the options in the configuration file dhcpd. conf, view another man document (use the command man 5 dhcp-options ).

To view the service status, run systemctl statusdhcpd. service. To stop the DHCP service, run the systemctl stop dhcpd. service Command. After modifying the configuration file, you can run the systemctl restart dhcpd. service command to make the configuration file take effect. Of course, in the actual production environment, you cannot change the configuration file and restart the DHCP service at will. Instead, you must use the omshell Command, as stated in the official document, this command can change the configuration without suspending the service.

4. Set Service Startup

To enable the dhcpd service to start up, run the following command:Systemctl enable dhcpd. service.

If you want to check whether the service is set to boot, run the systemctl list-unit-files command. To cancel service startup, run systemctldisable dhcpd. service.

5. check and test

As of above, all configurations have been completed. Finally, check whether the client can obtain the IP address through DHCP:

As you can see, all clients can obtain the IP address normally, and the subnet mask and gateway are also correct.

Note: many of the above information is mainly from the official documents of RedHat. Please refer to the privacy Guide for instructions on how to set up a DHCP server. If you are interested, please refer to it.

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.