标签:dhcp 配置
安装完DHCP后,了解其重要的配置文件
配置服务
主配置文件为/etc/dhcp/dhcpd.conf
打开后发现可以查看配置实例example,可以根据实例了解下
修改配置文件
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
#此行我修改为自己的域名
option domain-name "liuliancao.com";
#此处servers我修改为自己dns的地址
option domain-name-servers 192.168.177.130,192.168.177.133;
#修改默认租约
default-lease-time 6000;
max-lease-time 72000;
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;通常这不是安全的做法,会修改dns服务器的内容,建议关闭
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
#定义不同的日志级别,这里默认吧
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
#让服务知道,这是一个不被允许使用的域,我把它注释掉了
#subnet 10.152.187.0 netmask 255.255.255.0 {
#}
# This is a very basic subnet declaration.
#最基本的设置,有子网的定义,地址池的设置,路由(网关)的设置,此处我也注释掉
#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
#option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}
# This declaration allows BOOTP clients to get dynamic addresses,
# which we don‘t really recommend.
#BOOTP的使用说明,不使用
#subnet 10.254.239.32 netmask 255.255.255.224 {
# range dynamic-bootp 10.254.239.40 10.254.239.60;
#option broadcast-address 10.254.239.31;
#option routers rtr-239-32-1.example.org;
#}
#典型的配置,我修改了下成为自己的配置
# A slightly different configuration for an internal subnet.
subnet 192.168.177.0 netmask 255.255.255.0 {
range 192.168.177.10 192.168.177.20;
#默认情况下为130-254虚拟机dhcp分配,等会用来比较接受了哪个服务器
option domain-name-servers 192.168.177.130,192.168.177.133;
option domain-name "liuliancao.com";
option routers 192.168.177.1;
# option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200;
}
#定义特殊的主机,并为之绑定ip地址,即固定ip地址,这里先不用
#host server {
#通过mac定位
# hardware ethernet 00:0C:29:1D:07:88;
# fixed-address 192.168.177.133;
#}重启dhcpd服务
[root@www ~]# service dhcpd restart Shutting down dhcpd: [ OK ] Starting dhcpd: [ OK ]
上面的如果启动失败,请自行查看/var/log/messages,有详细的说明信息
[root@www ~]# netstat -tunlp |grep dhcpd udp 0 0 0.0.0.0:67 0.0.0.0:* 2677/dhcpd
设置客户端为BOOTPROTO=dhcp
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=dhcp HWADDR=00:0C:29:1D:07:88 NETMASK=255.255.255.0 ONBOOT=yes GATEWAY=192.168.177.1
如果你启动的时候显示NetworkManager actived的话,请关闭这个服务
[root@localhost network-scripts]# service NetworkManager stop Stopping NetworkManager daemon: [ OK ] [root@localhost network-scripts]# chkconfig NetworkManager off
在客户端重启网络
[root@localhost ~]# service network restart
这一步请在内部虚拟机运行,否则就会迟迟没有响应,因为客户端ip已经变了,说明该客户端是用来server端的dhcp
[root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:1D:07:88 inet addr:192.168.177.3 Bcast:192.168.177.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe1d:788/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1867 errors:0 dropped:0 overruns:0 frame:0 TX packets:1854 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:184954 (180.6 KiB) TX bytes:227183 (221.8 KiB)
此时服务端可以查看leases
[root@www ~]# tail -8 /var/lib/dhcpd/dhcpd.leases
lease 192.168.177.3 {
starts 4 2015/05/2119:11:50;
ends 4 2015/05/21 19:21:50;租约的时间信息
cltt 4 2015/05/21 19:11:50;
binding state active;
next binding state free;
hardware etherne
t00:0c:29:1d:07:88;这个mac就是client的mac
此时把之前配置文件中的静态绑定启用,在客户端有[root@ns2 ~]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining IP information for eth0... done
[root@ns2 ~]# ifconfig eth0 Linkencap:Ethernet HWaddr00:0C:29:1D:07:88 inet addr:192.168.177.133 Bcast:192.168.177.255 Mask:255.255.255.0 inet6 addr:fe80::20c:29ff:fe1d:788/64 Scope:Link UP BROADCAST RUNNINGMULTICAST MTU:1500 Metric:1 RX packets:2121 errors:0 dropped:0overruns:0 frame:0 TX packets:2080errors:0 dropped:0 overruns:0 carrier:0 collisions:0txqueuelen:1000 RX bytes:212609(207.6 KiB) TX bytes:251128 (245.2 KiB)
不过绑定信息并不需要租约
本文出自 “启学的学习之路” 博客,请务必保留此出处http://qixue.blog.51cto.com/7213178/1656648
标签:dhcp 配置
原文地址:http://qixue.blog.51cto.com/7213178/1656648