dhcp服务器安装

Posted on Posted in linux
Tips: 本文创建于2014年2月20日,已超过 2 年,内容或图片可能已经失效!

安装

yum install dhcp

/etc/dhcpd.conf 主配置文件
/usr/share/doc/dhcp-* 模版文件
/usr/sbin/dhcpd 执行文件
/var/lib/dhcpd/dhcpd.leases 租约文件
/etc/sysconfig/dhcrelay 中继代理配置文件

cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
vim /etc/dhcpd.conf
	ddns-update-style interim;
	ignore client-updates;	#忽略客户端的动态更新,提供服务器负载
	#可以定义多个subnet分配不同网段的IP
	subnet 192.168.0.0 netmask 255.255.255.0 {
		option routers	192.168.0.1;	#网关
		option subnet-mask	255.255.255.0;	#声明子网掩码
		option nis-domain	"domain.org";	#声明域名
		option domain-name	"domain.org";	#dns域
		option domain-name-servers	192.168.1.1;	#声明dns的ip地址,如果有多个,用逗号隔开
		option time-offset	-28800;	#8时区,单位秒
		#option ntp-servers	192.168.1.1;	#声明时间服务器的IP

		range dynamic-bootp 192.168.0.100 192.168.1.200;	#地址池范围
		range 192.168.0.20 192.168.70;	#地址池有多个,再添加range
		default-lease-time 21600;	#默认租约时间
		max-lease-time 43200;	#最大租约时间

		host ns {
			next-server marvin.redhat.com;	#用来客户端获取到地址后,寻找下一个服务器进行下一次的工作
			hardware ethernet 12:34:56:78:AB:CD;	#	mac地址
			fixed-address 207.175.42.254;	#	分配的IP
		}
	}
service dhcpd start

端口:
服务器端67
客户端68

netstat -antlp | grep :67

yum -y install nmap*
nmap localhost #扫描自己

vim /etc/sysconfig/dhcpd
	# Command line options here
	DHCPDARGS=eth0 #只针对eth0网卡进行dhcp服务
vim /var/lib/dhcpd/dhcpd.leases #作用是查看已经用了的IP地址,没有就先touch一个
	lease	192.168.1.100 {
	start
	end
	hardware
	client-hostname
	}

客户端配置

/etc/sysconfig/network
NETWORKING=yes
/etc/sysconfig/network-scripts/ifcfg-eth*
BOOTPROTO=dhcp
ONBOOT=yes

service network restart
	or
dhclient eth0
dhclient -r

客户端租约文件 /var/lib/dhcpd/dhclient-eth*.lease

dhcp中继代理(另一台机器)

vim /etc/sysconfig/dhcrelay
	INTERFACES="eth0 eth1"	#如果中继代理接受到dhcp应答以后,将使用哪个网卡应答客户端,一般情况下,都写上
	DHCPSERVERS="192.168.1.100"	#定义dhcp服务器的IP地址
/etc/init.d/dhcrelay restart

dhcp冗余(不用)
dhcp服务器本身没有冗余功能

server1 192.168.0.2/24
dhcpd.conf
ddns-update-style none;
default-lease-time 1200;
max-lease-time 2400;
option broadcast-address	192.168.0.255;
subnet 192.168.0.0 netmask 255.255.255.0 {
	option routers 192.168.0.1;
	range 192.168.0.3 192.168.0.60;
}
subnet 192168.1.0 netmask 255.255.255.0 {
	option routers 192.168.1.1;
	range 192.168.1.3 192.168.1.60;
}

server2 192.168.1.2/24
dhcpd.conf
ddns-update-style none;
default-lease-time 1200;
max-lease-time 2400;
option broadcast-address	192.168.1.255;
subnet 192.168.0.0 netmask 255.255.255.0 {
	option routers 192.168.0.1;
	range 192.168.0.70 192.168.0.80;
}
subnet 192168.1.0 netmask 255.255.255.0 {
	option routers 192.168.1.1;
	range 192.168.1.70 192.168.1.80;
}

service dhcpd restart

注意事项:
1、dhcp与本机的网络信息网段要一致

要求:
网络段:192.168.149.0/24
DNS=202.106.0.20
GW=192.168.149.129

