搭建DHCP 服务器

服务端:192.168.42.175  客户端:192.168.42.176

(保证虚拟机两张网卡都相同,这里采用的是NAT模式)

1.      安装DHCP 服务端

[root@xuegod175 ~]# rpm -ivh/media/CentOS_6.5_Final/Packages/dhcp-common-4.1.1-38.P1.el6.centos.x86_64.rpm

Preparing...               ########################################### [100%]

       packagedhcp-common-12:4.1.1-38.P1.el6.centos.x86_64 is already installed

[root@xuegod175 ~]# rpm -ivh/media/CentOS_6.5_Final/Packages/dhcp-

dhcp-4.1.1-38.P1.el6.centos.x86_64.rpm        dhcp-common-4.1.1-38.P1.el6.centos.x86_64.rpm

[root@xuegod175 ~]# rpm -ivh/media/CentOS_6.5_Final/Packages/dhcp-4.1.1-38.P1.el6.centos.x86_64.rpm

Preparing...               ########################################### [100%]

  1:dhcp                  ########################################### [100%]

[root@xuegod175 ~]# rpm -ivh/media/CentOS_6.5_Final/Packages/dhclient-4.1.1-38.P1.el6.centos.x86_64.rpm

Preparing...               ########################################### [100%]

       packagedhclient-12:4.1.1-38.P1.el6.centos.x86_64 is already installed

2.    拷贝配置文件

[root@xuegod175 ~]# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

cp: overwrite `/etc/dhcp/dhcpd.conf'?yes

3.      修改主要配置文件

[root@xuegod175 ~]# cat/etc/dhcp/dhcpd.conf

subnet 192.168.42.0 netmask255.255.255.0{     192.168.42.0 网段  255.255.255.0)子网掩码

range 192.168.42.100 192.168.42.200;   #表示的是地址池

option domain-name-servers 192.168.42.2;   #DNS地址

option domain-name"xuegod.cn";

option routers 192.168.42.2; #网关(注意:这里的网关在虚拟机中要查看NAT 里面设置的网关要一致)

option broadcast-address 192.168.42.255;#广播地址

default-lease-time 600; 最短租期

max-lease-time 7200; 最长租期

}

4.      客户端进行测试

客户端机器需要把IP 地址获取方式改成自动获取方式 重启网卡进行测试

[root@xuegod176~]# /etc/init.d/network restart

Shutting downinterface eth0:  Device state: 3(disconnected)

[  OK  ]

Shutting downloopback interface:                         [  OK  ]

Bringing uploopback interface:                           

[  OK  ]

Bringing upinterface eth0:  Active connection state:activated

Activeconnection path: /org/freedesktop/NetworkManager/ActiveConnection/4 [  OK  ]

搭建DHCP 服务器

经测试:客户端能够正常获取到ip地址

查看网关

[root@xuegod176 ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.42.0    0.0.0.0         255.255.255.0   U    1      0        0 eth1

0.0.0.0         192.168.42.2    0.0.0.0         UG   0      0        0 eth1 #网关正确

查看DNS

[root@xuegod176 ~]# cat /etc/resolv.conf

# Generated by NetworkManager

domain xuegod.cn

search xuegod.cn cn

nameserver 192.168.42.2        #DNS 正确




本文转自 Innocence_caosm 51CTO博客,原文链接:http://blog.51cto.com/innocence/1909717,如需转载请自行联系原作者
上一篇:php脚本#!/usr/bin/env php写法的好处


下一篇:50个Android Studio秘诀、技巧和资源