Configuration of the DHCP server in linux (group chart)
Source: Internet
Author: User
Article Title: configuration of the DHCP server in linux (group chart ). 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.
Linux is mainly used on servers. As a server, Web, dhcp, and dns are the most important services on the Internet, I will discuss dhcp applications with my friends.
(Note: to configure a network server, if you choose to install or use a VM to bridge the network in the existing network environment, it may affect your current network environment, consult your network administrator before configuration .)
What is dhcp?
Dhcp (dynamic host configuration protocol) is a dynamic host Allocation protocol. It is used to dynamically allocate IP addresses and configure related network environments to hosts in a network segment, for example, we use the dhcp protocol for adsl dialing.
I. Common concepts of dhcp.
1. Scope:
The scope is the continuity of IP addresses that can be allocated in a network.
2. Super Scope
A super scope is a set of scopes. Is composed of multiple IP subnets in a physical subnet. We can understand that the scope is a user, and the super scope is the user group.
3. Scope of exclusion
The exclusion scope is used to define an IP address or a group of IP addresses that are not assigned to a dhcp client.
4. address pool
After the dhcp scope and exclusion scope are defined, the remaining available addresses constitute an address pool. Addresses in the pool can be allocated to users.
5. Lease
It is the length of time specified by the dhcp server. Within this length, the client can use the address assigned to it. If the lease expires, the client must update the ip lease.
6. Reserved address
You can use reserved addresses to associate dynamic addresses with their MAC addresses. It is used to ensure that the network card uses an IP address for a long time.
7. Option type.
This is another parameter that DCHP provides for the workstation, such as the IP address of the gateway and the dns server.
Here we only introduce some basic concepts of dhcp, because we mainly introduce how to configure these services in linux. So if you want to learn more about dhcp or the following services (dhcp in linux is the same as dhcp in win), you can refer to networks or books.
Ii. Dhcp settings
First install the dhcp service. If you did not select the dhcp component during the first installation, you can find the relevant software on the installation disc of your release and the rpm deletion package to install it, alternatively, you can find the binary rpm release package for the dhcp-3.0p11-23.i386.rpm under/RedHat/RPMS/on the second disc for installation, with the same effect after installation.
Then insert the installation disk as prompted during the update.
Remind friends again that in linux, all program configurations are controlled by text files. Therefore, we need to set up a dhcp server to modify the configuration file.
So let's take a look at its typical configuration file.
The dhcp configuration file is/etc/dhcpd. conf, but this file does not exist by default. You need to use its template to create a configuration file. Template location in/usr/share/doc/dhcp-3.0p11/dhcpd. conf. sample
If you cannot find your configuration file, you can use the search command we have learned, locate filename for search,
After finding this file, Let's first look at the template configuration.
For convenience, I used the cat command to import the configuration file to a text file, and then I got win. The template configuration file is as follows:
Similar to all configuration files, it uses # To represent annotations. Now let's see what each line says.
Ddns-update-style interim;
# Configure to use the transitional DHCP-DNS interactive update mode.
Ignore client-updates;
# Ignore client updates
Subnet 192.168.0.0 netmask 255.255.255.0 {
# Set subnet Declaration
# --- Default gateway
Option routers 192.168.0.1;
# Set the default gateway to 192.168.0.1
Option subnet-mask limit 255.0;
# Set the client Subnet Mask
Option nis-domain "domain.org ";
# Set the NIS domain for the customer
Option domain-name "domain.org ";
# Setting domain names for customers
Option domain-name-servers 192.168.1.1;
# Set a Domain Name Server for the customer
Option time-offset-18000; # Eastern Standard Time
# Set the offset time.
# Option ntp-servers 192.168.1.1;
Set the NTP server.
# Option netbios-name-servers 192.168.1.1;
Set the wins Server
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- You understand Netbios very well
# Option netbios-node-type 2;
# Setting the netbios Node Type I don't know what the netbios node is. *_*!, It is best not to understand. Hey.
Range dynamic-bootp 192.168.0.128 192.168.0.255;
# Set a dynamic address pool.
Default-lease-time 21600;
# Set the default address lease period.
Max-lease-time 43200;
# Set the maximum address lease period for the client
# We want the nameserver to appear at a fixed address
// Set host Declaration
Host ns {
Next-server marvin.redhat.com;
// Set the Host Name of the server from the boot file for diskless websites.
Hardware ethernet 12: 34: 56: 78: AB: CD;
Specifies the mac address of a dhcp client.
Fixed-address 207.175.42.254;
Assign an ip address to a specified mac address
}
}
After reading this configuration file, if you have a basic knowledge of English. Do you think it is really easy to understand? In fact, do not be intimidated by linux configuration files. configuring linux is far simpler and easier to understand than windows. These configuration files give you a template, you can fill in the form according to the template. It is similar to giving you a plan. You can choose to do or not to do what you want to do. You can fill in the blanks based on your environment. Unlike windows, you don't know what the wizard does. If something goes wrong, you don't know who to look. But linux is different. If something goes wrong, you can cat your configuration sheet and paste it online to express your requirements. It is easy for others to know what you have done.
The following is an example of this configuration.
First look at the next figure, a very common network environment. (I changed the previous design scheme because I talked about dhcp here, so I won't take vlan into account. If you are interested, you can talk about this question in the Community http://www.easysafe.net/issue .)
We have a 10.0.0.0 network called easysafe.net.
There is a DHCP and an enterprise application system,
Dns server address 10.0.0.12
The database server address of the system is 10.0.0.10.
The application server address is 10.0.0.11.
There is a network management and monitoring area, with the network management workstation IP address 10.0.0.30, and the machine name is webmaster.
Then there is a firewall for NAT. The internal IP address is 10.0.0.1 and the external IP address is 202.117.0.43 (just compile a. HOHO file)
You are the network manager of this enterprise. Because you have many machines, our staff often ask you for an IP address. So you asked the boss to give you a obsolete machine, which is installed with linux and configured with a DHCP server to assign them IP addresses.
So what should we do now.
First, consider this environment.
10.0.0.10
10.0.0.11,
10.0.0.1
To avoid network problems, the above addresses should be reserved static addresses, that is, you should have an exclusion range. This range can be large or small. In the current situation, you can set a larger scope to avoid future problems. For example, we set it from 10.0.0.1 ~ 10.0.0.20, used by the system.
10.0.0.30 is for your own use, but you do not want others to use this ip address, nor do you want to re-install the system and modify it every time. Therefore, you decided to bind your IP address to the MAC.
Other users can use 10.0.0.21 at will ~ 10.0.0.254.
Now, call out our DHCP configuration sheet template to see how to configure it.
Ddns-update-style interim;
Ignore client-updates;
# Subnet 192.168.1.0 netmask 255.255.255.0 {
# The statement has changed. Our total network is 10.0.0.0/24.
Subnet 10.0.0.0 netmask 255.255.255.0 {
# When a friend modifies the configuration, we can use the original configuration # comment out.
# --- Default gateway
# Option routers 192.168.0.1;
# The route is changed to 10.0.0.1.
Option routers 10.0.0.1;
Option subnet-mask limit 255.0;
Option broadcast-address 10.0.0.255;
# Add a broadcast address
# You do not need to change this sentence because our subnet is still a subnet with three types of addresses.
# Option nis-domain "domain.org ";
# Nis not required
# Option nis-domain "easysafe.net ";
# Option domain-name "domain.org ";
Option domain-name "easysafe.net ";
# Option domain-name-servers 192.168.1.1;
Option domain-name-server 10.0.0.12
Option time-offset-18000; # Eastern Standard Time
# Set this time offset based on local conditions.
# Option ntp-servers 192.168.1.1;
# Option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (default is hybrid). Don't change this unless
# -- You understand Netbios very well
# Option netbios-node-type 2;
# Do not modify the above because I have no ntp or wins servers.
# Range dynamic-bootp 192.168.0.128 192.168.0.255;
# Set your dynamic IP address pool.
# Range dynamic-bootp 10.0.0.21 10.0.0.254
Default-lease-time 21600;
Max-lease-time 43200;
# The default ip update time and maximum update time are not modified.
# We want the nameserver to appear at a fixed address
#??????????????????????
# The above are some of the configurations in the template. Now we add some configurations that are not available in the template.
#??????????????????????
Subnet 10.0.0.0.0 netmask 255.255.255.0 {
Range 10.0.0.21 10.0.0.254;
}
# Note that our address pool is configured here !! From 10.0.0.21 to 10.0.0.254
# Host ns {
# Next-server marvin.redhat.com;
# Hardware ethernet 12: 34: 56: 78: AB: CD;
# Fixed-address 207.175.42.254;
#}
# Set the address for a specific user. Let's see how to configure the network management machine.
# Ease of configuration: Add a group declaration here, so that if someone looks at an address, you fix it,
# Set it.
Group {
Host webmaster {
Option host-name "webmaster.easysafe.net ";
# Your host name. You can set it to webmaster.
Hardware ethernet 00: cd: a9: 70: e3: f3;
# Use ifconfig to view your MAC address in linux. If you want to watch win
# You can use ipconfig to set the mac address.
Fixed-address 10.0.0.30
}
}
}
As you can see, there are not many configuration files modified here: there are no 10 statements added in total, but the dhcp configuration file is ready.
Copy the file back to the etc directory and store it as dhcpd. conf. Then you can use vi to check the file.
But don't be too happy. How does linux know that you want to start the dhcp service and use this configuration file?
Now let's look at what we will do later.
First, to run dhcp, we need a client lease database file in/var/lib/dhcpd. leases. By default, this database is empty and does not need to be configured. However, the administrator can check the running status of dhcp. '
In general, the format of this file is
Lease address {statement}
Create the/var/lib/dhcp/dhcpd. lease file as required.
After completing the above configuration, dhcp will be started later. Like the smb service mentioned earlier, it is also executed through the service command.
Service dhcpd start
Failed to start the service. The system prompts 10th and 27th errors.
The original one was to input domain-name-servers into domain-name-server by mistake.
The other is that two ranges are added.
It took about half a day to start dhcp. Depressed and changed several times.
Then you can use pstree to check whether the service is started.
Pstree | grep dhcpd
, The Service has
If you want to enable dhcp for each server startup in the future, you can use ntsysV to select your dhcp server.
There is still a small problem, that is, the client configuration.
In client win, this is the default.
In linux, You can manually configure your dhcp.
Check your network configuration file. If you are not set to enable the network automatically, modify the network configuration file.
Vi/etc/sysconfig/network
Add
NETWORKING = yes
(Enable networking during boot)
Or use
@ Echo "NETWORKING = yes">/etc/sysconfig/network
Then modify your Nic configuration file.
/Etc/sysconfig/network-scriptes/ifcfg-eth0 File
These rows should be included
DEVICE = eth0
BOOTPROTO = dhcp
ONBOOT = yes
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.