1 需求 配置一个网络内IP自动获取 2 系统 Centos 6.8 内核2.6.32-642.el6.x86_64 软件dhcp.x86_64 3 实施 3.1 安装dhcp软
1 需求
配置一个网络内IP自动获取
2 系统
Centos 6.8
内核 2.6.32-642.el6.x86_64
软件 dhcp.x86_64
3 实施
3.1 安装dhcp软件
yum install dhcp.x86_64
3.2 配置dhcp
系统默认/etc/dhcp/dhcpd.conf 里面是说明软件,需要从/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample 拷贝过来
[root@wzlvm network-scripts]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
然后把配置文件里面内容改为一下配置内容(里面就是说明很多,其他不需要的也比较多,可以直接全部清除,再写上新内容)
[root@wzlvm network-scripts]# vim /etc/dhcp/dhcpd.conf 1 option domain-name "wzl.com"; -- DNS域名 2 option domain-name-servers 192.168.125.134; -- DNS解析服务器 3 default-lease-time 600; -- 自少使用时长600秒 4 max-lease-time 7200; -- 最长使用时间7200秒 5 log-facility local7; 6 subnet 192.168.1.0 netmask 255.255.255.0 { -- 192.168.1.0 是网号 7 option routers 192.168.1.1; -- 192.168.1.1 是网关 8 option subnet-mask 255.255.255.0; -- 子网掩码 9 option time-offset -18000; 10 range 192.168.1.112 192.168.1.114; -- ip池 11 default-lease-time 21600; 12 max-lease-time 43200; 13 }
由于DHCP 中配置的网号需要和网卡在同一个网段中,所以我们可以在机器中新增一张虚拟网卡
[root@myvm network-scripts]# ll ifcfg-eth0*-rw-r--r-- 1 root root 202 Oct 13 15:43 ifcfg-eth0-rw-r--r-- 1 root root 85 Oct 13 17:00 ifcfg-eth0:1 -- 这个是新增的虚拟网卡[root@myvm network-scripts]# vim ifcfg-eth0:1 1 DEVICE=eth0:1 2 BOOTPROTO=static -- 设为静态 3 IPADDR=192.168.1.100 -- 设置一个和dhcpd.conf中网号在同一网段中的IP 4 NETMASK=255.255.255.0 -- 子网掩码 5 ONBOOT=yes -- 激活
重启网卡,让ifcfg-eth0:1生效
service network restart
关闭虚拟机的dhcp服务,然后重启上面服务机的dhcp 服务
service dhcpd restart
[root@myvm network-scripts]# service dhcpd restartStarting dhcpd: [ OK ]
4 验证
在客户端中重启网卡就获取到自己配置的dhcp 网段中的IP
eth0 Link encap:Ethernet HWaddr 00:0C:29:17:43:C6 inet addr:192.168.1.112 Bcast:172.16.193.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe17:43c6/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1272 errors:0 dropped:0 overruns:0 frame:0 TX packets:1037 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:109382 (106.8 KiB) TX bytes:266465 (260.2 KiB)