DHCP服务的搭建

DHCP服务搭建

  • 首先需要安装DHCP的软件包,我们使用rpm包用yum进行安装
[root@localhost ~]# yum install -y dhcp.x86_64
  • 需要修改配置文件:/etc/dhcpd.conf ,修改之前我们需要cp一个模板文件
[root@localhost ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample  /etc/dhcp/dhcpd.conf 
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 

subnet 192.168.4.0 netmask 255.255.255.0 {
  range 192.168.4.10 192.168.4.200;
  option domain-name-servers 8.8.8.8;
  option domain-name "internal.example.org";
  option routers 192.168.4.1;
  option broadcast-address 192.168.4.255;
  default-lease-time 600;
  max-lease-time 7200;
}

> Subnet: 网段声明作用于整个子网段 
> range: 设置用于分配的IP地址池  起始IP 
> option domain-name-servers: 设置指定域名服务器
> option routers: 设置网关地址
> option broadcast-address: 设置广播地址
> option subnet-mask: 设置客户机的子网掩码 
> Host: 保留主机,作用于单个主机 ,(通常防止所在网段的subnet声明内) 
> default-lease-time: 设置默认的租约
> max-lease-time: 最大的租约时间
> hardware ethernet参数:指定对应主机的MAC地址
> fixed-address参数: 指定为该主机保留的IP地址

 - 说明一下,dhcp服务器如果想配置不同网段的IP,前提必须有一个和本地IP同网段的声明才可以。
  • 启动DHCP服务,并设置为开机自起状态
[root@localhost ~]# service dhcpd start
Starting dhcpd:                                            [  OK  ]
[root@localhost ~]# chkconfig dhcpd on
[root@localhost ~]# chkconfig --list dhcpd
dhcpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
  • 查看dhcp服务是否正常启动并处于监听状态,默认dhcp服务的端口号为UDP67
[root@localhost ~]# netstat -natpu | grep 67
udp        0      0 0.0.0.0:67                  0.0.0.0:*                               5548/dhcpd   
  • 客户端使用dhcp释放和获得dhcp服务器的分配的ip
    获得:Dhclient –d eth1
[root@localhost ~]# dhclient -d eth1
Internet Systems Consortium DHCP Client 4.1.1-P1
Copyright 2004-2010 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eth1/00:0c:29:33:4a:0c
Sending on   LPF/eth1/00:0c:29:33:4a:0c
Sending on   Socket/fallback
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 8 (xid=0x68888b56)
DHCPOFFER from 192.168.4.115
DHCPREQUEST on eth1 to 255.255.255.255 port 67 (xid=0x68888b56)
DHCPACK from 192.168.4.115 (xid=0x68888b56)

释放:dhclient –r eth1

[root@localhost ~]# dhclient -r eth1
  • dhcp软件包的主要文件
    -主配置文件:/etc/dhcpd.conf
[root@zhangsan ~]# ls -ltr /etc/dhcp/dhcpd.conf 
-rw-r--r--. 1 root root 3260 Apr 12 15:10 /etc/dhcp/dhcpd.conf

-执行程序:/usr/sbin/dhcpd、/usr/sbin/dhcrelay

[root@zhangsan ~]# ls -ltr /usr/sbin/dhcpd 
-rwxr-xr-x. 1 root root 825904 Sep 25  2012 /usr/sbin/dhcpd
[root@zhangsan ~]# ls -ltr /usr/sbin/dhcrelay 
-rwxr-xr-x. 1 root root 465680 Sep 25  2012 /usr/sbin/dhcrelay

-服务脚本:/etc/init.d/dhcpd、/etc/init.d/dhcrelay

[root@zhangsan ~]# ls -ltr /etc/init.d/dhcpd
-rwxr-xr-x. 1 root root 3118 Sep 25  2012 /etc/init.d/dhcpd
[root@zhangsan ~]# ls -ltr /etc/init.d/dhcrelay 
-rwxr-xr-x. 1 root root 2510 Sep 25  2012 /etc/init.d/dhcrelay

-执行参数配置:/etc/sysconfig/dhcpd

[root@zhangsan ~]# ls -ltr /etc/sysconfig/dhcpd
-rw-r--r--. 1 root root 39 Sep 25  2012 /etc/sysconfig/dhcpd

-DHCP中继配置:/etc/sysconfig/dhcrelay

[root@zhangsan ~]# ls -ltr /etc/sysconfig/dhcrelay
-rw-r--r--. 1 root root 101 Sep 25  2012 /etc/sysconfig/dhcrelay

到此我们就简单的将dhcp服务搭建好了,下面小伙伴就可以从dhcp服务器获取到IP地址了,后面我们再进行不同网段客户端获取不同的IP的配置。

你可能感兴趣的:(Linux服务的搭建)