配置 DHCP 服务 实现 ip 地址自动分配

原因:由于公司使用 CentOS6.5 充当网关,为了避免麻烦给同事们一个个地去配置 IP 地址, 所以决定安装使用 dhcp 来自动分配 IP(之前是真一个一个去给他们配置 IP 地址,真他妈的累,烦,卖力而且不讨好~~)

1
[[email protected] ~]# yum install -y dhcp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[[email protected] ~]# vim /etc/dhcp/dhcpd.conf

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#
# 全局配置

# 设置客户端域名
option domain-name "wgsc.tv";
option domain-name-servers 192.168.1.60, 192.168.1.61;

# 默认租约12h
default-lease-time 43200;

# 最大租约24h
max-lease-time 86400;

# 不要ddns设定
ddns-update-style none;

# 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;

# 设置DHCP子网段
subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.181 192.168.1.230;
    option routers 192.168.1.1;
}


################### 服务器(设备)静态IP配置 ###################
# Java_bug_6
host device_1 {
  hardware ethernet fc:aa:14:3a:42:f0;
  fixed-address 192.168.1.6;
}

# k3-25
host device_2 {
  hardware ethernet fc:aa:14:48:62:98;
  fixed-address 192.168.1.25;
}

# ....省略一大串
1
2
3
[[email protected] ~]# vim /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS=eth0

Tips: CentOS7 以后不需要设置

1
2
[[email protected] ~]# /etc/inin.d/iptables stop
[[email protected] ~]# chkconfig iptables off
1
[[email protected] ~]# /etc/init.d/dhcpd start

注: 启动日志信息可以查看 /var/log/message 租约信息可查看 /var/lib/dhcpd/dhcpd.leases