Skip to content

zhausong/PyPXE

 
 

Repository files navigation

About

This repository contains code that provides a working PXE server (via HTTP, TFTP, DHCP, and/or iPXE) implemented purely in Python. Currently, only Python 2.6 and newer is supported. 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 thes 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.

Usage

Using PyPXE as a Library

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.

QuickStart

pypxe-server.py uses all three services in combination with the option of enabling/disabling them individually while also setting some options. Edit the pypxe-server.py settings to your preferred settings or run 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.

Note: Python 2.6 does not include the argparse module, it is included in the standard library as of 2.7 and newer. The argparse module is required to take in command line arguments and pypxe-server.py will not run without it.

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 pypxe-server.py

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 pypxe-server.py --dhcp

...or start pypxe-server.py in ProxyDHCP mode rather than a full DHCP server to prevent DHCP conflicts on your network...

$ sudo python pypxe-server.py --dhcp-proxy

PyPXE Server Arguments

The following are arguments that can be passed to pypxe-server.py when running from the command line:

Main Arguments
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
--no-dhcp Disable built-in DHCP server True
--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. ''
--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
--syslog Specify a syslog server None
--syslog-port Specify a syslog server port 514
DHCP Service Arguments
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 '<broadcast>'
--dhcp-fileserver-ip DHCP_FILESERVER_IP Specify DHCP file server IP address 192.168.2.2
--dhcp-whitelist Only serve clients specified in the static lease file (--static-config) False
File Name/Directory Arguments
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
Network Block Device Arguments
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

Notes

  • Core.iso located in netboot is from the TinyCore Project and is provided as an example to network boot from using PyPXE
  • chainload.kpxe located in netboot is the undionly.kpxe from the iPXE Project
  • ldlinux.c32, libutil.c32, pxelinux.0, menu.c32, and memdisk located in netboot are from the SYSLINUX Project version 6.02

About

Pure Python2 PXE (DHCP-(Proxy)/TFTP/HTTP/NBD) Server

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%