DHCP服务器的搭建(服务器本身一般都设置为静态ip地址)
准备工作:给服务器本身设置固定ip地址
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 //配置文件
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0 //设备名为eth0,第一块物理网卡
BOOTPROTO=static //static或none为静态ip;dhcp为动态获取
ONBOOT=yes //必须为on开机自动开启
HWADDR=00:0c:29:12:d0:4f //MAC地址
IPADDR=192.168.1.1 //设置固定ip地址
NETMASK=255.255.255.0 //子网掩码
[root@localhost ~]# /etc/init.d/network restart //重启服务或service network restart
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: ch [确定]
[root@localhost ~]# chkconfig network on //设置为开机自启动
[root@localhost ~]# chkconfig --list network //检查开启自启动
network 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
1、 安装dhcp软件包
[root@localhost ~]# rpm -q dhcp
package dhcp is not installed
放入光盘镜像
[root@localhost ~]# cd /misc/cd/Server/
[root@localhost Server]# ls dhcp*
dhcp-3.0.5-31.el5_8.1.x86_64.rpm
dhcp-devel-3.0.5-31.el5_8.1.i386.rpm
dhcp-devel-3.0.5-31.el5_8.1.x86_64.rpm
dhcpv6-1.0.10-20.el5.x86_64.rpm
dhcpv6-client-1.0.10-20.el5.x86_64.rpm
[root@localhost Server]# rpm -ivh dhcp-3.0.5-31.el5_8.1.x86_64.rpm
Preparing... (1########################################### [100%]
1:dhcp ( ########################################### [100%]
[root@localhost Server]# rpm -q dhcp
dhcp-3.0.5-31.el5_8.1
2、配置DHCP服务器(主配置文件)
[root@localhost ~]# cat /etc/dhcpd.conf //dhcp主配置文件
ddns-update-style interim; //全局配置参数,动态更新类型
subnet 192.168.1.0 netmask 255.255.255.0 { //网段声明
option routers 192.168.1.254; //网关
option subnet-mask 255.255.255.0; //子网掩码
option domain-name "tarena.com"; //默认搜索域
option domain-name-servers 202.106.0.20; //DNS服务器
range dynamic-bootp 192.168.1.10 192.168.1.20; //动态分配的ip地址段
default-lease-time 21600; //默认租期
max-lease-time 43200; //最大租期
host ns { //host主机声明,为某一台主机配置保留地址
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD; //客户机MAC
fixed-address 192.168.1.253; //分配保留地址
}
}
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample //dhcp设置的模板
#末行模式下: r /usr/share/doc/dhcp*/dhcpd.conf.sample 可以拷贝模板内容
3、启动DHCP服务
[root@localhost ~]# /etc/init.d/dhcpd restart
启动 dhcpd: [确定]
[root@localhost ~]# chkconfig dhcpd on
[root@localhost ~]# chkconfig --list dhcpd
dhcpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
4、测试(在客户端测试)
安装dhcp服务
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=dhcp //设置为dhcp动态获取
ONBOOT=yes
HWADDR=00:0c:29:1e:f6:df
[root@localhost ~]# service network restart //重启网络服务
[root@localhost ~]# ifconfig eth0 | grep inet //查看获取ip地址情况
inet addr:192.168.1.19 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe1e:f6df/64 Scope:Link
注:本文档仅为本人学习之笔记,大神请飘过,不足之处请谅解并真诚接受您的指正。谢谢。