DHCP configuration section

Source: Internet
Author: User

DHCP Configuration under Linux

1. DHCP Working process
DHCP discover \ \ Client Request Server provides address
DHCP offer \ \ server provides IP address
DHCP request \ \ client leased IP address
DHCP ACK \ \ Server confirms client's lease

2. Install the DHCP package
# yum Install DHCPD
# CD/ETC/DHCPD
# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample./dhcpd.conf

3. Configure DHCP
Basic Configuration Content
Determine the network on which the IP address resides
Set the IP address range you want to assign
Set subnet mask for assigned IP address
Set the gateway IP address
Set DNS Address
Set the lease time (default lease time and maximum lease period)

Address binding (Assigning a fixed IP address to a device)

# Vim Dhcpd.conf
Option Domain-name "sxjy.com";
Option Domain-name-servers 8.8.8.8,202.103.96.112;

Default-lease-time 3600;
Max-lease-time 72000;

Log-facility Local7;
Shared-network Sxjy {
Subnet 172.16.10.0 netmask 255.255.255.0 {
Range 172.16.10.2 172.16.10.100;
Range 172.16.10.200 172.16.10.250;
Option routers 172.16.10.1;
Option Broadcast-address 172.16.10.255;
Default-lease-time 7200;
Max-lease-time 15400;
}

Subnet 172.16.20.0 netmask 255.255.255.0 {
Range 172.16.20.2 172.16.20.100;
Range 172.16.20.200 172.16.20.250;
Option routers 172.16.20.1;
Option Broadcast-address 172.16.20.255;
}

Host Ftp.sxjy.com {
Hardware Ethernet 00:0c:29:b6:df:5e;
Fixed-address 172.16.10.10;
Fixed-address 172.16.10.10;
}
}

Exercise: With three virtual machines, one for the server and two for the client, two clients are required to obtain the addresses of different network segments assigned to the server, such as a
The address obtained is 192.168.1.10/24, and the other is 192.168.2.10/24, the specific address segment can be defined by itself, but cannot be assigned to others
IP address, grabbing packets on the server observing IP allocations

4. DHCP Address binding
Host Ftp.sxjy.com {
Hardware Ethernet 00:0c:29:b6:df:5e;
Fixed-address 192.168.10.10;
}

5. DHCP Relay configuration
(1) Turn on the Routing and forwarding function of Relay server
# vim/etc/sysctl.conf
Net.ipv4.ip_forward = 1
# sysctl-p

(2) Setting relay options
# Vim/etc/sysconfig/dhcrelay
interfaces= "Eth0 eth1"
Dhcpservers= "172.16.10.1"

(3) Start the DHCP Relay service
# service Dhcrelay Start

6. Use of Windows clients
Ipconfig/renew \ \ Re-obtain the IP address
Ipconfig/release \ Release IP address

# dhclinet Eth0
DHCP relay experiment steps:
(1) Set up a single-NIC DHCP server on which to configure the pool of addresses within its own network segment, and also configure additional network segment address pools, which must contain option routers options.
[Email protected] ~]# cat/etc/dhcp/dhcpd.conf
Ddns-update-style none;
Option Domain-name "sxjy.com";
Option Domain-name-servers 1.1.1.1;
Default-lease-time 6000;
Max-lease-time 7200;
Log-facility Local7;
#shared-network haha {
Subnet 192.168.3.0 netmask 255.255.255.0 {
Range 192.168.3.10 192.168.3.20; Address pools for other networks
Option Domain-name-servers 2.2.2.2;
Option routers 192.168.3.254; The gateway address must be specified
}

Subnet 192.168.2.0 netmask 255.255.255.0 {
Range 192.168.2.10 192.168.2.20; The address pool is the address pool of the DHCP server's own network
Option Domain-name-servers 2.2.2.2;
Option routers 192.168.2.100;
}
Your network card is 192.168.2.0
[[Email protected] ~]# IP add show eth1
3:eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:17:18:20 BRD FF:FF:FF:FF:FF:FF
inet 192.168.2.100/24 BRD 192.168.2.255 Scope Global eth1\
At the same time, your gateway also needs to point to the routing host:
[[email protected] ~]# Route|grep default
Default 192.168.2.254 0.0.0.0 UG 0 0 0 eth1

(2) Set up the routing host while assuming the role of DHCP relay
The router connects to the DHCP server with a network card (eth0) IP of 192.168.2.254, and the other Net card (eth1) must be 192.168.3.254 (match the address pool setting in step 1)
A, turn on the relay server's route forwarding function
# vim/etc/sysctl.conf
Net.ipv4.ip_forward = 1
# sysctl-p
B. Set relay options
# Vim/etc/sysconfig/dhcrelay
interfaces= "Eth0 eth1"
Dhcpservers= "172.16.10.1"
Start Dhcrelay:service dhcrelay Start
(3) Setting up the client
The eth1 of the client's NIC link router:
Dhclient-r eth0;dhclient eth0
PS: Router eht1 and client eth0 share the SW1 LAN. The router eth0 and the DHCP server share the Host-only LAN.

DHCP for routers

Configuration of the DHCP server
Router (config) #interface fastethernet 0/0
Router (config-if) #no shutdown
Router (config-if) #ip address 192.168.10.1 255.255.255.0
Router (config-if) #exit
Router (config) #ip DHCP pool Xixi
Router (dhcp-config) #network 192.168.20.0 255.255.255.0
Router (dhcp-config) #default-router 192.168.20.1
Router (dhcp-config) #dns-server 8.8.8.8
Router (Dhcp-config) #exit
Router (dhcp-config) #network 192.168.10.0 255.255.255.0
Router (dhcp-config) #default-router 192.168.10.2
Router (dhcp-config) #dns-server 8.8.8.8
Router (Dhcp-config) #exit
Router (config) #ip Route 0.0.0.0 0.0.0.0 192.168.10.2

Configuration of the relay Agent
Router (config) #interface fastethernet 0/0
Router (config-if) #no shutdown

%link-5-changed:interface fastethernet0/0, CHANGED state-to-up

%lineproto-5-updown:line protocol on Interface fastethernet0/0, changed

Router (config-if) #ip address 192.168.10.2 255.255.255.0
Router (config) #interface fastethernet 0/1
Router (config-if) #no shutdown
Router (config-if) #ip address 192.168.20.1 255.255.255.0
Router (config-if) #IP helper-address 192.168.10.1

Test
On the host
Pc>ipconfig/release

IP address ......: 0.0.0.0 ........ £ º
Subnet Mask ........: 0.0.0.0.....
The Default Gateway ...: 0.0.0.0 ...... £ º
DNS Server ...........: 0.0.0.0...

Pc>ipconfig/renew

IP address ......: 192.168.20.2 ........ £ º
Subnet Mask ........: 255.255.255.0.....
The Default Gateway ...: 192.168.20.1 ...... £ º
DNS Server ...........: 8.8.8.8...

DHCP configuration section

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.