Bài giảng Quản trị Linux trình bày những kiến thức cơ bản về dynamic host configuration protocol. Nội dung chính trong chương này gồm có: Why use DHCP? Configuring a DHCP server, configuring a DHCP client. Mời các bạn cùng tham khảo.
Trang 1Đặng Thanh Bình mm
Trang 3
WHY USE DHCP?
Trang 4
Why Use DHCP?
¢ Dynamic Host Configuration Protocol (DHCP) is a network protocol that automatically assigns
TCP/IP information to client machines
¢ Each DHCP client connects to the centrally
located DHCP server, which returns that client's
network configuration (including the IP address, gateway, and DNS servers)
Trang 5
Why Use DHCP?
¢ DHCP is useful for automatic configuration of
client network interfaces
¢ When configuring the client system, the administrator chooses DHCP instead of specifying
an IP address, netmask, gateway, or DNS servers
¢ The client retrieves this information from the
DHCP server
Trang 6Why Use DHCP?
¢ DHCP is also useful if an administrator wants to change the IP addresses of a large number of systems
¢ Instead of reconfiguring all the systems, he can just edit one DHCP configuration file on the server for the new set of IP addresses
— If the DNS servers for an organization changes, the changes are made on the DHCP server, not on the
DHCP clients
Trang 7Why Use DHCP?
¢ If an organization has a functional DHCP server properly connected to a network, laptops and other mobile computer users can move these
devices from office to office
Trang 8CONFIGURING A DHCP SERVER
Trang 9
/var/lib/dhcpd/dhcpd.leases to store’ the
client lease database
Trang 10
Configuration File
¢ The first step in configuring a DHCP server is to create the configuration file that stores the network information for the clients
¢ Use this file to declare options and global options for client systems
¢ The configuration file can contain extra tabs or blank lines for easier formatting Keywords are case-insensitive and lines beginning with a hash
mark (#) are considered comments
Trang 11DNS update schemes
implemented
— the ad-hoc DNS update mode
— the interim DHCP-DNS interaction update mode
¢ You must configure the DNS server for compatibility with these schemes
Trang 12¢ To use the recommended mode, add the
following line to the top of the configuration file
ddns-update-style interim;
Trang 13Types Of Statements
¢ Two types of statements in the configuration file:
— Parameters — State how to perform a task, whether
to perform a task, or what network configuration options to send to the client
— Declarations — Describe the topology of the network,
describe the clients, provide addresses for the clients,
or apply a group of parameters to a group of
declarations
Trang 14Ex 1 Subnet Declaration
¢ There are global options for every DHCP client in the subnet and a range declared Clients are assigned an IP address within the range
Trang 15Ex 2 Shared-network Declaration
¢ All subnets that share the same physical network Should be declared within a shared-network declaration
e Parameters within the shared-network, but outside the enclosed subnet declarations, are
considered to be global parameters
¢ The name of the shared-network must be a descriptive title for the network, such as using the title ‘test-lab to describe all the subnets ina test lab environment
Trang 16Ex 2 Shared-network Declaration
shared-network name {
option domain-name "test.redhat.com";
option domain-name-servers nsl.redhat.com, ns2.redhat.com;
Trang 17Ex 3 Group Declaration
¢ The group declaration is used to apply global parameters to a group of declarations
¢ For example, shared networks, subnets, and
hosts can be grouped
Trang 18Ex 3 Group Declaration
hardware ethernet 00:A0:78:8E:9E:AA;
fixed-address 192.168.1.4;
host raleigh { option host-name "raleigh.example.com";
hardware ethernet 00:A1:DD:74:C3:F2;
fixed-address 192.168.1.6;
Trang 19
Ex 4 Range Parameter
¢ To configure a DHCP server that leases a dynamic
IP address to a system within a subnet, modify Example 4, “Range Parameter” with your values
e It declares a default lease time, maximum lease
time, and network configuration values for the
clients
¢ This example assigns IP addresses in the range
systems
Trang 20Ex 4 Range Parameter
Trang 21Ex 5 Static IP Address using DHCP
¢ To assign an IP address to a client based on the MAC
address of the network interface card, use the
hardware ethernet parameter within a_ host declaration
¢ As demonstrated in Example 5, “Static IP Address using DHCP”, the host apex declaration specifies that the NIC with the MAC address 00:A0:78:8E:9E:AA always receives the IP address 192.168.1.4
¢ Note that the optional parameter host-name can also be used to assign a host name to the client
iy , |
Trang 22Ex 5 Static IP Address using DHCP
host apex {
option host-name "apex.example.com";
hardware ethernet 00:A0:7/8:8E:9E:AA;
fixed-address 192.168.1.4;
Trang 23Lease Database
/var/lib/dhcpd/dhcpd.leases stores the DHCP client
— The dhcpd.leases file is renamed dAgd:-leases~ and the
temporary lease database is written to dhq@pd:- leases:
Trang 24
Starting and Stopping the Server
Trang 25Starting and Stopping the Server
¢ If more than one network interface is attached to the system, but the DHCP server should only be Started on one of the interfaces, configure the DHCP server to start only on that device
¢ In /etc/sysconfig/dhcpd, add the name of the
interface to the list of DHCPDARGS:
# Command line options here
DHCPDARGS=eth0
Trang 26
DHCP Relay Agent
¢ The DHCP Relay Agent (dhcrelay) allows for the relay of DHCP and BOOTP requests from a subnet
with no DHCP server on it to one or more DHCP
servers on other subnets
Trang 27DHCP Relay Agent
¢ When a DHCP server returns a reply, the reply is
broadcast or unicast on the network that sent the original request
¢ The DHCP Relay Agent listens for DHCP requests
on all interfaces unless the interfaces are
specified in /etc/sysconfig/dhcrelay with the
INTERFACES directive
¢ To start the DHCP Relay Agent, use the command service dhcrelay start
Trang 28CONFIGURING A DHCP CLIENT
Trang 29
Configuring DHCP Clients
° The first step is to make sure the kernel recognizes the network interface card
¢ To configure a DHCP client manually
— Modify the /etc/sysconfig/network file to enable networking
— Modify the configuration file for each network device
in the f/etc/sysconfig/network-scripts directory
¢ In this directory, each device should have a configuration file named ifcfg-ethO, where ethO is the network device name
Trang 30
/etc/sysconfig/network file
¢ The /etc/sysconfig/network file should contain
the following line:
NETWORKING=-yes
¢ The NETWORKING variable must be set to yes if you want networking to start at boot time
Trang 31¢ A configuration file is needed for each device to
be configured to use DHCP
Trang 32etc/sysconfig/network-scripts/ifcfg-ethO
¢ Other options for the network script
— DHCP_HOSTNAME — Only use this option if the DHCP server requires the client to specify a hostname before receiving an IP address (The DHCP server daemon in Red Hat Enterprise Linux does not support this feature.)
— PEERDNS=<answer>, where <answer> is one of the
Trang 33/etc/sysconfig/network-scripts/ifcfg-ethO
¢ Other options for the network script
— SRCADDR=<address>, where <address> Is the
specified source IP address for outgoing packets
— USERCTL=<answer>, where <answer> is one of the
following:
¢ yes — Non-root users are allowed to control this device
¢ no — Non-root users are not allowed to control this device