安装dhcp,yum install dhcp rpm -qa | grep dhcp dhcp-3.0.5-18-el5 默认下,/etc/dhcpd.conf文档为空,所以刚安装了软件,启动dhcp服务是失败的。把/usr/share/doc/dhcp-3.0.5/dhcp.conf.sample拷贝至/etc,并命名为dhcpd.conf,覆盖掉那个空文件。
cp /usr/share/doc/dhcp-3.0.5/dhcp.conf.sample /etc/dhcpd.conf yes覆盖
这时如果还是不能启动服务,则考虑您的电脑网卡是否被激活,使用ifconfig查看,如果只有lo则需要,ifup eth0激活网卡。 使用service dhcpd start,就【确定】或【OK】了。
接着,vi /etc/dhcpd.conf 默认配置文件如下:
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
# --- default gateway
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "domain.org";
option domain-name-servers 192.168.1.1;
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# 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.0.128 192.168.0.254;
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;
fixed-address 207.175.42.254;
}
}
现在来修改配置文件,以满足我们自己的需要:
前提:
ddns-update-style interim;
ignore client-updates;
第一句是指定DHCP服务器支持DNS动态更新的方式为interim,第二句指定客户机不能更新DNS记录,这是对所有子网有效的参数,所以我们把它们放在最开始。
1、设置IP地址范围 subnet语句用于声明IP地址范围。它的格式如下:
subnet 子网 IP network 子网掩码
{
range 起始IP 结束IP;
IP 参数;
}
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.254;
option subnet-mask 255.255.255.0;
option domain-name "linux";
option domain-name-servers 210.47.176.1;
range 192.168.0.200 192.168.0.230;
}
然后service dhcpd restart。设置别的电脑为自动获得IP地址和DNS服务器地址,重启网卡,用ifconfig(linux)或ipconfig /all(windows)查看即可。
ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.254;
option subnet-mask 255.255.255.0;
option domain-name "linux";
option domain-name-servers 210.47.176.1;
range 192.168.0.200 192.168.0.230;
host jsj{
hardware ethernet 00:1C:25:3B:35:57;
fix-address 192.168.0.100;
}
}
保存文件,重启服务,再重启那台电脑,即可发现其IP地址变为192.168.0.100了,当然host jsj中的jsj是那台电脑的名字,和MAC地址一样得自己查。