First, the basic concept of DHCP
Dhcp:dynamic host Configration Protocol Dynamic Host Configuration Protocol
C/S Architecture:
Server: Static address. Provides a pool of addresses (list): 67/UDP
Client: Dynamic address, 68/UDP (the server sometimes initiates a request to the client)
DHCP scope of work: The current physical network can not be carried out across the network;
DHCP Communication process: (broadcast mode, brodcast)
CLIENT:DHCP Discover Message
SERVER:DHCP offer Message
CLIENT:DHCP Request Message
SERVER:DHCP ACK Message (confirmation)
DHCP has the concept of a lease (lease), when the remaining 50% of the available time to renew (unicast), the client side to send the DHCP request message again, the server side sends the DHCP ACK message, the use of time extended to maximum use time. When the server side cannot renew the lease, send DHCP NAK message to client side, client resend Discover message request new address;
Second, DHCP basic configuration
[[email protected] ~]# yum install -y dhcp[[email protected] ~]# rpm -ql dhcp/etc/networkmanager/etc/networkmanager/dispatcher.d/etc/networkmanager/dispatcher.d/12- dhcpd/etc/dhcp/etc/dhcp/dhcpd.conf #dhcp配置文件 (IPv4) is empty by default, You should use the sample file to cover the/etc/dhcp/dhcpd6.conf/etc/openldap/schema/dhcp.schema/etc/sysconfig/dhcpd #服务程序/usr/bin/omshell/usr/lib/systemd/system/dhcpd.service/usr/lib/ systemd/system/dhcpd6.service/usr/lib/systemd/system/dhcrelay.service/usr/sbin/dhcpd/usr/sbin/dhcrelay/usr/ share/doc/dhcp-4.2.5/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example #使用此配置文件进行配置/usr/share/doc/ dhcp-4.2.5/dhcpd6.conf.example/usr/share/doc/dhcp-4.2.5/ldap/usr/share/doc/dhcp-4.2.5/ldap/readme.ldap/usr/ share/doc/dhcp-4.2.5/ldap/dhcp.schema/usr/share/doc/dhcp-4.2.5/ldap/dhcpd-conf-to-ldap/usr/share/man/man1/ Omshell.1.gz/usr/share/man/man5/dhcpd.conf.5.gz/usr/share/man/man5/dhcpd.leases.5.gz/usr/share/man/man8/dhcpd.8.gz/usr/share/man/man8/dhcrelay.8.gz/ usr/share/systemtap/tapset/dhcpd.stp/var/lib/dhcpd/var/lib/dhcpd/dhcpd.leases/var/lib/dhcpd/dhcpd6.leases[[ email protected] dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example ./ DHCPD.CONFCP: Do you want to overwrite "./dhcpd.conf"? y[[email protected] dhcp]# sed -n "/^[^#]/p" dhcpd.conf # Displays lines option domain-name "Tz.com" in the configuration file that begin with a non-# number; #定义全局的域名 option domain-name-servers 172.16.0.1; #定义全局的dns域default-lease-time 3600;max-lease-time 7200; log-facility local7;subnet 172.16.0.0 netmask 255.255.0.0 { #定义dhcp服务范围range 172.16.61.1 172.16.61.61; #定义dhcp地址池option routers 172.16.61.2; #定义该地址池所分配的路由}[[email protected] dhcp]# systemctl start dhcpd #启动dhcp服务 [[email protected] dhcp]# ss -uanState Recv-Q Send-Q Local Address:Port Peer Address:Port UNCONN 0 0 *:67 *:*
DHCP requests for clients using the same physical network:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7B/52/wKioL1bLG56RkuHYAAA5aaMbeP0767.png "title=" 1.PNG " alt= "Wkiol1blg56rkuhyaaa5aambep0767.png"/>
Dhcpoffer from DHCP server
The address assigned to IS 172.16.61.1
Pxe:preboot Execution Environment (domain boot loading environment)
Booting the operating system through a network card
FileName "": The file name of the initial boot file to be loaded based on the boot of the NIC;
Next-server host:initial Boot file is located in the service host address;
Tftp-server:trivial
First, configure the Tftp-server
[[email protected] ~]# yum install -y tftp-server[[email protected] ~] # rpm -ql tftp-server/etc/xinetd.d/tftp/usr/lib/systemd/system/tftp.service/usr/lib/systemd/ system/tftp.socket/usr/sbin/in.tftpd/usr/share/doc/tftp-server-5.2/usr/share/doc/tftp-server-5.2/changes/usr/ share/doc/tftp-server-5.2/readme/usr/share/doc/tftp-server-5.2/readme.security/usr/share/man/man8/ In.tftpd.8.gz/usr/share/man/man8/tftpd.8.gz/var/lib/tftpboot[[email protected] ~]# systemctl start tftp.socket #启动tftp-server Service [[email protected] ~]# yum install -y syslinux #安装syslinux, offering a variety of bootloader[[email protected] ~]# rpm -ql syslinux | grep "\<pxe"/usr/share/doc/syslinux-4.05/pxelinux.txt/usr /share/syslinux/pxechain.com/usr/share/syslinux/pxelinux.0 #该文件为pxe使用到的bootloader
Ii. Configuring PXE (for example, CentOS 7)
[[email protected] tftpboot]# ll total dosage 39992-rw-r--r--. 1 root root 20832 2 Month 23 08:46 chain.c32 # Syslinux provided by Bootloader-rw-r--r--. 1 root root 35745476 3 Month 28 2015 initrd.img #提供ramdisk文件 (available on CD-ROM)-rw-r--r--. 1 root root 33756 2 Moon 23 08:46 mboot.c32 #syslinux提供的bootloader-rw-r--r--. 1 root root 26268 2 Month 23 08:46 memdisk #syslinux提供 -rw-r--r--. 1 root root 55140 2 Month 23 08:46 menu.c32 # Syslinux provided by Bootloader-rw-r--r--. 1 root root 26771 2 Month 23 08:37 pxelinux.0 #syslinux提供drwxr-xr-x. 2 root root 6 2 Month 23 08:47 pxelinux.cfg #创建该目录-rw-r--r--. 1 root root 5029136 3 Month 6 2015 vmlinuz #提供内核文件 (available on CD-ROM) [[email protected] pxelinux.cfg]# vim default # Create the default file under the Pxelinux.cfg directory default menu.c32 #展示文本界面 prompt 30 #提示符 timeout 60 #超时时长 menu title centos 7 pxe menu # global menu item &NBSP;&NBSP;LABLE&NBSP;LINUX&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp; #boot label menu lable install centos 7 x86_64 #菜单项名称 KERNEL vmlinuz #提供内核文件 append initrd= initrd.img inst.repo=http://172.16.61.2/centos7 ks=http://172.16.61.2/centos7.cfg #提供pxe的repo仓库以及ks文件 [[email protected] cdrom]# mount --bind /media/ cdrom/ /var/www/html/centos7 #使用光盘提供repo仓库 [[email protected] ~]# ls /var/www/html/centos7 centos7.cfg index.html #配置好yum仓库以及ks文件 [[email protected] ~]# systemctl start httpd #启动httpd
Third, configuration Dhcp-server
Subnet 172.16.0.0 netmask 255.255.0.0 {range 172.16.61.44 172.16.61.61; Option routers 172.16.61.2; FileName "pxelinux.0"; Next-server 172.16.61.2; #通过172.16.61.2 host load Pxelinux.0}[[email protected] ~]# systemctl start dhcpd #启动dhcp服务
Iv. Testing PXE
Use the same physical network host to adjust the boot sequence to boot the NIC to the hard disk boot
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7B/55/wKioL1bL2OvzV_OHAAAWx4MJyJA368.png "title=" 1.PNG " alt= "Wkiol1bl2ovzv_ohaaawx4mjyja368.png"/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7B/56/wKioL1bL4CixEFqDAABP7Odn3xE306.png "style=" float: none; "title=" 1.PNG "alt=" Wkiol1bl4cixefqdaabp7odn3xe306.png "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7B/56/wKiom1bL37yQtzsLAAAiAfEeavU123.png "style=" float: none; "title=" 2.PNG "alt=" Wkiom1bl37yqtzslaaaiafeeavu123.png "/>
When we need to install the operating system for multiple hosts in the LAN, PXE implements the unified installation requirements, we do not need to manually install the operating system for each host, but when we have different requirements for each host, for example, some hosts need to install CentOS6 have host need to install CENTOS7, PXE will not be able to provide us with a different operating system to choose from. Then we need to use the cobbler.
DHCP, PXE-based configuration