TFTP server setup on linux within 5 minitues

1.First install tftp server using below command
$sudo apt-get install tftp-hpa

2.Create file with your favorite editor.
$vim tftp.sh

3.Copy below content and save it.

#!/bin/sh

check_status() {
ret=$?
if [ “$ret” -ne “0” ]; then
echo “Failed setup, aborting..”
exit 1
fi
}

tftprootdefault=/tftpboot

echo “——————————————————————————–”
echo “Which directory do you want to be your tftp root directory?(if this directory does not exist it will be created for you)”
read -p “[ $tftprootdefault ] ” tftproot

if [ ! -n “$tftproot” ]; then
tftproot=$tftprootdefault
fi

echo
echo “——————————————————————————–”
echo “This step will set up the tftp server in the $tftproot directory.”
echo
echo “Note! This command requires you to have administrator priviliges (sudo access) ”
echo “on your host.”
read -p “Press return to continue” REPLY

if [ -d $tftproot ]; then
echo
echo “$tftproot already exists, not creating..”
else
sudo mkdir -p $tftproot
check_status
sudo chmod 777 $tftproot
check_status
sudo chown nobody $tftproot
check_status
fi

tftpcfg=/etc/inetd.conf
tftpdef=/etc/default/tftpd-hpa

echo “tftp dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s $tftproot” > $tftpcfg
check_status
echo
echo “$tftpcfg successfully created”

echo “#/etc/default/tftpd-hpa
RUN_DAEMON=”\””yes”\””
TFTP_USERNAME=”\””tftp”\””
#TFTP_DIRECTORY=”\””/var/lib/tftpboot”\””
TFTP_DIRECTORY=”\””$tftproot”\””
TFTP_ADDRESS=”\””0.0.0.0:69″\””
TFTP_OPTIONS=”\””–secure””\”” > $tftpdef
check_status
echo
echo “$tftpdef successfully created”

echo
echo “Restarting tftp server”
sudo restart tftpd-hpa
echo “——————————————————————————–”
echo “done”

4.Now execute using below command
$sudo ./tftp.sh

5.Thats it enjoy…………….

Posted in Uncategorized | Leave a comment