Home System Tutorial LINUX How to Set Up the Ancient and Simple TFTP Server on Linux

How to Set Up the Ancient and Simple TFTP Server on Linux

Feb 11, 2024 pm 07:42 PM
linux linux tutorial linux system linux command shell script embeddedlinux Getting started with linux linux learning

Did you know there's a simpler alternative to the popular file transfer protocol? It's TFTP, and here's how to set it up on Linux.

TFTP (Trivial File Transfer Protocol) was first defined in 1980. It is a fairly old protocol, published as TFTP Protocol Revision 2 in June 1981 by Karen R. Sollins in RFC 783 (Request for Comments).

In the early days, the main goal of TFTP was to send and receive files over the network. In particular, it is used to transfer files required during boot to enable the system to boot over the network.

The following describes how to set up a TFTP server on a Linux machine.

What is TFTP?

TFTP is still used for file transfer purposes, with no fundamental changes to the functionality it supports. TFTP is used to download and send files over UDP/IP. It does not have additional features such as identity and authorization controls, file listing, deletion or renaming that are common in other file transfer protocols.

Unlike the Advanced File Transfer Protocol, which uses TCP at the transport layer, it works on the UDP protocol and does not have functions such as checking whether data packets belonging to files will be sent to the other end. Because of this limitation, it is more suitable for use in a LAN rather than the Internet or WAN.

Despite all of these seemingly disadvantageous properties listed above, one aspect of the TFTP protocol that is very powerful is its simplicity. Compared to its alternatives, this protocol is very easy to implement, even for environments without an operating system. Due to this feature, it has a wide range of uses in embedded systems.

Install TFTP server on Linux

When using embedded devices, it is important to install the TFTP server service. On Linux systems, it is possible to run multiple TFTP server implementations. If you are using a Debian-based distribution, you can install the tftpd-hpa, tftpd or atftpd packages. If you are not sure which one to choose, consider installing the tftpd-hpa package.

┌──(linuxmi㉿linuxmi)-[~/linuxmi.com]
└─$ sudo apt-get install tftpd-hpa
Copy after login
如何在 Linux 上设置古老又简单的 TFTP 服务器

After installation, the TFTP service will start listening on UDP port 69. To serve files to other systems via a TFTP server, you need to remember some prerequisites:
The first is to copy the required files to the TFTP home directory or a directory under that home directory, and the second is to make the file permissions visible to the public
To find out what the TFTP server home directory is, you can look at the TFTP_DIRECTORY variable in the /etc/default/tftpd-hpa file. Typically, you'll see directories like /var/lib/tftpboot or /srv/tftp. If necessary, you can change this directory and restart the service.

┌──(linuxmi㉿linuxmi)-[~/linuxmi.com]
└─$ cat /etc/default/tftpd-hpa
Copy after login
如何在 Linux 上设置古老又简单的 TFTP 服务器

For ease of use, if you change the owner of the relevant TFTP home directory to your user account, you do not need to add the sudo prefix to every command you run. Use the chown command to change ownership from root to the current user:

sudo chown -R $USER /srv/tftp
Copy after login

The TFTP server package name and default home directory may vary depending on the Linux distribution used.

Use TFTP server to send files

Sometimes there are situations where TFTP is the only option for moving files from an embedded Linux system to an external environment. For example, sometimes the system may not support any writable media that can be used to transfer files.

In this case, since the TFTP client may be compiled in busybox, you can send the files saved in the system to the TFTP server on the network.

To use the TFTP client application, issue the busybox tftp command:

busybox tftp
Copy after login

To send the sample file to the TFTP server, you need to use the following command:

busybox tftp -l example.bin -p 192.168.1.111
Copy after login

Although the above command is correct, an error will occur while transferring the file to the TFTP server. Since the error message returned is not self-explanatory, it can be difficult to understand what the real problem is.

The problem here is because of some security procedures on the TFTP server. TFTP requires that a file with the same name should be located in the directory where the file will be written, as a prerequisite for file upload, and that write permissions for the file should be available to everyone.

In other words, files that do not exist on the TFTP server cannot be uploaded through the TFTP client. If you create an empty file with the same name and edit its access permissions, the above upload process will succeed. To do this, you must run the following command in the relevant TFTP server home directory:

cd /srv/tftp  
touch example.bin
chmod 666 example.bin
Copy after login

Now you can perform the upload successfully.

It is also possible to disable the above security measures and let the TFTP server create a file that does not exist. To do this, you can use the -c or --create parameter when starting the tftpd-hpa application. It is sufficient to add this parameter to the existing TFTPD_OPTIONS variable in the /etc/default/tftpd-hpa file:

# /etc/default/tftpd-hpa  
TFTP_USERNAME="tftp"  
TFTP_DIRECTORY="/srv/tftp"  
TFTP_ADDRESS="0.0.0.0:69"  
TFTP_OPTIONS="--secure --create"
Copy after login

Why use TFTP server for file transfer?

The most important advantage of TFTP is that it is fast and helps you save time. It is ideal for transferring configuration files of network devices to other systems. Furthermore, it has very simple usage standards. It can easily run with software on Windows and Linux based operating systems. Finally, in situations where FTP is technically not possible, TFTP can always save the day.

Of course, the biggest disadvantage is insecurity. Therefore, you must be very careful when transferring files using a TFTP server.

Except for file transfer, you cannot use the TFTP server to perform functions such as file deletion, editing, and modification. This feature is a major drawback for those using or looking for advanced systems. Finally, it doesn't require authentication, which is a major drawback if you're serious about your security.

Setting up TFTP on other operating systems

If you want to use TFTP on Windows, you don't need to install any third-party software. You can enable TFTP using the Turn Windows features on or off option in Control Panel.

The above is the detailed content of How to Set Up the Ancient and Simple TFTP Server on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

See all articles