Recently I decide to jump into the pool of using diskless Ubuntu. Basically the client computer downloads the necessary files from the Ubuntu server every time during the boot. To keep things simple and easy, Ubuntu does that by using TFTP. So the first step is to set up a TFTP server on the server. For those who haven’t heard of TFTP, it is similar to FTP, except that it has no security feature, and the function is extremely limited. Anyway, here is how to set up a TFTP server on Ubuntu 11.10:
Installing TFTP sounds easy. However, I’ve heard that many people experienced many issues during the installation, such as Error code 2: Access violation issue. That’s why I create this tutorial. If you follow exact the same steps, you will not experience any problem.
First, let’s install all the necessary packages:
sudo apt-get install xinetd tftpd tftp -y
Next, we need to create a configuration file:
sudo nano /etc/xinetd.d/tftp
Put the following content into the file.
service tftp { protocol = udp port = 69 socket_type = dgram wait = yes user = nobody server = /usr/sbin/in.tftpd server_args = var/lib/tftpboot -s disable = no }
In the server_args, I have var/lib/tftpboot, which represents the location of the tftp root, i.e., /var/lib/tftpboot. Notice that I skip the root /.
Now let’s change the ownership of the directory:
sudo mkdir /var/lib/tftpboot sudo chown -R nobody:nobody /var/lib/tftpboot sudo chmod -R 777 /var/lib/tftpboot
and start the TFTP service:
sudo service xinetd stop sudo service xinetd start
Verify the TFTP is running correctly or not:
netstat -na | grep LIST | grep 69
You should see something like this:
tcp 0 0 0.0.0.0:69 0.0.0.0:* LISTEN
Test: Upload a file to TFTP Server
Now let’s test the TFTP server by logging into the server first:
tftp localhost
and upload a file:
tftp> put myfile.jpg Sent 56733279 bytes in 5.7 seconds
Quit:
q
Make sure that file has been uploaded:
ls -l /var/lib/tftpboot
Test: Download a file from TFTP Server
Now, let’s go to a different directory and download the file we just upload.
cd some_other_directory
and log in to the tftp server again:
tftp localhost
and get the file:
tftp> get myfile.jpg Received 56733279 bytes in 5.7 seconds
You are done.
Troubleshooting (e.g., Error code 2: Access violation)
If you see a message like: Error code 2: Access violation
Make sure that you:
– Follow the exact procedure in this tutorial
– Make sure that the tftp is started with -s flag.
– Check the permission of the directory, i.e., 777
– After you’ve made any changes to the TFTP configuration, make sure that you stop and start the inet service again.
– Don’t forget to quit tftp before retrying the command.
That’s it!
Enjoy TFTP.
–Derrick
Our sponsors:
This Howto helped me much, but I can’t get tftp working.
Did you try “get myfile.jpg” after “put myfile.jpg”?
I opened http://ubuntuforums.org/showthread.php?t=1891866&highlight=access+code+violation
Please, can you give your opinion?
Hi ego,
If you see a message like: Error code 2: Access violation
Make sure that you:
– Check the permission of the directory, i.e., 777
– Make sure that the tftp is started with -s flag.
Thanks.
–Derrick
I’ve put a bug, can you take a look at https://bugs.launchpad.net/ubuntu/+source/netkit-tftp/+bug/901273
Hi ego,
No it is not a bug, at least in the latest version of Ubuntu. Take a look to my another post: [Solved]TFTP: Error code 2: Access violation.
Thanks.
–Derrick
HI. Looked like this was going to be a good reference. I can’t make this work
sudo chown -R nobody:nobody /var/lib/tftpboot
sudo chmo7 -R 777 /var/lib/tftpboot
Changed nobody:nobody to nobody:nogroup
and
chmo7 to chown
stopped and started.
No joy. Access violation 2. The tftpboot looks like this
drwxr-xr-x 2 777 nogroup
I started the service but netstat -na | grep LIST | grep 22 doesnt give the expected output. How do I troubleshoot that please?
Never mind, it works anyway… Thanks for this.
change to:
server_args = -s /var/lib/tftpboot
not correct
sudo chown -R nobody:nobody /var/lib/tftpboot
sudo chmo7 -R 777 /var/lib/tftpboot
correct
sudo chown -R nobody:nogroup /var/lib/tftpboot
sudo chown -R 777 /var/lib/tftpboot
becouse it works on 69 port, so grep 69
and when you put a file, it uploads with 600 permission, and when you tries to get file, you get access violation
sorry
>sudo chown -R 777 /var/lib/tftpboot
chmod
Thanks for all of your comments. Hope it helps those who experience the access violation error.
Value too large for defined data type why? i try to put a 2 gb file.
does anyone have a solution for “Permission denied” error while trying to get a file?
try “chmod -R 777” not “chown -R 777”; 777 are permissions, not a username.
touch /var/lib/tftpboot/
chmod 777 /var/lib/tftpboot/
tftp localhost
tftp> put
if you “error 2”
touch /var/lib/tftpboot/file_name
chmod 777 /var/lib/tftpboot/file_name
tftp localhost
tftp> put file_name
Pingback: Setting TFTP Server in Linux Mint 12 | Ordinary Man
This was a fantastic post and it helped me immensely.
I hope you don’t mind but I copied and pasted your post to my blog, but made sure to give you the credit. If you do not want me to keep your post there let me know and I will take it down and just keep the link back to your post.
Thanks again for posting this great How-To.
http://www.edwardcrosby.com/2012/08/20/setting-tftp-server-in-linux-mint-12/
To check the service you should run this:
netstat -anu | grep 69
And the output should look like this:
udp 0 0 0.0.0.0:69 0.0.0.0:*
Why are you looking looking to see if port 22 is listening? That’s the SSH port! Shouldn’t you be looking for port 69?
Your config file is also missing the leading slash on ‘var/lib/tftpboot’, it should be ‘/var/lib/tftpboot’
you put udp in the conf, and get tcp in netstat ?
Yes, that is strange…i think it must look like this:
# netstat -a | grep -i tftp
udp 0 0 *:tftp *:*
Pingback: ubuntu - TFTP: cannot send/recive file, showing Error: TFTP, Opcode: Error Code(5) - ITTone