From 5a090f6ac49acf0291dfd917881b331d111cbc4e Mon Sep 17 00:00:00 2001 From: TomasM Date: Thu, 22 Nov 2018 06:13:30 -0500 Subject: [PATCH] Provide Gateway address in DHCP response for PXE clients, so they can use internet --- Slax/debian/rootcopy/usr/bin/pxe | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Slax/debian/rootcopy/usr/bin/pxe b/Slax/debian/rootcopy/usr/bin/pxe index 01f3cea..97b7e9c 100755 --- a/Slax/debian/rootcopy/usr/bin/pxe +++ b/Slax/debian/rootcopy/usr/bin/pxe @@ -8,15 +8,23 @@ LIVE=/run/initramfs FTPROOT=/var/state/dnsmasq/root # find out our own IP address. If more interfaces are available, use the first one -IP="$(ls -1 /sys/class/net | egrep -v '^lo$' | sort | head -n 1 | xargs -r ifconfig | fgrep "inet " | tr -s " " | cut -d " " -f 3)" +IP="$(hostname -I | cut -d " " -f 1)" +GW=$(ip route show | grep default | grep -o "via.*" | cut -d " " -f 2) # if no IP is assigned to this computer, setup private address randomly if [ "$IP" = "" ]; then - killall dhcpcd 2>/dev/null + killall dhclient 2>/dev/null IP="10."$(($RANDOM/130+1))"."$(($RANDOM/130+1))".1" ifconfig $(ls -1 /sys/class/net | egrep -v '^lo$' | sort | head -n 1) $IP netmask 255.255.255.0 fi +# if gateway is not recognized, lets make our IP a gateway and enable forwarding +if [ "$GW" = "" ]; then + GW="$IP" + echo 1 > /proc/sys/net/ipv4/conf/all/forwarding + echo 1 > /proc/sys/net/ipv6/conf/all/forwarding +fi + echo Starting PXE server on $IP ... # calculate C class range @@ -71,6 +79,7 @@ APPEND initrd=/initrfs.img load_ramdisk=1 prompt_ramdisk=0 rw printk.time=0 $(ca # start the DHCP server and TFTP server dnsmasq --enable-tftp --tftp-root=/var/state/dnsmasq/root \ --dhcp-boot=pxelinux.0,"$IP",$IP \ +--dhcp-option=3,$GW \ --dhcp-range=$RANGE.2,$RANGE.250,infinite --log-dhcp # start HTTP server at port 7529 (that are the numbers you type on your phone to write 'slax')