linux服務DHCP詳解

DHCP -----   Dynamic Host Configuration Protocol   動態主機配置協議linux

應用層協議vim


做用:爲客戶端分配IP信息 windows

原理:服務器

一、客戶端發送DHCP Discovery探索DHCP服務器 網絡

二、DHCP服務器發送DHCP Offer (IP/NETMASK/GATEWAY/DNS)dom

三、客戶端發送DHCP Requestide

四、DHCP服務器發送DHCP ACK測試

五、客戶端發送Gratuation ARP用於檢測IP地址是否衝突 url



軟件:dhcpspa

配置文件:/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 

相關文章
相關標籤/搜索