# TFTP **Repository Path**: openes/tftp ## Basic Information - **Project Name**: TFTP - **Description**: TFTP 简单文件传输协议环境搭建 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-04-28 - **Last Updated**: 2025-07-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TFTP 简单文件传输环境搭建 ### TFTP 简介 * TFTP(Trivial File Transfer Protocol, 简单文件传输协议)是 TCP/IP 协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务。我们可以使用 TFTP 来加载内核 zImage、设备树和其他较小的文件到开发板 DDR 上,从而实现网络挂载。 ### 步骤一:准备工作 * 参考[【Linux 网络环境搭建】](https://gitee.com/openes/netcfg)完成准备工作。 * 这里结合自己的网络配置来验证,我的相关 IP 配置为: * 开发板 IP:192.168.5.4 * 虚拟机 Ubuntu IP:192.168.5.2 ### 步骤二:安装和配置 xinetd * 在 Ubuntu 终端中执行以下命令,安装 xinetd。 ``` sudo apt-get install xinetd ``` ![](./images/安装xinetd.png) * 查询 /etc/ 下是否存在 xinetd.conf 文件,没有的话则自己新建一个。已经有 xinetd.conf 文件可以直接跳到步骤三。 * 如果没有 xinetd.conf 这个文件,那就自己创建一个。 ``` sudo vi /etc/xinetd.conf ``` * 创建出来的文件是空白的,修改 xinetd.conf 文件内容如下: ``` # Simple configuration file for xinetd # # Some defaults, and include /etc/xinetd.d/ defaults { # Please note that you need a log_type line to be able to use log_on_success # and log_on_failure. The default is the following : # log_type = SYSLOG daemon info } includedir /etc/xinetd.d ``` ![](./images/xinetd.conf内容.png) ### 步骤三:创建 TFTP 目录 * 新建 TFTP 目录,这里建立在 /home/thin-wind/Design 目录下,目录名为 tftp。将 tftp 目录赋予 可读可写可执行权限。 ``` mkdir tftp chmod 777 tftp/ ``` ![](./images/创建tftp目录.png) ### 步骤四:安装 tftp 服务程序 * 涉及到的 tftp 服务程序有两个,分别是 tftp-hpa 和 tftpd-hpa。使用如下命令安装: ``` sudo apt-get install tftp-hpa tftpd-hpa ``` ![](./images/安装tftp服务程序.png) * 执行以下指令打开 tftpd-hpa 配置文件,修改 tftp 目录为步骤三创建的 TFTP 服务器工作目录。 ``` sudo vi /etc/default/tftpd-hpa ``` ![](./images/修改tftpd-hpa.png) * 执行以下指令创建 /etc/xinetd.d/tftp 文件,配置 /etc/xinetd.d/tftp 文件,将 tftp 路径设置为自 己的 tftp 路径。 ``` cd /etc/xinetd.d/ sudo vi tftp ``` * 在 /etc/xinetd.d/tftp 这个文件中添加如下内容。 ``` server tftp { socket_type = dgram wait = yes disable = no user = root protocol = udp server = /usr/sbin/in.tftpd server_args = -s /home/thin-wind/Design/tftp -c #log_on_success += PID HOST DURATION #log_on_failure += HOST per_source = 11 cps =100 2 flags =IPv4 } ``` ![](./images/修改tftp内容.png) * 重启 tftpd-hpa。 ``` sudo service tftpd-hpa restart ``` * 重启 xinetd 服务。 ``` sudo service xinetd restart ``` * 至此, tftp 简单文件传输环境已经搭建完成。 ### TFTP 传输文件测试 * 在 Ubuntu 系统的 tftp 目录下创建一个名为 tftp_test.txt 的文件,并下入字符串 "Hello world." ``` touch tftp_test.txt echo "Hello world." > tftp_test.txt ``` ![](./images/tftptest.png) * 在开发板文件系统执行以下指令将 Ubuntu 虚拟机(192.168.5.2)TFTP 工作目录下的 tftp_test.txt 文件拷贝到开发板中。 ``` tftp -g -r tftp_test.txt 192.168.5.2 cat tftp_test.txt ``` ![](./images/测试TFTP.png) * 可以看到 tftp_test.txt 成功传输到开发板上,TFTP 环境搭建成功。