vim /etc/dhcpd.conf
	ddns-update-style interim;
	ignore client-updates;
	subnet 192.168.149.0 netmask 255.255.255.0 {
		option routers	192.168.149.129;
		option subnet-mask	255.255.255.0;

		pool	{
		option domain-name-servers	202.106.0.20;
		range dynamic-bootp	192.168.149.1 192.168.149.127;
		default-lease-time	21600;
		max-lease-time	43200;
		}
		#option time-offset	-18000;

		pool	{
		option domain-name-servers	202.106.46.151;
		range 192.168.149.130 192.168.149.254;
		default-lease-time 41600;
		max-lease-time 83200;
		}

		host zhangsan {
			hardware ethernet aa:bb:cc:dd:ee:ff
			fixed-address	192.168.149.128
		}
	}

dhcp日志分离

vim /etc/syslog.conf
local1.none	/var/log/messages
local1.*	/var/log/dhcp.log

vim /etc/dhcpd.conf
log-facility	local1;

service dhcpd restart
/etc/init.d/syslog restart

dhcp-get-ip

一、环境
Description: Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Release: 5.5
Codename: Tikanga
DHCP服务器IP:192.168.77.1

二、安装

[root@localhost ~]# yum -y install dhcp

三、配置文件说明
主配置文件:/etc/dhcpd.conf
主配置模版文件:/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample
执行文件:/usr/sbin/dhcpd
租约文件:cat /var/lib/dhcpd/dhcpd.leases
中继代理配置文件:/etc/sysconfig/dhcrelay

四、配置
1、获取简单的dhcpIP

[root@localhost ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp:是否覆盖"/etc/dhcpd.conf"? y
[root@localhost ~]# cat /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates; #忽略客户端的动态更新,利于服务器的负载
#定义多个subnet可以分配不同的网段IP
subnet 192.168.77.0 netmask 255.255.255.0 {

# --- default gateway
 option routers 192.168.77.1; #网关
 option subnet-mask 255.255.255.0; #声明子网掩码

option nis-domain "domain.org"; #声明域名
 option domain-name "domain.org"; #dns域
 option domain-name-servers 192.168.1.1; #声明dns的ip地址,如果有多个,用逗号隔开

option time-offset -288000; # Eastern Standard Time #8时区,单位秒
# option ntp-servers 192.168.1.1; #ntp时区服务器
# 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;

range dynamic-bootp 192.168.77.100 192.168.77.200; #地址池范围
 default-lease-time 21600; #默认租约时间
 max-lease-time 43200; #最大租约时间

# we want the nameserver to appear at a fixed address
 host ns {
 next-server marvin.redhat.com; #客户端获取地址后,寻找下一个服务器进行下一次的工作
 hardware ethernet 12:34:56:78:AB:CD; #mac地址
 fixed-address 207.175.42.254; #分配的IP地址
 }
}

查看客户端(XP)获取IP情况,如图

2、指定网卡进行dhcpd服务

[root@localhost ~]# vim /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS=eth0

3、查看已经分配的IP地址,如果没有dhcpd.leases就touch一个

[root@localhost ~]# cat /var/lib/dhcpd/dhcpd.leases
# All times in this file are in UTC (GMT), not your local timezone. This is
# not a bug, so please don't ask about it. There is no portable way to
# store leases in the local timezone, so please don't request this as a
# feature. If this is inconvenient or confusing to you, we sincerely
# apologize. Seriously, though - don't ask.
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-V3.0.5-RedHat
lease 192.168.77.178 {
 starts 0 2014/01/05 05:29:59;
 ends 0 2014/01/05 11:29:59;
 binding state active;
 next binding state free;
 hardware ethernet 00:0c:29:59:73:52;
 uid "\001\000\014)YsR";
 client-hostname "lhh-xp";
}

4、dhcp日志分离

vim /etc/syslog.conf
local1.none /var/log/messages
local1.* /var/log/dhcp.log

vim /etc/dhcpd.conf
log-facility local1;

service dhcpd restart
/etc/init.d/syslog restart

» 转载请注明来源:若我若鱼 » dhcp服务器安装

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + one =