实例介绍
【实例简介】
About
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.
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 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
PyPXE Server Arguments
The following are arguments that can be passed to pypxe.server 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 |
--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 |
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 | '' |
--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 |
TFTP Service Arguments
Argument | Description | Default |
---|---|---|
--tftp-server-ip TFTP_SERVER_IP | Specify TFTP server IP address | 0.0.0.0 |
--tftp-port TFTP_PORT | Specify TFTP server Port | 69 |
HTTP Service Arguments
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 |
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 |
【核心代码】
相关软件
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论