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,如需轉載請自行聯系原作者