Ubuntu 20.04 搭建 PXE/iPXE Server
Ubuntu 20.04 搭建 PXE iPXE Server
- Introduction
- PXE Server组件
- Configure Static IP Address
- Configure DHCP Service
- Configure TFTP Service
- PXE验证
- Configure FTP Service
- Configure Syslinux for PXE verification
- iPXE验证
- Install HTTP Server
- iPXE verification
Introduction
验证网卡的PXE功能,需要搭建PXE server,PXE是网卡从服务器端启动,然后下载系统镜像,从来实现远程系统启动或者系统安装到本地。
PXE Server组件
DHCP Server
负责给PXE网卡分配网络IP地址,并通过网络提供指定的系统启动文件。
TFTP Server
PXE网卡通过TFTP协议获取启动文件,例如:pxelinux.0,vmlinuz,initrd.img, undionly.kpxe等。
FTP Server
PXE网卡通过FTP协议下载系统镜像文件,包含一个完整的系统。
Syslinux
是一个启动加载器集合,可以从硬盘、光盘或通过 PXE 的网络引导启动系统。
iPXE
iPXE is the leading open source network boot firmware. It provides a full PXE implementation enhanced with additional features such as:
- boot from a web server via HTTP
- boot from an iSCSI SAN
- boot from a Fibre Channel SAN via FCoE
- boot from an AoE SAN
- boot from a wireless network
- boot from a wide-area network
- boot from an Infiniband network
- control the boot process with a script
下面以 Ubuntu 20.04 为例来示例如何搭建一个自用的PXE Server的过程。
Configure Static IP Address
选定一个网卡作为接下来DHCP Server的外接端口,此处选定网卡 enp1s0 配置静态IP 192.168.10.10。
root@pxe-server:/home/pxe/Desktop# cat /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:# version: 2# renderer: NetworkManagerethernets:enp1s0:dhcp4: nodhcp6: noaddresses: [192.168.10.10/24]gateway4: 192.168.10.1nameservers:addresses: [114.114.114.114]root@pxe-server:/home/pxe/Desktop# ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255ether xx:xx:xx:xx:xx:xx txqueuelen 1000 (Ethernet)
也可以通过ifconfig的方法来配置临时IP,系统重启需要重新配置。有时发现重新开机后,之前配置的静态IP没有成功,那就手动配置一次,然后重新启动DHCP Server即可。
root@pxe-server:/home/pxe/Desktop# ifconfig enp1s0 192.168.10.10
Configure DHCP Service
- 安装DHCP Server
root@pxe-server:/home/pxe/Desktop# apt install isc-dhcp-server
- 编辑/etc/default/isc-dhcp-server
此处选择DHCP Server要绑定的网卡 enp1s0.
root@pxe-server:/home/pxe/Desktop# cat /etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
#INTERFACESv4=""
#INTERFACESv6=""
INTERFACES="enp1s0" #可以用这个参数设置,避免后续报出Error/warning.
- 编辑/etc/dhcp/dhcpd.conf
此处配置DHCP Server的关键信息,包括IP地址段,路由,针对PXE Server,还需要包括pxe启动image, next-server.
root@pxe-server:/home/pxe/Desktop# cat /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
## option definitions common to all supported networks...
option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;#这行注释掉,有时导致DHCP client获取IP失败default-lease-time 600;
max-lease-time 7200;# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
#log-facility local7;# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.#subnet 10.152.187.0 netmask 255.255.255.0 {#}# This is a very basic subnet declaration.#subnet 10.254.239.0 netmask 255.255.255.224 {# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.#subnet 10.254.239.32 netmask 255.255.255.224 {# range dynamic-bootp 10.254.239.40 10.254.239.60;
# option broadcast-address 10.254.239.31;
# option routers rtr-239-32-1.example.org;
#}# A slightly different configuration for an internal subnet.
#subnet 10.5.5.0 netmask 255.255.255.224 {# range 10.5.5.26 10.5.5.30;
# option domain-name-servers ns1.internal.example.org;
# option domain-name "internal.example.org";
# option subnet-mask 255.255.255.224;
# option routers 10.5.5.1;
# option broadcast-address 10.5.5.31;
# default-lease-time 600;
# max-lease-time 7200;
#}
option client-architecture code 93 = unsigned integer 16;
subnet 192.168.10.0 netmask 255.255.255.0 {range 192.168.10.11 192.168.10.30;
# option domain-name-servers 192.168.10.2, 192.168.10.3;
# option domain-name "internal.example.org";
# option subnet-mask 255.255.255.0;option routers 192.168.10.1;
# option broadcast-address 192.168.10.2;
# default-lease-time 600;
# max-lease-time 7200;# tftp server IP Addressnext-server 192.168.10.10;# ++++++++++++++++++++++++ For PXE Boot file#filename "pxelinux.0";# ------------------------ For PXE Boot file# ++++++++++++++++++++++++ For iPXE Boot filesif exists user-class and option user-class = "iPXE" {filename "ipxe.script"; # for iPXE booting scripts} elsif option client-architecture = 00:00 {filename "undionly.kpxe"; # for booting legacy PXE} else {filename "ipxe.efi"; # for booting UFEI PXE}# ------------------------ For iPXE Boot files
}# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.#host passacaglia {# hardware ethernet 0:0:c0:5d:bd:95;
# filename "vmunix.passacaglia";
# server-name "toccata.example.com";
#}# Fixed IP addresses can also be specified for hosts. These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP. Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
#host fantasia {# hardware ethernet 08:00:07:26:c0:a5;
# fixed-address fantasia.example.com;
#}# You can declare a class of clients and then do address allocation
# based on that. The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.#class "foo" {# match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
#}#shared-network 224-29 {# subnet 10.17.224.0 netmask 255.255.255.0 {# option routers rtr-224.example.org;
# }
# subnet 10.0.29.0 netmask 255.255.255.0 {# option routers rtr-29.example.org;
# }
# pool {# allow members of "foo";
# range 10.17.224.10 10.17.224.250;
# }
# pool {# deny members of "foo";
# range 10.0.29.10 10.0.29.230;
# }
#}
- Enable DHCP service
配置完成后,重启DHCP service,之后如果发现DHCP不工作的时候,都可以通过这种方式重启来修正。
root@pxe-server:/home/pxe/Desktop# service isc-dhcp-server restart
root@pxe-server:/home/pxe/Desktop# service isc-dhcp-server status
● isc-dhcp-server.service - ISC DHCP IPv4 serverLoaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)Active: active (running) since Thu 2021-04-22 17:16:17 CST; 1s agoDocs: man:dhcpd(8)Main PID: 2827 (dhcpd)Tasks: 4 (limit: 8778)Memory: 4.8MCGroup: /system.slice/isc-dhcp-server.service└─2827 dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf enp1s04月 22 17:16:17 pxe-server sh[2827]: Wrote 1 leases to leases file.
4月 22 17:16:17 pxe-server dhcpd[2827]: Listening on LPF/enp1s0/xx:xx:xx:xx:xx:xx/192.168.10.0/24
4月 22 17:16:17 pxe-server sh[2827]: Listening on LPF/enp1s0/xx:xx:xx:xx:xx:xx/192.168.10.0/24
4月 22 17:16:17 pxe-server sh[2827]: Sending on LPF/enp1s0/xx:xx:xx:xx:xx:xx/192.168.10.0/24
4月 22 17:16:17 pxe-server sh[2827]: Sending on Socket/fallback/fallback-net
4月 22 17:16:17 pxe-server dhcpd[2827]: Sending on LPF/enp1s0/xx:xx:xx:xx:xx:xx/192.168.10.0/24
4月 22 17:16:17 pxe-server dhcpd[2827]: Sending on Socket/fallback/fallback-net
4月 22 17:16:17 pxe-server dhcpd[2827]: Server starting service.
4月 22 17:16:18 pxe-server dhcpd[2827]: reuse_lease: lease age 118 (secs) under 25% threshold, reply with unaltered, existing lease for 192.168.10.11
4月 22 17:16:18 pxe-server dhcpd[2827]: DHCPREQUEST for 192.168.10.11 from xx:xx:xx:xx:xx:xx ( ) via enp1s0
Configure TFTP Service
- 安装TFTP服务
root@pxe-server:/home/pxe/Desktop# apt install tftpd-hpa
- 配置/etc/default/tftpd-hpa
root@pxe-server:/home/pxe/Desktop# cat /etc/default/tftpd-hpa
# /etc/default/tftpd-hpaTFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp" #下载文件目录
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"
- Enable TFTP service
root@pxe-server:/home/pxe/Desktop# service tftpd-hpa restart
root@pxe-server:/home/pxe/Desktop# service tftpd-hpa status
● tftpd-hpa.service - LSB: HPAs tftp serverLoaded: loaded (/etc/init.d/tftpd-hpa; generated)Active: active (running) since Thu 2021-04-22 17:44:09 CST; 1s agoDocs: man:systemd-sysv-generator(8)Process: 1817 ExecStart=/etc/init.d/tftpd-hpa start (code=exited, status=0/SUCCESS)Tasks: 1 (limit: 8778)Memory: 1.0MCGroup: /system.slice/tftpd-hpa.service└─1825 /usr/sbin/in.tftpd --listen --user tftp --address :69 --secure /srv/tftp4月 22 17:44:09 pxe-server systemd[1]: Starting LSB: HPAs tftp server...
4月 22 17:44:09 pxe-server tftpd-hpa[1817]: * Starting HPAs tftpd in.tftpd
4月 22 17:44:09 pxe-server tftpd-hpa[1817]: ...done.
4月 22 17:44:09 pxe-server systemd[1]: Started LSB: HPA's tftp server.
PXE验证
Configure FTP Service
用来下载系统安装镜像的服务有几种选项,FTP,HTTP,NFS等,此处选择FTP.
- 安装 FTP Server
root@pxe-server:/home/pxe/Desktop# apt install vsftpd
FTP的默认文件夹为"/srv/ftp/",需要把OS Image copy到这个目录,以下为redhat8.1的OS images.
root@pxe-server:/home/pxe/Desktop# ls /srv/
ftp tftp
root@pxe-server:/home/pxe/Desktop# ls /srv/ftp/
AppStream EFI extra_files.json images media.repo RPM-GPG-KEY-redhat-release
BaseOS EULA GPL isolinux RPM-GPG-KEY-redhat-beta TRANS.TBL
配置/etc/vsftpd.conf
Enable FTP service
root@pxe-server:/home/pxe/Desktop#service vsftpd status
● vsftpd.service - vsftpd FTP serverLoaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)Active: active (running) since Tue 2021-04-13 05:36:40 CST; 12h agoMain PID: 32304 (vsftpd)Tasks: 1 (limit: 154342)Memory: 21.5MCGroup: /system.slice/vsftpd.service└─32304 /usr/sbin/vsftpd /etc/vsftpd.conf4 13 05:36:40 pxeserver systemd[1]: Starting vsftpd FTP server...
4 13 05:36:40 pxeserver systemd[1]: Started vsftpd FTP server.
Configure Syslinux for PXE verification
如果不需要验证PXE,这一章节的操作可以略过,直接到下一章节,可以配置iPXE。
- install Syslinux
root@pxe-server:/home/pxe/Desktop# apt install syslinux
安装完成后,可以从下列目录中找到legacy/uefi启动image
root@pxe-server:/home/pxe/Desktop# ls /usr/lib/syslinux
mbr memdisk modules
root@pxe-server:/home/pxe/Desktop# ls /usr/lib/syslinux/modules
bios efi32 efi6
Copy pxelinux.0文件到"/srv/tftp/“目录,此处应该包含所有用到的boot image,包括iPXE的,这几个文件名字都包含在”/etc/dhcp/dhcpd.conf".
从OS image文件中copy initrd.img,vmlinuz到tftp/pxeboot/目录中
root@pxe-server:/home/pxe/Desktop# ls /srv/ftp/images/pxeboot/ #redhat8.1的OS images
initrd.img vmlinuz
root@pxe-server:/home/pxe/Desktop# ls /srv/tftp/pxeboot/
initrd.img vmlinuz
- 配置pxelinux.cfg/default文件
root@pxe-server:/home/pxe/Desktop# cat /srv/tftp/pxelinux.cfg/default
default redhat81
timeout 3
prompt 0
label redhat81
menu title redhat 8.1 pxe installtion
kernel /pxeboot/vmlinuz
append initrd=/pxeboot/initrd.img inst.stage2=ftp://192.168.10.10/
此时,legacy PXE的配置完成,可以用来验证PXE的功能了。
iPXE验证
Install HTTP Server
iPXE默认不是support FTP server,需要安装HTTP Server来完成安装文件的传输,安装过程十分简单。
root@pxe-server:/home/pxe/Desktop# apt install apache2
root@pxe-server:/home/pxe/Desktop# service apache2 status
安装完成后,把安装文件copy到/var/www/html目录,把默认的index.html删除即可。
root@pxe-server:/home/pxe/Desktop# ls /var/www/html
RHEL8.3
iPXE verification
此处用来配置iPXE,iPXE可以同时support legacy and uefi PXE。
root@pxe-server:/home/pxe/Desktop# apt install ipxe
root@pxe-server:/home/pxe/Desktop# cp /usr/lib/ipxe/{ipxe.efi,undionly.kpxe} /srv/tftp/
root@pxe-server:/home/pxe/Desktop# ls /srv/tftp/
ipxe.efi undionly.kpxe ipxe.script
针对ipxe.script,此处给出一个示例:
#!ipxe:start
menu iPXE Boot Options
item shell iPXE shell
item linux-net Linux OS installation
item exit Exit to BIOS
choose --default linux-net --timeout 10000 option && goto ${option}
:shell
shell
:linux-net
set server_root http://192.168.10.10/
initrd ${server_root}/RHEL8.3/images/pxeboot/initrd.img
kernel ${server_root}/RHEL8.3/images/pxeboot/vmlinuz inst.repo=${server_root}/RHEL8.3/ initrd=initrd.img
boot
:exit
exit
Ubuntu 20.04 搭建 PXE/iPXE Server相关推荐
- ubuntu 20.04搭建samba文件共享服务器,实现基于Linux和Windows的共享文件服务
ubuntu 20.04搭建samba文件共享服务器,实现基于Linux和Windows的共享文件服务--超详细 一,samba的基本概念 二,samba的安装 三,samba的基本配置 创建文件夹 ...
- Ubuntu 20.04 搭建 Fisco-BCOS 2.8.0 区块链系统
0. 摘要 本文根据 Fisco-BCOS 及 Webase 官方文档,就安装过程做了详细描述.针对官方文档中一些不清楚的地方,做了补充,方便新手搭建. 1. 准备工作 1.1 系统: Ubuntu ...
- Ubuntu 20.04 搭建 DVWA 靶场
文章目录 0x01. 前言 0x02. 系统和靶场信息 0x03. 具体安装配置过程 0x01. 前言 之前写过在Kali 上搭建 DVWA,因为Kali上已经预装了很多软件和依赖,所以比较方便,最近 ...
- ubuntu 20.04搭建elasticsearch-7.6.2
目录 ubuntu安装 es7.6.2 安装步骤 上传至Ubuntu 服务器 这里我存放在 /usr/ 解压elasticsearch-7.6.2-linux-x86_64.tar.gz 出现问题及解 ...
- ubuntu 20.04搭建ESP-ADF开发环境
1. 下载esp-gitee-tools 包含给 gitee 其他仓库提供的扩展工具,包括 submodule 更新.开发工具安装等. git clone https://gitee.com/Espr ...
- 第三篇 Ubuntu 20.04 搭建AI开发环境
文章目录 摘要 CUDA安装方法 1.检查驱动 2.安装CUDA 3.配置PATH 安装cuDNN 安装Anaconda 安装PyCharm 摘要 这篇文章包括CUDA的安装方法.cuDNN安装方法. ...
- Ubuntu 20.04集群手动安装OpenStack Yoga
文章目录 基础配置 基础中的基础 软件配置 OpenStack keystone X11转发 Glance 控制节点 Placement 控制节点 Nova 控制节点 计算节点 Neuron 控制节点 ...
- Ubuntu 20.04 VNC server 搭建及客户端访问
vnc server安装 sudo su root apt-get update apt install gnome-panel gnome-settings-daemon metacity naut ...
- Ubuntu 20.04 LTS Server搭建软路由
首先是安装Ubuntu 20.04 LTS Server,这个步骤网上都可以找到 注意的是,安装的时候开启openssh-server 下述步骤是是指定安装好Ubuntu 20.04 LTS Serv ...
最新文章
- LeetCode-笔记-199. 二叉树的右视图——BFS广度优先搜索
- Linux: TLB 查询流程
- 个人博客前端模板_博客设计——概述
- vue 使用element 菜单与tab页联动
- selenium python_Python+Selenium基础入门及实践
- 三折线弹塑性滞回模型matlab,动力弹塑性滞回模型-迈达斯汇总.doc
- 数据科学 IPython 笔记本 8.1 matplotlib
- ROS入门-4.安装ROS系统(ubuntu20.04版本安装ros的noetic版本)
- hdu 1203 I NEED A OFFER!
- bad interpreter: No such file or directory解决
- 适配器模式的极简概述
- 电脑显示未安装任何音频输出设备_音频频谱分析仪插件Voxengo SPAN Plus介绍及安装教程...
- java和php基础部分相同或异同
- 难以回答的问题:注册监听器有什么用?
- 中文版的XP转换为英文版的XP和XP多国语言包
- IOS设备之armv6,armv7,armv7s,arm64
- iOS 逆向 越狱 砸壳 获取
- Cramér‐von Mises检验
- An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)
- 计算机主流处理器介绍,现在电脑主流配置有哪些 2017主流电脑配置清单一览表...