DHCP配置

DHCP服务器IP:192.168.1.10

一,安装dhcp

[root@localhost ~]# yum install dhcp
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
cdrom                                                                 | 4.1 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-27.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package           Arch                Version                      Repository          Size
=============================================================================================
Installing:
 dhcp              x86_64              12:4.2.5-27.el7              cdrom              506 k

Transaction Summary
=============================================================================================
Install  1 Package

Total download size: 506 k
Installed size: 1.4 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 12:dhcp-4.2.5-27.el7.x86_64                                               1/1 
  Verifying  : 12:dhcp-4.2.5-27.el7.x86_64                                               1/1 

Installed:
  dhcp.x86_64 12:4.2.5-27.el7                                                                

Complete!
View Code

二,编辑dhcpd配置文件

[root@localhost ~]# !v
vim /etc/dhcp/dhcpd.conf

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
ddns-update-style none;
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.60;
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
option domain-name "cnblog.com";
option domain-name-servers 192.168.1.1;
default-lease-time 21600;
max-lease-time 43200;
}

三,通过一台客户机验证DHCP服务器是否配置成功

更改客户机网卡配置文件

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 

HWADDR=00:0C:29:51:55:DB
TYPE=Ethernet
BOOTPROTO=dhcp   //客户机需要改成"dhcp"
DEFROUTE=yes
PEERDNS=no
PEERROUTES=no
IPV4_FAILURE_FATAL=no
NAME=eno16777736
UUID=0bf4eae0-e5b4-4dab-b42d-8ae4a90adee3
ONBOOT=yes

重启网卡,验证是否通过DHCP方式获取到地址

[root@localhost ~]# systemctl restart network
[root@localhost ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.50  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe51:55db  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:51:55:db  txqueuelen 1000  (Ethernet)
        RX packets 88  bytes 9565 (9.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 112  bytes 16255 (15.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 4  bytes 336 (336.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4  bytes 336 (336.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

四,如果想给主机名为"user1"主机分配固定IP地址"192.168.1.54"

[root@localhost ~]# !v
vim /etc/dhcp/dhcpd.conf 

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
ddns-update-style none;
ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.60;
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
option domain-name "feng.xyz";
option domain-name-servers 192.168.1.1;
default-lease-time 21600;
max-lease-time 43200;

host user1 {        //"user1"为需要固定IP的主机的主机名("hostname")
hardware ethernet 00:0c:29:51:55:db; //mac地址
fixed-address 192.168.1.54; //固定的IP地址
}
}

 

你可能感兴趣的:(DHCP配置)