linux服务DHCP详解

DHCP -----   Dynamic Host Configuration Protocol   动态主机配置协议

应用层协议


作用:为客户端分配IP信息 

原理:

1、客户端发送DHCP Discovery探索DHCP服务器 

2、DHCP服务器发送DHCP Offer (IP/NETMASK/GATEWAY/DNS)

3、客户端发送DHCP Request

4、DHCP服务器发送DHCP ACK

5、客户端发送Gratuation ARP用于检测IP地址是否冲突 



软件:dhcp

配置文件:/etc/dhcp/dhcpd.conf

服务:dhcpd

端口:67/udp(DHCP服务端端口) , 68/udp(DHCP客户端端口) 




示例:配置DHCP服务器 


环境描述:

隔离网络: Lan1     网段:192.168.87.0/24

DHCP服务器:   192.168.87.101, dhcpserver.linux.com 

客户端:

Linux

windows XP 


1) 配置主机名,IP地址


[root@server ~]# hostnamectl set-hostname server.linux.com 


[root@server ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 

# Generated by dracut initrd

DEVICE=eth0

NAME=eth0

ONBOOT=yes

BOOTPROTO=none

TYPE=Ethernet

IPADDR=192.168.87.101

NETMASK=255.255.255.0


[root@server ~]# systemctl restart network

[root@server ~]# systemctl restart NetworkManager


[root@server ~]# ip addr show eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 52:54:00:71:3b:1c brd ff:ff:ff:ff:ff:ff

    inet 192.168.87.101/24 brd 192.168.87.255 scope global eth0

       valid_lft forever preferred_lft forever

    inet6 fe80::5054:ff:fe71:3b1c/64 scope link 

       valid_lft forever preferred_lft forever




2) 配置yum源,安装DHCP软件  


[root@server ~]# mkdir /etc/yum.repos.d/default

[root@server ~]# mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/default


[root@server ~]# vim /etc/yum.repos.d/local.repo


[local]

name=localsrc

baseurl=file:///mnt

enabled=1

gpgcheck=0


[root@server ~]# mount /dev/cdrom /mnt/



[root@server ~]# yum clean all

已加载插件:fastestmirror, langpacks

正在清理软件源: local

Cleaning up everything

[root@server ~]# yum makecache 生成元数据


[root@server ~]# 


[root@server ~]# yum install -y dhcp 




3) 编辑配置文件 


[root@server ~]# vim /etc/dhcp/dhcpd.conf 


subnet 192.168.87.0 netmask 255.255.255.0 {

  range 192.168.87.10 192.168.87.100;

  option routers 192.168.87.1;

  option domain-name-servers 114.114.114.114, 8.8.8.8;

}


[root@server ~]# systemctl start dhcpd

[root@server ~]# systemctl enable dhcpd  >>>设置服务开机自动启动

Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.


[root@server ~]# ss -anup | grep :67

UNCONN     0      0            *:67                       *:*                   users:(("dhcpd",pid=1822,fd=7))

UNCONN     0      0      *%virbr0:67                       *:*                   users:(("dnsmasq",pid=1506,fd=3))



4) 测试 




DHCP排错:


日志:/var/log/messages 


# tail -f /var/log/messages 










本文转自 北冥有大鱼  51CTO博客,原文链接:http://blog.51cto.com/lyw168/1957476,如需转载请自行联系原作者
上一篇:dedecms最新注入漏洞


下一篇:静态构造函数的执行时机