--- title: PXE Server on Debian tags: บทความ, sysadmin, debian, linux, pxe, isc-dhcp, netboot, tftp --- # การทำ PXE server บน Debian **อ้างอิง** [Install Debian 9 (Stretch) via PXE Network Boot Server](https://www.howtoforge.com/tutorial/install-debian-9-stretch-via-pxe-network-boot-server/) และ [Diskless PXE netboot How-To for Debian 8 Jessie](https://www.linuxquestions.org/questions/blog/isaackuo-112178/diskless-pxe-netboot-how-to-for-debian-8-jessie-37169/) บทความนี้เป็นบันทึกเรียนรู้และทดลองทำ PXE Server ซึ่งทดสอบระบบโดยการติดตั้ง Debian โดย boot ตัวติดตั้งผ่าน Network แทน CD/USB ซึ่งสามารถนำไปประยุกต์ใช้ในการทำ diskless PC ได้ เพียงแต่ศึกษาเพิ่มเติมการ boot OS ต่างๆ ## สิ่งที่ต้องการ - DHCP Server - TFTP Server - [Debian Netboot images](http://ftp.nl.debian.org/debian/dists/buster/main/installer-amd64/current/images/netboot/netboot.tar.gz) ใช้ทดสอบการ PXE boot. **สภาพแวดล้อม** > - Network มี 2 range คือ > 1. 192.168.1.0/24 เป็น network กลางที่สามารถออก Internet ได้ > 1. 192.168.56.0/24 เป็น Host only network ซึ่งเป็น network ภายในเครื่องฯ ที่ทำ Virtual Box. > - คอมพิวเตอร์ VM มี 2 ตัว > 1. Srv-1 เป็น Debian 10 Buster ทำหน้าที่เป็น server ที่จะเป็นทั้ง DHCP and TFTP โดยถูกกำหนด fixed ip เป็น 192.168.56.61 > 1. PXEClient1 ทำหน้าที่เป็นเครื่องลูก ที่จะทดสอบ boot จาก PXE เพื่อทำการติดตั้ง Debian โดยจะได้ fixed ip จาก DHCP server > ``` $ sudo install tftpd-hpa syslinux pxelinux nfs-kernel-server isc-dhcp-server syslinux-utils syslinux ``` ## ขั้นตอนการติดตั้ง การทดลองทำบน Virtual Box จึงติดตั้งทุกอย่างบน Server VM เดียว และ Client VM อีกหนึ่งสำหรับทดสอบระบบ ### DHCP Server หากระบบที่ใช้งานอยู่ มี DHCP Server อยู่แล้ว ก็ไม่ต้องติดตั้ง DHCP Server นี้อีก แต่ต้องตั้งค่า DHCP ให้ติดต่อ TFTP Server (ศึกษาการตั้งค่าจากคู่มือ DHCP Server ที่ใช้งาน) - บน Linux นั้น ส่วนมากจะใช้ [ISC DHCP Server](https://www.isc.org/dhcp/) คำสั่งติดตั้ง ```shell=bash $ sudo apt update $ sudo apt install -y isc-dhcp-server ``` - เมื่อติดตั้งเสร็จ ก็ทำการตั้งค่า DHCP Server โดยมี 2 ไฟล์ที่ต้อง update คือ `/etc/dhcp/dhcpd.conf` และ `/etc/default/isc-dhcp-server.conf` **/etc/dhcp/dhcpd.conf** กำหนด IP range ที่จะใช้ และ options ต่างๆ รวมถึงการทำ fix ip ```config authoritative; # เปิดการใช้ dhcp server นี้ ## ตั้งค่า IP ที่จะใช้งาน และ option ต่างๆ subnet 192.168.56.0 netmask 255.255.255.0 { range 192.168.56.150 192.168.56.170; option routers 192.168.56.1; allow bootp; allow booting; filename "pxelinux.0"; } ## หากต้องการกำหนด IP ให้อุปกรณ์ host srv2 { hardware ethernet 08:00:27:55:40:24; fixed-address 192.168.56.155; } ``` **/etc/default/isc-dhcp-server.conf** กำหนด NIC ที่จะให้ dhcp แจก IP กับ network ไหน ```config INTERFACESv4="enp0s8" #INTERFACESv6="" ``` - ตั้งค่าต่างๆ แล้ว ลอง restart isc-dhcp-server จากประสบการณ์หากตั้งค่าถูกแล้ว ต้องทำการ reboot server ด้วย ```shell=bash $ sudo systemctl stop isc-dhcp-server $ sudo systemctl start isc-dhcp-server $ sudo systemctl status isc-dhcp-server ``` หากพบว่ามี dhcp รันอยู่แล้ว ให้ทำการ `sudo reboot` ### TFTP Server - ติดตั้ง tftpd-hpa ```shell=bash $ sudo apt install tftpd-hpa $ sudo mkdir -p /srv/tftp /srv/nfs1 ``` และจัดเตรียม - ตรวจสอบไฟล์ `/etc/default/tftpd-hpa` ตามการตั้งค่า ดังนี้ ```config TFTP_USERNAME="tftp" TFTP_DIRECTORY="/srv/tftp" TFTP_ADDRESS="0.0.0.0:69" TFTP_OPTIONS="--secure" ``` - restart service ```shell=bash $ sudo systemctl stop tftpd-hpa $ sudo systemctl start tftpd-hpa $ sudo systemctl status tftpd-hpa ``` ### เตรียม Debian Net Boot - ติดตั้ง Syslinux bootloader ```shell=bash $ sudo apt install syslinux-utils syslinux ``` - ทำการ download และ uncompress ```shell=bash $ wget http://ftp.nl.debian.org/debian/dists/buster/main/installer-amd64/current/images/netboot/netboot.tar.gz $ cd /srv/tftp $ sudo tar xzvf ~/netboot.tar.gz $ sudo cp /usr/lib/syslinux/memdisk /srv/tftp/ $ sudo ln -s /srv/tftp/debian-installer/amd64/bootnetx64.efi /srv/tftp/ ``` --- รายละเอียดเพิ่มเติมอื่น สามารถอ่านได้จากอ้างอิงข้างต้น ### คลิป YouTube {%youtube AQkU3lcB_x8%} **After the scene** {%youtube wz_QCfLdnN0%} ---  > ความคิดเห็นคำแนะนำของท่านต่อบทความนี้ จะถูกนำมาใช้ในการพัฒนาปรับปรุงงานเขียนของผม อย่างไงก็รบกวนแสดงความเห็นคิดด้วยนะครับ > > สนับสนุนการเงินได้ที่ > - บัญชีกสิกรไทย 003–3–29344–5
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.