How to install and use the DHCP service in Linux

Source: Internet
Author: User
Tags domain name server
Article Title: How to install and use the DHCP service in Linux. 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.

DHCP is based on the customer/server mode. When the DHCP client is started, it automatically communicates with the DHCP server, and the DHCP server provides services with automatically assigned IP addresses for the DHCP client.

Of course, advanced DHCP is not just as simple as allocating addresses. Today, we only set up a normal DHCP server for our courses. the client can obtain the necessary network configuration information for accessing the Internet.

The server where the DHCP service software is installed is called the DHCP server, and the client with the DHCP function enabled is called the DHCP client. the DHCP server provides services for the DHCP client through address lease, it has the following two methods:

Limited lease term and permanent lease

To learn about a DHCP server, you must know how the DHCP server works:

DHCPDISCOVER (DHCP invention)

DHCPOFFER (DHCP supply)

DHCPREQUEST (DHCP request)

DHCPACK (DHCP confirmation)

The four steps are necessary for the client to obtain the IP address.

When DHCP is provided, the server has allocated an IP address to the client. the IP address assigned to the client in the second part is temporary. after the client obtains the IP address, it will send a DHCP request to lease the address, after receiving the request, the server will officially allocate the address to the client and then send DHCP confirmation to the client.

The four steps mainly deal with multiple DHCP servers in the same network.

Background process: dhcpd

Script:/etc/rc. d/init. d/dhcpd

Port: 67

Required RPM Package: dhcp

Related RPM packages:

Dhcp-devel-3.0.5-7.el5.i386.rpm

Dhcpv6-0.10-33.el5.i386.rpm

Dhcpv6_client-0.10-33.el5.i386.rpm

Configuration File:/etc/dhcpd. conf

Log:/var/log/xferlog

Let's try again. The network startup method is also called bootpc, so that the obtained IP address will not be subject to the server's lease period of 111ttt.com, and it will always be valid.

Now, we need to install the DHCP server first.

1. download or find the DHCP service installation package from the CD.

II. Installation (dhcp * indicates the installation package name ):

# Rpm-ivh dhcp *

3. configure the DHCP file:

Copy/usr/share/doc/dhcp */dhcpd. conf. sample to the/etc directory and change it to dhcpd. conf.

# Cp/usr/share/doc/dhcp */dhcpd. conf. sample/etc/dhcpd. conf

Of course, you can also first vi/etc/dhcpd. conf, and then run the following command in the last line mode:

R/usr/share/doc/dhcp */dhcpd. conf. sample

In this way, the content of the dhcpd. conf. sample file will be imported.

Open dhcpd. conf and modify the following items:

Subnet is followed by the network segment you defined. it must be the same as the IP address of the local machine,

Each statement ends with a semicolon (;). do not forget it.

For example, if my IP address is "192.168.2.11", The following is my configuration file:

Ddns-update-style interim;

Ignore client-updates;

Subnet 192.168.2.0 netmask 255.255.255.0 {

Option routers 192.168.2.1;

Option subnet-mask limit 255.0;

Option nis-domain "domain.org ";

Option domain-name "domain.org ";

Option domain-name-servers 192.168.2.1;

Option time-offset-18000;

Range dynamic-bootp 192.168.2.100 192.168.2.254

Default-lease-time 21600;

Max-lease-time 43200;

Filename "/pxelinux.0 ";

Next-server 192.168.2.11;

Host ns {

Next-server marvin.redhat.com;

Hardware ethernet 12: 34: 56: 78: AB: CD;

Fixed-address 207.175.42.254;

}

}

IV. detailed notes:

Ddns-update-style interim; # define the supported DNS Dynamic update types (required). generally, we set it to disabled,

# Interim and none both mean to disable

Allow/ignore client-updates; # allow/neglect clients to update DNS records

Allow/deny unknown-clients; # whether to dynamically allocate IP addresses to unknown users

Allow/deny bootp; # whether to respond to the activation query

Allow/deny booting; # whether to respond to user queries

Subnet 192.168.2.0 netmask 255.255.255.0 {# set the subnet declaration

# --- Default gateway

Option routers 192.168.2.1; # set the default gateway to 192.168.2.1

Option subnet-mask subnet mask 255.255.0; # set the Client subnet mask

Option nis-domain "domain.org"; # set the NIS domain for the customer

Option domain-name "domain.org"; # set a domain name for the customer

Option domain-name-servers 192.168.2.1; # set the domain name server for the customer

Option time-offset-18000; # Eastern Standard Time # specify the Greenwich Mean time offset Time for the client, in seconds,

# This option can be used in both global and local configurations.

# Option ntp-servers 192.168.2.1; # NTP is a time server

# Option netbios-name-servers 192.168.2.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 this netbios node is.

Range dynamic-bootp 192.168.2.28 192.168.2.254; # set a dynamic address pool

Default-lease-time 21600; # set the default address lease period

Max-lease-time 43200; # set the maximum client address lease period

# We want the nameserver to appear at a fixed address

Filename "/pxelinux.0"; # Name of the startup file, which is applied to diskless installation. it can be the relative or absolute path of tftp.

Next-server 192.168.2.11; # This is the name of the server they shocould get it from

# Tftp server, which can be different from the dhcp server. this parameter is generally used by PXE networks.

# Set host declaration

Host ns {

Next-server marvin.redhat.com;

Hardware ethernet 12: 34: 56: 78: AB: CD; # specify the mac address of a dhcp client

Fixed-address 207.175.42.254; # assign an ip address to the specified mac address

}

}

5. After configuring the dhcpd. conf file, you can start the dhcp service:

# Service dhcpd restart

You can run the "netstat-nlutp" command to check whether the dhcp service has been started.

6. other related documents:

1. this file/var/lib/dhcpd. leases can view the rented IP address and related information.

2. this file/etc/sysconfig/dhcpd is the Nic of the DHCP server 111ttt.com. if there is only one Nic, you do not need to set

DHCPDARGS = eth0 or eth1, if all 111ttt.com is not required.

3. this file/etc/sysconfig/dhcrelay is the file for configuring DHCP Relay. open it.

Interfaces is the dhcpdiscover (request) from this port that will be forwarded to the subsequent DHCPSERVERS server.

If DHCP relay is set, you need to start the relay service: service dhcrelay start.

7. under The linux client, you can manually configure your dhcp:

Observe your network configuration file. if you are not set to enable the network automatically, modify your 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.

The/etc/sysconfig/network-scriptes/ifcfg-eth0 file should include these lines:

DEVICE = eth0

BOOTPROTO = dhcp

ONBOOT = yes

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.