- Background
- Introduction
- Installation
- Configuration
- Edit tftpd-hpa Configuration File
- Modify Permissions on TFTP Root Directory
- Restart the tftpd-hpa Service
- Additional Information
- External Links
- How to install tftp server on Debian 11
- Installing TFTP server and client:
- Configuring the TFTP server:
- Upload and Download files using TFTP:
- TFTP vs FTP vs SFTP:
- Conclusion:
- About the author
- David Adams
- Установка TFTP сервера (tftpd) в Ubuntu Linux
- Установка сервера tftpd и службы openbsd-inetd
- Настройка tftpd
- Перезапуск службы inetd
- Проверка работы TFTP сервера, использование TFTP клиента
Background
A network administrator may find the need to deploy a TFTP server quickly and cost effectively. The reader may find that there is more than one TFTP server package available for Ubuntu systems.
including tftpd, atftpd, and tftpd-hpa. tftpd-hpa was chosen in this scenario because of its relative «up-to-date-ness» and availability of documentation.
Introduction
This document will guide the reader on how to setup a TFTP server that will allow clients to both download and upload files.
(This process has been completely tested and verified on 11/18/2015 using Ubuntu 14.04.3 Server and the latest version of tftpd-hpa available from the apt repositories (tftpd-hpa_5.2-7ubuntu3_amd64.deb))
Installation
sudo apt-get install tftpd-hpa.
Once the installation is complete, you will have a running TFTP server on your system that will be listening on all active network interfaces, on both IPv4 and IPv6. All you will be able to do is download files from the TFTP server. Uploading will not work. We will fix that in the Configuration section below.
You can confirm this by running.
sudo service tftpd-hpa status
The default configuration file for tftpd-hpa is /etc/default/tftpd-hpa.
The default root directory where files will be stored is /var/lib/tftpboot.
Configuration
Edit tftpd-hpa Configuration File
As mentioned before, all you will be able to do at this point is download files from the TFTP server. If you want to upload to the TFTP server, read on. To begin with, make a copy of the default tftpd-hpa configuration file.
sudo cp /etc/default/tftpd-hpa /etc/default/tftpd-hpa.ORIGINAL
Then, edit the tftpd-hpa configuration file.
sudo vi /etc/default/tftpd-hpa
and change the line that reads.
TFTP_OPTIONS="--secure --create"
and save the file and exit the vi editor.
Modify Permissions on TFTP Root Directory
The root directory where files must be stored in order to access them via TFTP is /var/lib/tftpboot. If you want to be able to upload to that directory, then perform the following command.
sudo chown -R tftp /var/lib/tftpboot
Restart the tftpd-hpa Service
To make the changes take effect, the tftpd-hpa service must be restarted. This can be accomplished by performing the following command.
sudo service tftpd-hpa restart
At this point you should now have a TFTP server that allows you to both download and upload files.
Additional Information
tftpd-hpa seems to be somewhat tied to traditional tftpd. For more information try.
External Links
- http://chschneider.eu/linux/server/tftpd-hpa.shtml — The first «how to» that I used to go through this process.
- http://askubuntu.com/questions/443117/how-to-configure-tftpd-hpa-to-allow-upload-of-new-files — The final link that lead me to discover the process of allowing uploads.
TFTP (последним исправлял пользователь 67 2015-11-19 21:50:29)
The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details
How to install tftp server on Debian 11
This tutorial explains how to set up a TFTP (Trivial File Transfer Protocol) server on Debian 11 and Linux-based distributions.
Before starting, let’s open the tftp port (69) using UFW (Uncomplicated Firewall), as shown in the following image.
Once the port is open, we can proceed with the TFTP installation.
Installing TFTP server and client:
To begin installing the TFTP service, use apt as shown in the screenshot below.
As said, the previous command installed the TFTP service. To install the TFTP client using apt, run the following command.
Configuring the TFTP server:
Once the TFTP server is installed, you need to configure it. The TFTP configuration file is located at /etc/default/tftpd-hpa. You can edit the configuration file using nano, as shown in the example below. On debian, run the following command.
The default configuration file seems like the image below where:
- TFTP_USERNAME: Here, you can specify the TFTP user; the default user is tftp.
- TFTP_DIRECTORY: Here, you can specify the TFTP directory to upload or download files from. By default, the directory /srv/tftp is created; you can leave it or define a new one (in such case, you’ll need to create it using the mkdir command).
- TFTP_ADDRESS: Here, you specify the TFTP IP address and port, which by default for TFTP is port 69
- TFTP_OPTIONS: Here, you can specify options; we’ll add the needed option to upload files to the TFTP server in our following examples.
In the screenshot below, you can see I only edited TFTP_ADDRESS to define the server IP and TFTP_OPTIONS to allow uploading files by adding the —create option.
After editing the configuration file, exit saving changes (For nano, press Ctrl+X and Y)
As you can see, the default tftp directory is where files are stored in /srv/ftp. On Debian 11, this directory is created by default when installing tftp. You can create a different one if needed. But you’ll need to change the user and group ownership to allow the defined user in the configuration file (By default, the tftp user) to store files inside.
To change the directory ownership to the tftp user, use the chown command as shown below.
Once reconfigured, restart the tftp service; you can do it using systemctl, as shown in the following example.
Upload and Download files using TFTP:
To connect to a TFTP server, just run tftp followed by the server IP address as shown in the following screenshot, in which tftp is used to connect to the server with IP address 192.168.1.103.
Once connected, to upload a file, you can use the put command followed by the file name you want to upload. In the example below, the file named linuxhintfile is uploaded to the server with IP address 192.168.1.103.
To download files, use the get command followed by the file name you want to download, as shown in the image below.
TFTP vs FTP vs SFTP:
Unlike FTP and SFTP, TFTP works under the UDP protocol; it is a faster but less secure and flexible alternative. TFTP doesn’t allow authentication, and users can’t modify files. Even the regular FTP protocol (Port 21) is the safest alternative. TFTP is mainly used for network boot processes and is almost unused.
The TFTP server doesn’t allow to show the TFTP directory content; users must know the file name they want to download.
Conclusion:
As you can see, the main advantage of the TFTP protocol is the simplicity of implementing it. Any Linux user level can easily set up a TFTP server. It is important to remember that TFTP is an unsafe implementation, and SFTP must be considered the main alternative to transfer files and filter unwanted access. Users must remember to open port 69 to allow TFTP traffic; this can be achieved using Iptables or UFW, as shown in the first step of this article.
You can get additional information on TFTP at https://linux.die.net/man/1/tftp.
I hope this tutorial explaining how to install a TFTP server on Debian 11 was useful. Keep following Linux Hint for additional Linux tips and tutorials.
About the author
David Adams
David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.
Установка TFTP сервера (tftpd) в Ubuntu Linux
TFTP — простой протокол для передачи файлов по сети, использует протокол UDP (по порту 69), не поддерживает аутентификацию и шифрование. TFTP часто используется для загрузки файлов (прошивок, конфигураций) на устройства (маршрутизаторы, мини-АТС и другие), но его можно использовать и для простой пересылки файлов по сети между компьютерами. Для Linux доступно несколько TFTP демонов (серверов): tftpd, atftpd, tftpd-hpa. Вы можете использовать любой из них. Я расскажу, как устанавливать tftpd.
Помимо tftpd нужно будет установить службу inetd. inetd — представляет собой сетевую службу, которая обрабатывает входящие соединения (TCP, UDP) и запускает соответствующую программу для обработки запроса. Я буду использовать службу openbsd-inetd. Есть еще служба xinetd, вы можете ее использовать, но настраивается она несколько иначе.
Установка сервера tftpd и службы openbsd-inetd
Установим сервер tftpd и openbsd-inetd, для этого выполним команду:
sudo apt-get install openbsd-inetd tftpd tftp
По завершении установки вы увидите сообщения вида:
. Настраивается пакет openbsd-inetd (0.20080125-4ubuntu2) . * Stopping internet superserver inetd [ OK ] * Not starting internet superserver: no services enabled Настраивается пакет tftpd (0.17-17ubuntu1) .
Настройка tftpd
По умолчанию TFTP сервер настроен на использование директории /srv/tftp. Мы настроим TFTP сервер так, чтобы он использовал для работы директорию /tftpboot. В этой директории будут храниться файлы, которые мы можем скачать с сервера или же закачать в нее. Отредактируем файл /etc/inetd.conf.
В файле найдите строки вида:
#:BOOT: TFTP service is provided primarily for booting. Most sites # run this only on machines acting as "boot servers." tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /srv/tftp
Аргумент /srv/tftp команды in.tftpd указывает на каталог в котором будут храниться файлы TFTP сервера. Заменим /srv/tftp на /tftpboot.
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
Создадим директорию /tftpboot:
sudo chown -R nobody /tftpboot
Перезапуск службы inetd
Чтобы новые настройки вступили в силу, перезапустим службу inetd:
sudo /etc/init.d/openbsd-inetd restart
На этом установка TFTP сервера завершена, проверим его работу.
Проверка работы TFTP сервера, использование TFTP клиента
Для начала установим TFTP клиент, чтобы можно было подключаться к TFTP северу. Для установки TFTP клиента выполните в терминале команду:
Теперь создадим на сервере в директории /tftpboot какой-нибудь файл, например, myfile. Для создания файла myfile и записи в него текста «This is my file» выполните в терминале команду:
echo This is my file > /tftpboot/myfile
Теперь мы можем запустить TFTP клиент командой tftp. Команда tftp принимает в качестве параметра IP адрес сервера. Если вы запускаете клиент на локальном компьютере, то укажите IP адрес 127.0.0.1, если же на удаленном компьютере, то укажите IP адрес сервера.
Когда клиент запустится, вы попадете в режим ввода команд для клиента TFTP. Выполните команду get myfile, которая означает получить файл с именем myfile с сервера.
В случае, если вы все сделали правильно, файл myfile загрузится с TFTP сервера. Для выхода из TFTP клиента введите команду quit.