Tech/OSS/PyPXE
Jump to navigation
Jump to search
PXE Fun with Python
A project called PyPXE creates a quick and dirty DHCP, TFTP, and HTTP server along with other toys for an all in one PXE solution or iPXE solution.
Howto
User
The services needed use a privileged port so need to be done as root.
lathama@lappy:~$ su Password: root@lappy:/home/lathama#
Get PyPXE
Now to get the source
root@lappy:/home/lathama# cd /usr/src root@lappy:/usr/src# git clone https://github.com/psychomario/PyPXE.git Cloning into 'PyPXE'... remote: Counting objects: 2152, done. remote: Compressing objects: 100% (9/9), done. remote: Total 2152 (delta 3), reused 7 (delta 2), pack-reused 2140 Receiving objects: 100% (2152/2152), 9.19 MiB | 9.14 MiB/s, done. Resolving deltas: 100% (1296/1296), done. root@lappy:/usr/src# cd PyPXE
Networking
Lets set an unused interface to the example IP address of 192.168.2.2
root@lappy:/usr/src/PyPXE# ip addr add 192.168.2.2/24 dev <your device name>
Firewall
Firewall, ugh, many systems using firewalld block TFTP by default so you need to check it and maybe enable it with something like
root@lappy:/usr/src/PyPXE# firewall-cmd --zone=public --add-service=tftp
Start PyPXE
We will start the server up with the example configuration. Special note that we did not install PyPXE we are running it from the source.
root@lappy:/usr/src/PyPXE# python -m pypxe.server --dhcp --tftp 2018-05-28 18:18:34,187 [INFO] PyPXE Starting TFTP server... 2018-05-28 18:18:34,187 [INFO] PyPXE Starting DHCP server... 2018-05-28 18:18:34,190 [INFO] PyPXE PyPXE successfully initialized and running!
Testing
Lets test the TFTP server real quick.
lathama@lappy:~$ tftp tftp> connect 192.168.2.2 tftp> binary tftp> get Core.iso Received 8318976 bytes in 0.6 seconds tftp> quit
Things are working, yeah!
2018-05-28 19:55:05,770 [DEBUG] PyPXE.TFTP.Client.('192.168.2.100', 49168) Sending block 5907 2018-05-28 19:55:05,771 [DEBUG] PyPXE.TFTP.Client.('192.168.2.100', 49168) Sending block 5908 2018-05-28 19:55:05,772 [DEBUG] PyPXE.TFTP.Client.('192.168.2.100', 49168) Sending block 5909 2018-05-28 19:55:05,772 [INFO] PyPXE.TFTP.Client.('192.168.2.100', 49168) Completed sending /usr/src/PyPXE/netboot/Core.iso 2018-05-28 19:55:48,702 [DEBUG] PyPXE.DHCP Received message 2018-05-28 19:55:48,702 [DEBUG] PyPXE.DHCP <--BEGIN MESSAGE-->