Provide Gateway address in DHCP response for PXE clients, so they can use internet
parent
263216ab42
commit
5a090f6ac4
|
|
@ -8,15 +8,23 @@ LIVE=/run/initramfs
|
||||||
FTPROOT=/var/state/dnsmasq/root
|
FTPROOT=/var/state/dnsmasq/root
|
||||||
|
|
||||||
# find out our own IP address. If more interfaces are available, use the first one
|
# 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 no IP is assigned to this computer, setup private address randomly
|
||||||
if [ "$IP" = "" ]; then
|
if [ "$IP" = "" ]; then
|
||||||
killall dhcpcd 2>/dev/null
|
killall dhclient 2>/dev/null
|
||||||
IP="10."$(($RANDOM/130+1))"."$(($RANDOM/130+1))".1"
|
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
|
ifconfig $(ls -1 /sys/class/net | egrep -v '^lo$' | sort | head -n 1) $IP netmask 255.255.255.0
|
||||||
fi
|
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 ...
|
echo Starting PXE server on $IP ...
|
||||||
|
|
||||||
# calculate C class range
|
# 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
|
# start the DHCP server and TFTP server
|
||||||
dnsmasq --enable-tftp --tftp-root=/var/state/dnsmasq/root \
|
dnsmasq --enable-tftp --tftp-root=/var/state/dnsmasq/root \
|
||||||
--dhcp-boot=pxelinux.0,"$IP",$IP \
|
--dhcp-boot=pxelinux.0,"$IP",$IP \
|
||||||
|
--dhcp-option=3,$GW \
|
||||||
--dhcp-range=$RANGE.2,$RANGE.250,infinite --log-dhcp
|
--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')
|
# start HTTP server at port 7529 (that are the numbers you type on your phone to write 'slax')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue