linux上搭建DHCP服务
1.首先安装DHCP服务需要的软件包
yum install dhcp*
2.手工编译DHCP主配置文件/etc/dhcp/dhcpd.conf
配置内容如下
ddns-update-style none;
default-lease-time 600;
max-lease-time 1200;
option domain-name "ceshi.com";
option domain-name-servers 192.168.3.202;
subnet 192.168.3.0 netmask 255.255.255.0 {
range 192.168.3.190 192.168.3.210;
option subnet-mask 255.255.255.0;
option routers 192.168.3.253;
host Server01 {
hardware ethernet B0:51:8E:01:94:86;
fixed-address 192.168.3.202;
}
}
3使用命令测试配置未见是否存在语法错误
[root@ns1 ~]# service dhcpd configtest
Syntax: OK
正常
4开启允许分配IP地址的主机端口文件
vim /etc/sysconfig/dhcpd
DHCPDARGS= eth0
测试通过测试成功获取IP地址
Mar 28 10:17:13 localhost dhcpd: DHCPREQUEST for 192.168.3.190 from 00:23:4d:dc:36:41 (home) via eth0
Mar 28 10:17:13 localhost dhcpd: DHCPACK on 192.168.3.190 to 00:23:4d:dc:36:41 (home) via eth0
Mar 28 10:18:53 localhost named-sdb[4247]: network unreachable resolving 'py.qlogo.cn/A/IN': 2001:dc7:1000::1#53
Mar 28 10:19:48 localhost dhcpd: DHCPREQUEST for 192.168.0.163 from 18:87:96:a0:ec:33 via eth0: ignored (not authoritative).
Mar 28 10:22:13 localhost dhcpd: DHCPREQUEST for 192.168.3.190 from 00:23:4d:dc:36:41 (home) via eth0
Mar 28 10:22:13 localhost dhcpd: DHCPACK on 192.168.3.190 to 00:23:4d:dc:36:41 (home) via eth0
成功分配给MAC为00:23:4d:dc:36:41主机
DHCP中继让不同网主机跨越网段获取DHCP服务器分配IP,
1安装DHCP服务包
yum -y install dhcp*
2开启服务器的路由转发功能
vim /etc/sysctl.conf
将net.ipv4.ip_forward=0修改为1启用
使用命令让其修改生效
sysctl -p
3设置允许DHCP中继接口及DHCP服务器修改文件
[root@ns1 ~]# vim /etc/sysconfig/dhcrelay
# Command line options here
INTERFACES="eth0 eth1"
DHCPSERVERS="192.168.3.202"
4开启服务
/etc/init.d/dhcrelay restart