1.安装dhcp服务
rpm -ivh dhcp-3.0.5-13.el5.i386.rpm
2.启动DHCP
chkconfig dhcpd on
chkconfig --list dhcpd ----------查看
3.基本操作
/etc/init.d/dhcpd start
/etc/init.d/dhcpd stop
/etc/init.d/dhcpd restart
执行ntsysv
4.配置文件
cp /usr/share/doc/dhcp*/dhcpd.conf.sample ./dhcpd.con
5.案例1
架设一台DHCP服务器
要求:
1.为子网192.1680.0/24建立一个IP作用域,并将在192.168.0.20~192.168.0.100范围之内的IP地址动态分配给客户机。
2.假设子网中的DNS服务器地址为192.168.0.2,IP路由器地址为192.168.0.1,所在的网络域名为example.com,将这些参数指定给客户机。
3.为某台主机保留192.168.0.50这个IP地址,DNS服务器地址为192.168.0.5
1.修改配置文件
vi /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option domain-name "example.com"
option domain-name-servers 192.168.0.2;
option time-offset -18000
range dynamic-bootp 192.168.0.20 192.168.0.100;
default-lease-time 21600;
max-lease-time 432000;
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 192.168.0.50;
option domain-name-servers 192.168.0.5;
}
}
2.重启dhcp服务
service dhcpd restart
3.验证
在cmd中输入ipconfig /release 释放ip
输入ipconfig /renew 获得ip
重新编写配置文件/etc/dhcpd.config
vi /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option domain-name "example.com"
option domain-name-servers 192.168.0.2;
option time-offset -18000
range dynamic-bootp 192.168.0.20 192.168.0.30;
default-lease-time 21600;
max-lease-time 432000;
}
再次验证,重新在cmd中获取IP地址。
6.案例2
公司原有250台机器,IP规划为192.168.0.0、24网段,动态管理网络IP地址,现升级到
500台,如何保持原有IP地址规划不变的情况下,可以扩容现有的IP网络地址。
1.第一种方式:多作用域
1.给服务器增加一块网卡
2.在服务器通过命令:settup命令配置两块网卡
其中一块,iP:192.168.0.1 255.255.255.0
另一快,ip:192.3168.1.1 255.255.255.0
3.重新启动网络
service network restart
4.配置DHCP服务器
vi /etc/dhcpd.conf
dns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option time-offset -18000;
range dynamic-bootp 192.168.0.20 192.168.0.30;
default-lease-time 21600;
max-lease-time 43200;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option time-offset -18000;
range dynamic-bootp 192.168.1.20 192.168.1.30;
default-lease-time 21600;
max-lease-time 43200;
}
5.重启DHCP服务
service dhcpd restart
6.windows验证
7.网段间通讯
vi /etc/ssysctl.conf
net.ipv4.ip_forward=0 ------------->net.ipv4.ip_forward=1
刷新 sysctl -p
8.再次验证
在IP为192.168.0.30机器上
ping 192.168.1.30
2.第二种方式(超级作用域)
1.关闭其中一个网卡
ifdown eth1
3.配置DHCP服务器
vi /etc/dhcpd.conf
dns-update-style interim;
ignore client-updates;
shared-network test {
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option time-offset -18000;
range dynamic-bootp 192.168.0.20 192.168.0.30;
default-lease-time 21600;
max-lease-time 43200;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option time-offset -18000;
range dynamic-bootp 192.168.1.20 192.168.1.30;
default-lease-time 21600;
max-lease-time 43200;
}
}
4.关闭转发功能
vi /etc/ssysctl.conf
net.ipv4.ip_forward=1 ------------->net.ipv4.ip_forward=0
5.增加一台liniu服务器(目的是充当路由,为了解决不同网段间通讯问题)
有两块网卡:一块:192.168.0.1 255.255.255.0
另一块:192.168.1.1 255.255.255.0
打开转发功能:
vi /etc/ssysctl.conf
net.ipv4.ip_forward=0 ------------->net.ipv4.ip_forward=1
6.配置中继服务器
vi /etc/sysconfig/dhcrelay
INTERFACES="eth0 eth1" ------------监视网卡
DHCPSERVERS="192.168.0.99" -----------DHCP服务器IP
重启服务:service dhcrelay restart
7.windows验证
3.DHCP排错步骤
1.查看错误信息
2.检查配置文件
3.检查租约文件 -------tail /var/lib/dhcpd/dhcpd.leases
4.ping测试
5.查看日志 ---------tail /var/log/messages