DHCP服务的配置

一、DHCP的简介

1、软件包:dhcp

2、服务名:dhcpd(主程序)、dhcrelay(中继服务)

3、端口:udp 67 udp 68

4、配置文件:

/etc/dhcp/dhcpd.conf 主配置文件

/etc/sysconfig/dhcrelay 中继配置文件

/usr/share/doc/dhcp*/dhcpd.conf.sample 主配置文件模板

5、常见配置选项:

ddns-update-style interim; //设置dhcp互动更新模式

ignore client-updates; //忽略客户端更新

subnet 192.168.12.0 netmask 255.255.255.0 {  //设置子网申明

 # --- default gateway

 option routers 192.168.12.1; //设置客户端默认网关

 option subnet-mask 255.255.255.0; //设置客户端子网掩码

 option nis-domain "ixdba.net "; //设置NIS域

 option domain-name " ixdba.net "; //设置DNS域

 option domain-name-servers 192.168.12.1; //设置DNS服务器地址

 option time-offset -18000; # Eastern Standard Time //设置时间偏差

 # option ntp-servers 192.168.12.1; //设置时间服务器

 # option netbios-name-servers 192.168.12.1;    //设置netbios服务器地址

 # --- Selects point-to-point node (default is hybrid). Don't change this unless

 # -- you understand Netbios very well

 # option netbios-node-type 2;

 range dynamic-bootp 192.168.12.128 192.168.12.254; //设置地址池

 default-lease-time 21600; //设置默认租期,单位为秒

 max-lease-time 43200; //设置客户端最长租期,单位为秒

 # we want the nameserver to appear at a fixed address

 host ns { //设置保留地址

 server-name marvin.RedHat.com;    //分配地址的服务器名

 hardware ethernet 12:34:56:78:AB:CD;  //被保留地址的机器的MAC

 fixed-address 207.175.42.254;   //分配的IP地址

 }

 }

二、实验过程:

一)搭建DHCP服务器:

服务器端:

1、yum -y install dhcp

2、由于dhcp刚安装完成时是没有配置文件的,必须从模板文件中拷贝一份

cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

3、vim /etc/dhcp/dhcpd.conf 删除多余配置,保留一个subnet区域

  subnet 192.168.1.0 netmask 255.255.255.0 {

option routers 192.168.1.2;

option subnet-mask 255.255.255.0;

option domain-name-servers 192.168.1.2;

range 192.168.1.10 192.168.1.100;

default-lease-time 21600;

max-lease-time 23200;

}

4、service dhcpd restart


客户端:

1、将客户端的网卡获取IP的模式设置为自动获取

vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=dhcp

2、重启网络服务

service network restart


二)搭建DHCP中继服务:

服务器端:

1、yum -y install dhcp

2、cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

3、vim /etc/dhcp/dhcpd.conf 

  subnet 192.168.1.0 netmask 255.255.255.0 {

option routers 192.168.1.2;

option subnet-mask 255.255.255.0;

option domain-name-servers 192.168.1.2;

range 192.168.1.10 192.168.1.100;

default-lease-time 21600;

max-lease-time 23200;

}

  subnet 200.200.200.0 netmask 255.255.255.0 {

option routers 200.200.200.1;

option subnet-mask 255.255.255.0;

option domain-name-servers 200.200.200.1;

range 200.200.200.10 200.200.200.100;

default-lease-time 21600;

max-lease-time 23200;

}

4、service dhcpd restart

5、添加一条网关记录

route add default gw 192.168.1.2


中继端:

1、yum -y install dhcp

2、将内核参数配置文件设置为支持IP转发

vim /etc/sysctl.conf

ip.net.ipv4_forward 1

3、加载配置文件

sysctl -p

4、配置中继配置文件

vim /etc/sysconfig/dhcrelay

INTERFACE = "eth0  eth1"

DHCPSERVER = "192.168.1.1"

5、开启中继服务

service dhcrelay start

客户端:

1、将客户端的网卡获取IP的模式设置为自动获取

vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=dhcp

2、重启网络服务

service network restart


你可能感兴趣的:(DHCP)