Article Title: Linux as DHCP Server 3. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
3. dhcpd. leases
Dhcpd. leases is the database file of the DHCP Client lease. The default directory is/var/state/dhcp/. The file contains the lease statement. Each lease is obtained, updated, or released, its new value is recorded at the end of the file. This file is not generated after the first installation of DHCPd. However, this file is required for running DHCPd, so an empty file can be created.
# Touch/var/state/dhcp/dhcpd. leases
The format of the DHCPd file is
Lease ip-address {statements ...}
Each record contains an IP address provided to the customer, and the statement in curly brackets contains some lease information. The specific lease information varies slightly because the customer sends different DHCP requests.
4. Run DHCPd
To start DHCPd, simply type/usr/sbin/dhcpd or use ntsysv to automatically start the DHCPd service. You can also use
/Etc/rc. d/init. d/dhcpd start,
In this way, DHCPd is started on eth0. If the server on DHCPd has another network card eth1, you want to start it on eth1.
Dhcpd, enter
#/Usr/sbin/dhcpd eth1
The dhcpd in the above example. conf to start dhcpd. If we start a Windows 95 machine and specify the automatically obtained IP address in the TCP/IP option of the Windows 95 network configuration, that is, to enable the DHCP Client Program in Windows 95, the host name of this 95-host is ONE. After entering the system, use winipcfg to view the host name.
After the Windows 95 server obtains the lease, DHCPd creates a record in dhcp. leases.
Note that the time record of dhcpd. leases adopts the GMT time instead of the local time zone. To view the GMT time of the local machine, you can use
Date-u
5. Further descriptions of dhcpd. conf
5.1 overview of dhcpd. conf
As mentioned above, dhcpd. conf is a configuration file in recursive descent format. It is a bit like C's source program style. It is constructed by parameters and declarations.
Yes, the parameter statements mainly tell DHCPd network parameters, such as the lease time, gateway, DNS, and so on, while the declaration statement describes the network topology,
It indicates the customer on the network, the IP address to be provided to the customer, and a parameter group to a group of declarations.
The statements describing the network topology are shared-network and subnet .. If you want to dynamically specify IP addresses for customers in a subnet
The subnet declaration must contain a range declaration to describe the address range. If you want to statically specify an IP address for the DHCP client
Each such customer must have a host statement. Each subnet connected to the DHCP server to provide services must have a subnet
Declare that this is a subnet that does not have an IP address to be dynamically allocated.
A typical dhcpd. conf is as follows:
# Example
# Global Parameters
Shared-network shared network name {
Shared network parameters...
Subnet 204.254.239.0 netmask has been released successfully {
Specific subnet parameters...
Range 204.254.239.10 204.254.239.30;
}
Subnet 204.254.239.32 netmask has been released successfully {
Specific subnet parameters...
Range 204.254.239.42 204.254.239.62;
}
}
Subnet 204.254.239.64 netmask has been released successfully {
Specific subnet parameters...
Range 204.254.239.74 204.254.239.94;
}
Group {
Group-specific parameters...
Host ws1.domain {
Specific host parameters...
}
Host ws2.domain {
Specific host parameters...
}
Host ws3.domain {
Specific host parameters...
}
}
5.2 statement reference
Because many DHCPd statements cannot be listed one by one, the most common and important statements are provided here.
Declaration statements
Share-network Statement
Shared-network name {
[Parameters]
[Statement]
}
Share-network is used to tell the DHCP server that some IP subnets actually share the same physical network. Any subnet in the shared physical network must be declared in the share-network Statement. When a customer in the sub-network starts, it will get the specified parameters in the share-network Statement, unless these parameters are overwritten by parameters in subnet or host. Share-network is A suitable option. For example, if A company uses A Class B network of 145.252, department A of the company is allocated to the subnet 145.252.1.0, And the subnet mask is 255.255.255.0, here, the subnet number is 8 bits and the host number is also 8 bits. However, if Department A grows rapidly and exceeds 254 nodes, the physical network cannot be increased, we need to run two 8-bit netmask subnets on the original physical network, and the two subnets are actually on the same physical network,
The share-network statement can be as follows:
Shared-network share1 {
Subnet 145.252.1.0 netmask 255.255.255.0 {
Range 145.252.1.10 145.252.1.253;
}
Subnet 145.252.2.0 netmask 255.255.255.0 {
Range 145.252.2.10 145.252.1.253;
}
Share1 is a shared network name.
Subnet statement:
Subnet-number netmask {
[Parameters]
[Statement]
}
The subnet statement is used to provide sufficient information to determine whether an IP address belongs to the subnet. You can also provide the specified subnet parameters and specify the IP addresses that belong to the subnet that can be dynamically allocated to the customer. These IP addresses must be specified in the range declaration. Subnet-number can be an IP address or a domain name that can be resolved to the subnet number of this subnet. Netmask can be an IP address or a domain name that can be resolved to the subnet mask.
Range statement:
Range [dynamic-bootp] low-address [high-address];
In any subnet statement with a dynamically assigned IP address, at least one range statement is required to specify the range of the IP address to be allocated. If only one IP address is specified, the high IP address can be omitted.
Host statement:
Host hostname {
[Parameters]
[Statement]
}
The host statement is used to provide network information for specific clients.
Group Statement
Group {
[Parameters]
[Statement]
}
Group statements provide parameters for a group of declarations.
Allow and deny statements
The allow and deny statements are used to control the request of DHCPd to the customer.
Unknown-clients keyword
Allow unknown-clients;
Deny unknown-clients;
Allow unknown-clients allows DHCPd to dynamically allocate IP addresses to unknown customers, while deny unknown-clients does not.
The default value is allowed.
Bootp keywords
Allow bootp;
Deny bootp;
Specifies whether the DHCPd responds to the bootp query. this parameter is allowed by default.
Parameter statements
Default-lease-time statement
Syntax
Default-lease-time;
Specify the default lease time, in seconds. If the DHCP client requests a lease but does not specify the expiration time, the lease time is the default lease time.
Max-lease-time statement
Syntax
Max-lease-time;
The maximum lease time. If DHCP sends a request for a specific lease expiration time when requesting the lease time, the maximum lease time is used.
Hardware statement
Syntax
Hardware-type hardware-address;
Specify the physical hardware interface type and hardware address. The hardware address consists of six eight-bit groups, each of which is separated by a comma. For example, 00: 00: E8: 1B: 54: 97
Example: hard
Server-name statement
Server-name "name ";
The name used to tell the customer server.
Fixed-address statement
Fixed-address [, address...];
The fixed-address statement is used to specify one or more IP addresses for a DHCP client. It can only appear in the host declaration.
Option statements
The option-class statement starts with option, followed by an option name. The option name is followed by option data and there are many options. Some common options are listed here for reference.
Option routers ip-address [, ip-address];
Specifies the IP address of the vro in the customer's subnet. There can be multiple IP addresses;
Specify the host name for the customer. string is a string.
Option domain-name string;
Specify Domain Name
Option interface-mtu;
Indicates the MTU in the network. Here, mtu is a positive integer.
Example option interface-mtu 1500;
Option broadcast-address ip-address;
Broadcast address
Vi. Summary
The above are common DHCPd configurations. In actual DHCP Application, some policy issues related to IP Address Allocation should also be taken into account. At the same time, to ensure the robustness of the network, at least two DHCP servers must work together, if one fails, the other can continue
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