Construction of DHCP server under Linux

Source: Internet
Author: User
Tags system log uuid

1. Turn off the firewall and SELinux

[[Email protected]/]# service iptables stop

[email protected]/]# Vim/etc/selinux/config

Selinux=permissive (change enforcing to permissive) save exit

2. Prepare two virtual machines, one as the server and one as the client, and configure the IP addresses of the two hosts to enable the server and the client to communicate

Server:

[Email protected]/]# Vim/etc/sysconfig/network-scripts/ifcfg-eth0

Device=eth0

hwaddr=00:0c:29:a9:a0:68

Type=ethernet

Uuid=65d53814-182d-44ec-a0df-a0712c196aeb

Onboot=yes

Nm_controlled=no

Bootproto=none

ipaddr=192.168.4.5

netmask=255.255.255.0

Ipv6init=no

Userctl=no

Client:

[Email protected]/]# Vim/etc/sysconfig/network-scripts/ifcfg-eth0

Device=eth0

Hwaddr=00:0c:29:fe:4b:36

Type=ethernet

Uuid=65d53814-182d-44ec-a0df-a0712c196aeb

Onboot=yes

Nm_controlled=no

Bootproto=none

ipaddr=192.168.4.205

netmask=255.255.255.0

Ipv6init=no

Userctl=no

3. Install the DHCP service on the server

[[email protected]/]# yum-y Install DHCP

[[email protected]/]# rpm-q DHCP

Dhcp-4.1.1-38.p1.el6.x86_64

Ensure that the DHCP service is successfully installed

4. Modify the DHCP configuration file on the service

[email protected]/]# vim/etc/dhcp/dhcpd.conf

Default-lease-time 600; #默认租约时间600s

Max-lease-time 7200; #最大租约时间7200s

Subnet 192.168.4.0 netmask 255.255.255.0{#设置IP地址的作用域是192.168.4.0 Network Segment

Option routers 192.168.4.1; #设置分配的网关

Option Domain-name "tarena.com"; #设置默认搜索域

Option Domain-name-servers 202.106.0.20,8.8.8.8; #设置DNS地址

Range 192.168.4.28 192.168.4.54; #分配的IP地址范围

Range 192.168.4.128 192.168.4.200;

}

Host Fantasia {#保留地址, assigning IP addresses to specific hosts

Hardware Ethernet 00:0c:29:fe:4b:36;

Fixed-address 192.168.4.110;

}

Note: When modifying a configured file, you can open the /usr/share/doc/dhcp*/dhcpd.conf.sample reference configuration format, and you can also use the man dhcpd.conf To view the Help manual for a configuration file

5. Restart the service and set the boot from

[Email protected]/]# service DHCPD restart

[Email protected]/]# chkconfig dhcpd on

Note: If the service fails to start, it must be an error in the configuration file, you can check the document, or go to the system log by viewing the command less/var/log/messages to find out where the error is.

19:25:18 ser5 dhcpd:/etc/dhcp/dhcpd.conf line 13:semicolon expected.

19:25:18 Ser5 Dhcpd:range

19:25:18 ser5 dhcpd: ^

19:25:18 ser5 dhcpd:configuration File errors encountered--exiting

19:25:18 Ser5 dhcpd:

19:25:18 ser5 dhcpd:this version of ISC DHCP is based on the release available

19:25:18 ser5 dhcpd:on ftp.isc.org. Features has been added and other changes

You know the error is around line 13th of the configuration file

To restart the service after changing the configuration file

6. Authenticate with the client

[email protected]/]# dhclient-d eth0

Internet Systems Consortium DHCP Client 4.1.1-p1

Copyright 2004-2010 Internet Systems Consortium.

All rights reserved.

For info, visit https://www.isc.org/software/dhcp/


Listening on lpf/eth0/00:0c:29:fe:4b:36

Sending on lpf/eth0/00:0c:29:fe:4b:36

Sending on Socket/fallback

DHCPDISCOVER on eth0 to 255.255.255.255 port interval 7 (xid=0x5bef1d5e)

DHCPOFFER from 192.168.4.5

DHCPREQUEST on eth0 to 255.255.255.255 port (xid=0x5bef1d5e)

DHCPACK from 192.168.4.5 (xid=0x5bef1d5e)

Bound to 192.168.4.110 – renewal in 289 seconds.

This command dynamically verifies that the client obtains the IP address of the entire process, the address obtained through DHCP is 192.168.4.110

7. View lease Information

Server:

[Email protected]/]# cat/var/lib/dhcpd/dhcpd.leases

# The format of this file was documented in the Dhcpd.leases (5) manual page.

# This lease file is written by Isc-dhcp-4.1.1-p1


Lease 192.168.4.28 {

Starts 2 2014/08/12 06:50:35;

Ends 2 2014/08/12 07:00:35;

TSTP 2 2014/08/12 07:00:35;

CLTT 2 2014/08/12 06:50:35;

binding state free;

Hardware Ethernet 00:0c:29:fe:4b:36;

}

Server-duid "\000\001\000\001\033|u\227\000\014) \251\240h";

Can see the IP address information that the server rents out

Client:

[Email protected]/]# cat/var/lib/dhclient/dhclient-ethn.leases

Internet Systems Consortium DHCP Client 4.1.1-p1

Copyright 2004-2010 Internet Systems Consortium.

All rights reserved.

For info, visit https://www.isc.org/software/dhcp/


Listening on lpf/eth0/00:0c:29:fe:4b:36

Sending on lpf/eth0/00:0c:29:fe:4b:36

Sending on Socket/fallback

DHCPDISCOVER on eth0 to 255.255.255.255 port interval 7 (xid=0x5bef1d5e)

DHCPOFFER from 192.168.4.5

DHCPREQUEST on eth0 to 255.255.255.255 port (xid=0x5bef1d5e)

DHCPACK from 192.168.4.5 (xid=0x5bef1d5e)

Bound to 192.168.4.110 – renewal in 289 seconds.

^c

To view the IP leases that have been acquired


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.