Ubuntu 20.04 搭建 PXE/iPXE Server

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: NetworkManager
  ethernets:
    enp1s0:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.10.10/24]
      gateway4: 192.168.10.1
      nameservers:
        addresses: [114.114.114.114]

root@pxe-server:/home/pxe/Desktop# ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.10  netmask 255.255.255.0  broadcast 192.168.10.255
        ether 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

  1. 安装DHCP Server
root@pxe-server:/home/pxe/Desktop# apt install isc-dhcp-server
  1. 编辑/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.
  1. 编辑/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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值