This repository contains code that provides a working PXE server (via HTTP, TFTP, DHCP, and/or iPXE) implemented purely in Python. Please read DOCUMENTATION.md
for further explanation of the PyPXE project as well as recommended use. See the issues page for open issues, bugs, and enhancements/improvements.
DISCLAIMER: None of the implemented services are fully compliant with any standards or specifications. However, the true specifications and standards were followed when building PyPXE and while they work for PXE any other uses are purely coincidental. Use at your own risk.
PyPXE implements the following services for the purpose of creating a Python-based PXE environment: TFTP, HTTP, and DHCP. Each PyPXE service must be imported individually. For example, to import the TFTP service simply use:
from pypxe import tftp
or, if you prefer, you can use:
import pypxe.tftp
For more information on how each service works and how to manipulate them, see DOCUMENTATION.md
.
pypxe.server
uses all three services in combination with the option of enabling/disabling them individually while also setting some options. Run pypxe.server
with --help
or -h
to see what command line arguments you can pass. Treat the provided netboot
directory as tftpboot
that you would typically see on a TFTP server, put all of your network-bootable files in there and setup your menu(s) in netboot/pxelinux.cfg/default
.
Simply run the following command and you will have an out-of-the-box PXE-bootable server that runs TFTP and serves files out of the netboot
directory!
$ sudo python -m pypxe.server
If you require the ability to handle DHCP PXE requests then you can either enable the built-in DHCP server (after configuring, of course)...
$ sudo python -m pypxe.server --dhcp
...or start pypxe.server
in ProxyDHCP mode rather than a full DHCP server to prevent DHCP conflicts on your network...
$ sudo python -m pypxe.server --dhcp-proxy
The following are arguments that can be passed to pypxe.server
when running from the command line:
Argument | Description | Default |
---|---|---|
--ipxe |
Enable iPXE ROM | False |
--no-ipxe |
Disable iPXE ROM | True |
--http |
Enable built-in HTTP server | False |
--no-http |
Disable built-in HTTP server | True |
--dhcp |
Enable built-in DHCP server | False |
--dhcp-proxy |
Enable built-in DHCP server in proxy mode (implies --dhcp ) |
False |
--tftp |
Enable built-in TFTP server which is enabled by default | True |
--no-tftp |
Disable built-in TFTP server which is enabled by default | False |
--debug |
Enable selected services in DEBUG mode; services are selected by passing the name in a comma separated list. Options are: http, tftp and dhcp; one can also prefix an option with - to prevent debugging of that service; for example, the following will enable debugging for all services except the DHCP service --debug all,-dhcp . This mode adds a level of verbosity so that you can see what's happening in the background. |
'' |
--verbose |
Enable selected services in verbose mode; services are selected by passing the name in a comma separated list. Follows the same syntax for selecting service as --debug ._ |
'' |
--config |
Load configuration from JSON file. (see example_cfg.json ) |
None |
--static-config |
Load DHCP lease configuration from JSON file. (see example-leases.json ) |
None |
--save-leases |
Saves allocated leases on HUP , INT (^C ), ALRM and TERM . Loads on start if the file exists already |
None |
--syslog |
Specify a syslog server | None |
--syslog-port |
Specify a syslog server port | 514 |
Argument | Description | Default |
---|---|---|
--dhcp-server-ip DHCP_SERVER_IP |
Specify DHCP server IP address | 192.168.2.2 |
--dhcp-server-port DHCP_SERVER_PORT |
Specify DHCP server port | 67 |
--dhcp-begin DHCP_OFFER_BEGIN |
Specify DHCP lease range start | 192.168.2.100 |
--dhcp-end DHCP_OFFER_END |
Specify DHCP lease range end | 192.168.2.150 |
--dhcp-subnet DHCP_SUBNET |
Specify DHCP subnet mask | 255.255.255.0 |
--dhcp-router DHCP_ROUTER |
Specify DHCP lease router | 192.168.2.1 |
--dhcp-dns DHCP_DNS |
Specify DHCP lease DNS server | 8.8.8.8 |
--dhcp-broadcast DHCP_BROADCAST |
Specify DHCP broadcast address | '' |
--dhcp-fileserver DHCP_FILESERVER |
Specify DHCP file server IP address | 192.168.2.2 |
--dhcp-whitelist |
Only serve clients specified in the static lease file (--static-config ) |
False |
Argument | Description | Default |
---|---|---|
--tftp-server-ip TFTP_SERVER_IP |
Specify TFTP server IP address | 0.0.0.0 |
Argument | Description | Default |
---|---|---|
--http-server-ip HTTP_SERVER_IP |
Specify HTTP server IP address | 0.0.0.0 |
--http-port HTTP_PORT |
Specify HTTP server Port | 80 |
Argument | Description | Default |
---|---|---|
--netboot-dir NETBOOT_DIR |
Specify the local directory where network boot files will be served | 'netboot' |
--netboot-file NETBOOT_FILE |
Specify the PXE boot file name | automatically set based on what services are enabled or disabled, see DOCUMENTATION.md for further explanation |
Argument | Description | Default |
---|---|---|
--nbd NBD_BLOCK_DEVICE |
Specify the block device to be served by NBD and enable NBD. This can be a disk image. | '' |
--nbd-write |
Open the block device for write access. UNSAFE: Multiple clients can cause corruption | False |
--nbd-cow |
When write is enabled, create a volatile file per client with their changes. Clients can write but changes are not shared or kept. | True (Only applies if write is on) |
--nbd-cow-in-mem |
Client volatile changes are stored in RAM rather than on disk. WARNING: High RAM usage (up to sizeof(block device)*clients) | False |
--nbd-copy-to-ram |
Disk image is copied to RAM on start to speed up access. Changes are lost when write is used without cow. | False |
--nbd-server |
The NBD server IP address to bind to | 0.0.0.0 |
--nbd-port |
The NBD server port to bind to | 10809 |
Core.iso
located innetboot
is from the TinyCore Project and is provided as an example to network boot from using PyPXEchainload.kpxe
located innetboot
is theundionly.kpxe
from the iPXE Projectldlinux.c32
,libutil.c32
,pxelinux.0
,menu.c32
, andmemdisk
located innetboot
are from the SYSLINUX Project version 6.02