Simple setup of DHCP server under Linux

Source: Internet
Author: User

1, DHCP Introduction:

Dynamic Host configuration Protocol. config protocol. is a LAN network protocol, using UDP protocol work, mainly has two purposes: to the internal network or network service providers automatically assigned IP address, to the user or internal network administrator as a means of central management of all computers.


The DHCP protocol adopts the client/server model, and the dynamic assignment task of host address is driven by the network host. When the DHCP server receives the information from the network host request address, it sends the related address configuration information to the network host to realize the dynamic configuration of the network host address information.

DHCP has the following features:

1. Ensure that any IP address can be used by only one DHCP client at the same time.

2. DHCP should be able to assign a permanent fixed IP address to the user.

3. DHCP should be able to coexist with hosts that obtain IP addresses in other ways (such as hosts that manually configure IP addresses).

4. The DHCP server should provide services to existing BOOTP clients.


Service mode: C/S ;

SERVER:DHCP Server (running DHCP service);

UDP: Monitoring 67

CLIENT:DHCP Client (running DHCP program);

UDP: Monitoring 68


2. Install and configure DHCP:

[[Email protected] ~]# service iptables stop

[Email protected] ~]# Setenforce 0: Turn off firewall and selinux;


[Email protected] ~]# ifconfig

Eth0 Link encap:ethernet HWaddr 00:0c:29:b2:b7:26
inet addr:192.168.57.172bcast:192.168.57.255 mask:255.255.255.128
Inet6 ADDR:FE80::20C:29FF:FEB2:B726/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:15489 errors:0 dropped:0 overruns:0 frame:0
TX packets:6489 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10154545 (9.6 MiB) TX bytes:594358 (580.4 KiB)

eth1 Link encap:ethernet HWaddr 00:0c:29:b2:b7:30
inet addr:1.1.1.1bcast:1.1.1.255 mask:255.255.255.0
Inet6 ADDR:FE80::20C:29FF:FEB2:B730/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:336 errors:0 dropped:0 overruns:0 frame:0
TX packets:76 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:66858 (65.2 KiB) TX bytes:21624 (21.1 KiB)

: Add a NIC eth1, which is reserved for use by the DHCP service. Eth0 location management use;


[[email protected] ~]# yum-y Install DHCP: installing DHCP service;

[Email protected] ~]# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample/etc/dhcp/dhcpd.conf
CP: Do you want to overwrite "/etc/dhcp/dhcpd.conf"? Y
[[Email protected] ~]#: Copy a DHCPD configuration file example to a fixed location;


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

Dhcpd.conf can be roughly divided into four regions: (; semicolon-end)

1 , define the working properties of the DHCPD itself:

Log-facility: Log facilify;

2 , Global Address Assignment properties: option (globally valid, does not affect subnet)

Note: ("The smaller the scope, the greater the priority, the greater the scope , the smaller the priority ")

Option router: assigning a gateway;

The global priority is less than the priority of the scope;

Equivalent to the default configuration;

3 , subnet configuration: (" the smaller the scope, the greater the priority, and the greater the scope, the smaller the priority level. ")

Usually each scope is defined by a subnet;

Subnet Network_address netmask netmask {

Address pool (range), Gateway, DNS

}

Note: The priority of the scope takes precedence over the global priority;

4 , host configuration:

A fixed address is usually assigned to a specific MAC address;

Host ' host ID ' {

Mac IP Address

}

Note: The reserved host address, do not appear in any other address pool, otherwise it will conflict;


Example 1: define a pool of DHCP addresses, using 1.1.1.0/24 network segments, the address range to be sent to the client is:1.1.1.2-1.1.1.10, the gateway is 1.1.1.1:

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

Subnet 1.1.1.0 netmask 255.255.255.0 {
Range 1.1.1.2 1.1.1.10;
Option routers 1.1.1.1;
}

[[Email protected] ~]# service DHCP Restart: Restart the DHCP service;


[Email protected] ~]# Ps-aux | grep DHCP
Warning:bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.8/faq
DHCPD 27398 0.0 0.2 49088 4044? Ss 23:03 0:00/usr/sbin/dhcpd-user Dhcpd-group dhcpd
Root 27403 0.0 0.0 103256 844 pts/0 s+ 23:05 0:00 grep DHCP
[[Email protected] ~]#: view DHCP process;


Find a windowns machine, set up the network card to obtain the IP address automatically:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5C/25/wKioL1UbsSyDugrqAAI3KH5mTzs823.jpg "title=" 2.jpg " alt= "Wkiol1ubssydugrqaai3kh5mtzs823.jpg"/>


Example 2: Configure DHCP to reserve a fixed address for a specific address;

1, determine the fixed IP card MAC address, this is 0050-56c0-0002

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5C/2A/wKiom1UbsY_j2a4AAAJeZAX10lY877.jpg "title=" 3.png " alt= "Wkiom1ubsy_j2a4aaajezax10ly877.jpg"/>


2. Edit the DHCP master configuration file:

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

Host Test {
Hardware Ethernet 00:50:56:c0:00:02;
Fixed-address 1.1.1.10;
Option routers 1.1.1.1;
Option Domain-name "test.com";
Option Domain-name-servers 202.96.209.133;
The implementation will 1.1.1.10 this IP address to the MAC address of 0050-56c0-0002 host;


[[Email protected] ~]# service DHCPD force-reload: overloaded DHCP configuration file;

Reboot the test network card on the Windows machine;

[[email protected] ~]# tail-f/var/log/boot.log: Dynamic observation of DHCP service IP delivery process;

APR 1 23:38:24 localhost dhcpd:uid lease 1.1.1.2 for client 00:50:56:c0:00:02 are duplicate on 1.1.1.0/24
APR 1 23:38:24 localhost dhcpd:dhcpdiscover from 00:50:56:c0:00:02 via eth1
APR 1 23:38:24 localhost dhcpd:dhcpoffer on 1.1.1.10 to 00:50:56:c0:00:02 via eth1
APR 1 23:38:24 localhost dhcpd:uid lease 1.1.1.2 for client 00:50:56:c0:00:02 are duplicate on 1.1.1.0/24
APR 1 23:38:24 localhost dhcpd:dhcpdiscover from 00:50:56:c0:00:02 via eth1
APR 1 23:38:24 localhost dhcpd:dhcpoffer on 1.1.1.10 to 00:50:56:c0:00:02 via eth1
APR 1 23:38:24 localhost dhcpd:dynamic and static leases present for 1.1.1.10.
APR 1 23:38:24 localhost dhcpd:remove host declaration test or Remove 1.1.1.10
APR 1 23:38:24 localhost dhcpd:from The dynamic address pool for 1.1.1.0/24
APR 1 23:38:24 localhost dhcpd:uid lease 1.1.1.2 for client 00:50:56:c0:00:02 are duplicate on 1.1.1.0/24
APR 1 23:38:24 localhost dhcpd:dhcprequest for 1.1.1.10 (1.1.1.1) from 00:50:56:c0:00:02 via eth1
APR 1 23:38:24 localhost dhcpd:dhcpack on 1.1.1.10 to 00:50:56:c0:00:02 via eth1


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5C/25/wKioL1UbtQWTJDwNAAImRiMP20g236.jpg "title=" 4.png " alt= "Wkiol1ubtqwtjdwnaaimrimp20g236.jpg"/>


OK,IP address successfully fixed allocation;


end;

This article is from "Linux Ops collection" blog, please make sure to keep this source http://5200linux.blog.51cto.com/6012970/1627388

Simple setup of DHCP server under Linux

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.