在服务器配置DHCP使客户机自动获取ip地址,网关,DNS
1.为服务器设置ip地址,网关,主机名,DNS服务器地址
为服务器设置ip地址
[[email protected] ~]# vim/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29:19:BB:76
ONBOOT=yes
IPADDR=192.168.1.1
NETWORK=255.255.255.0
为服务器设置主机名,网关
[[email protected] ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=dhcpser.tarena.com
GATEWAY=192.168.1.254
为服务器设置DNS服务器地址
[[email protected] ~]# vim /etc/resolv.conf
search tarena.com
nameserver 192.168.1.254
nameserver 202.106.0.20
重启network服务和设置为开机自动启动
[[email protected] ~]#service network restart
[[email protected] ~]# chkconfig network on
2.检查安装dhcp服务软件包
检查服务器是否有安装dhcp服务
[[email protected] ~]# rpm -q dhcp
packagedhcp is not installed
通过光驱安装dhcp软件
在/misc/cd/Server目录下安装
[[email protected] ~]# cd /misc/cd/Server/
[[email protected] Server]# rpm -ivhdhcp-3.0.5-31.el5_8.1.x86_64.rpm
[[email protected] Server]# rpm -q dhcp
dhcp-3.0.5-31.el5_8.1
3.通过修改配置文件/etc/dhcpd.conf配置dhcp服务
[[email protected] Server]# vim /etc/dhcpd.conf
进入配置文件后看到下两行注释,说明/usr/share/doc/dhcp*/dhcpd.conf.sample下有DHCP配置文件模板,可以在vim下/usr/share/doc/dhcp*/dhcpd.conf.sample直接读取此文件来配置
# DHCP Server Configuration file.
# see/usr/share/doc/dhcp*/dhcpd.conf.sample
加载模板后删除无效信息并添加修改配置文件
1ddns-update-style interim;
2 subnet192.168.1.0 netmask 255.255.255.0 {配置网段
3 option routers 192.168.1.254;默认网关
4 option subnet-mask 255.255.255.0;子网掩码
5 option domain-name "tarena.com";搜索域
6 option domain-name-servers 192.168.1.254,202.106.0.20; DNS服务器
7 range dynamic-bootp 192.168.1.0192.168.1.253; DHCP地址池
8 default-lease-time 21600;重启租约时间
9 max-lease-time 43200; 最大租约时间
10 host kehu2 { 客户2独立配置
11 hardware ethernet00:0C:29:E1:F6:25;指定客户2MAC地址
12 fixed-address 192.168.1.200;为客户2预留ip
13 }
14 }
配置完成保存退出后进行DHCP服务的重启以及开机自动启动
Service dhcpdconfigtest可执行对配置文件的语法检查
[[email protected] Server]# servicedhcpd restart
[[email protected] Server]# chkconfigdhcpd on
4.验证Linux客户机1
将客户1etc/sysconfig/network-scripts/ifcfg-eth0设置为DHCP动态获取IP
重启network服务
可看到客户机动态获取了ip(默认从大往小分配)
5.验证win7客户机2
将客户机2改为DHCP自动获取ip
查看ip可看到客户机2为我们为其预留的ip 192.168.1.200
【初学菜鸟作--DHCP的配置应用】,布布扣,bubuko.com