Centos6.5-DHCPServer安装

时间:2022-12-20 19:36:49

1、查询dhcp有没有被安装,如下没有被安装

[zfp@localhost ~]$ rpm -q dhcp
package dhcp is not installed
[zfp@localhost ~]$

2、查询yum网络源中有关dhcp的rpm包

[root@localhost zfp]# yum list |grep dhcp
dhcp.x86_64                        12:4.1.1-53.P1.el6.centos.1 updates         
dhcp-common.x86_64                 12:4.1.1-53.P1.el6.centos.1 updates         
dhcp-devel.i686                    12:4.1.1-53.P1.el6.centos.1 updates         
dhcp-devel.x86_64                  12:4.1.1-53.P1.el6.centos.1 updates         
sblim-cmpi-dhcp.i686               1.0-1.el6                   base            
sblim-cmpi-dhcp.x86_64             1.0-1.el6                   base            
sblim-cmpi-dhcp-devel.i686         1.0-1.el6                   base            
sblim-cmpi-dhcp-devel.x86_64       1.0-1.el6                   base            
sblim-cmpi-dhcp-test.x86_64        1.0-1.el6                   base

3、安装dhcp

[root@localhost zfp]# yum install dhcp -y

4、查询是否安装成功

[root@localhost zfp]# rpm -q dhcp
dhcp-4.1.1-53.P1.el6.centos.1.x86_64
[root@localhost zfp]#

查询安装的含有dhcp字符串包名的rpm包
[root@localhost zfp]# rpm -qa |grep dhcp
dhcp-common-4.1.1-53.P1.el6.centos.1.x86_64
dhcp-4.1.1-53.P1.el6.centos.1.x86_64

5、修改配置文件/etc/dhcp/dhcpd.conf

不同的发行版不一定是/etc/dhcp/dhcpd.conf这个文件,也可能是/etc/dhcpd.conf,centos6.5发行版是/etc/dhcp/dhcpd.conf

[root@localhost zfp]#vim /etc/dhcp/dhcpd.conf

ddns-update-style interim;      #表示dhcp服务器和dns服务器的动态信息更新模式

ignore client-updates;          #忽略客户端更新

subnet 10.10.10.0 netmask 255.255.255.0 {        #意思是我所分配的ip地址所在的网段为192.168.145.0 子网掩码为255.255.255.0

range 10.10.10.100 10.10.10.200;            #租用IP地址的范围

option domain-name-servers 8.8.8.8,114.114.114.114;

option domain-name "example.org";

option routers 10.10.10.1;                    #路由器地址,这里是当前 dhcp 机器的IP地址

option subnet-mask 255.255.255.0;                  #子网掩码

default-lease-time 600;                            #默认租约时间

max-lease-time 7200;                              #最大租约时间

#host myhost {                                      #设置主机声明

#hardware ethernet 08:00:27:2C:30:8C;            #指定dhcp客户的mac地址

#fixed-address 192.168.145.155;                  #给指定的mac地址分配ip

# }

}

6、创建虚接口并重启网络

cp ifcfg-eth0:1 ifcfg-eth0:1

vi ifcfg-eth0:1

DEVICE=eth0:1
HWADDR=00:0C:29:AD:F8:B7
TYPE=Ethernet
UUID=d60f7bad-0f18-420a-8e19-3e361f8ffed4
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.10.10.1
NETMASK=255.255.255.0

service network restart

[root@localhost zfp]#vim /etc/sysconfig/dhcpd
DHCPDARGS=eth0:1     #指定在eth0:11虚接口上提供dhcpserver服务

7、开启dhcp服务

root@localhost zfp]#service dhcpd start   (或者/etc/init.d/dhcpd start)

[root@localhost zfp]# service dhcpd status    
dhcpd (pid  4478) 正在运行...
[root@localhost zfp]#

设置开机启动dhcpd

chkconfig dhcpd on

如果有报错,查看dhcp服务开启的时候,报什么错误cat /var/log/messages  或者tail -f /var/log/messages &

如下是正常开启dhcp服务的log信息

Jan  9 04:50:38 localhost dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
Jan  9 04:50:38 localhost dhcpd: Copyright 2004-2010 Internet Systems Consortium.
Jan  9 04:50:38 localhost dhcpd: All rights reserved.
Jan  9 04:50:38 localhost dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Jan  9 04:50:38 localhost dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Jan  9 04:50:38 localhost dhcpd: Wrote 3 leases to leases file.
Jan  9 04:50:38 localhost dhcpd: Listening on LPF/eth0:1/00:0c:29:ad:f8:b7/10.10.10.0/24
Jan  9 04:50:38 localhost dhcpd: Sending on   LPF/eth0:1/00:0c:29:ad:f8:b7/10.10.10.0/24
Jan  9 04:50:38 localhost dhcpd: Sending on   Socket/fallback/fallback-net
Jan  9 04:50:40 localhost dhcpd: DHCPREQUEST for 10.10.10.100 from a0:9d:86:fc:89:12 via eth0:1
Jan  9 04:50:40 localhost dhcpd: DHCPACK on 10.10.10.100 to a0:9d:86:fc:89:12 via eth0:1
[root@localhost network-scripts]#

[root@localhost network-scripts]# netstat -anulp | grep :67
udp        0      0 0.0.0.0:67                  0.0.0.0:*                               4591/dhcpd         
[root@localhost network-scripts]#

如果启动的时候出现错误(Can't chown new lease file: Operation not permitted),需修改/etc/rc.d/init.d/dhcpd文件中的

user=dhcpd
group=dhcpd

user=root
group=root

再启动尝试

如下FORWARD链中REJECT的规则,阻止了数据报文的转发,进行删除iptables -D FORWARD 1,然后service iptables save保存到配置

iptables -nvL FORWARD

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)

pkts bytes target     prot opt in     out     source               destination

389 23343 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

End Of File