• linux系统中安装TFTP服务(简单文件传输协议)


    TFTP(Trivial File Transfer Protocol)

    TFTP:  基于UDP协议,占用的端口号为69

    TFTP:不需要客户端的权限认证(匿名用户模式??)

    TFTP:传输琐碎文件(trivial)时,效率高

    TFTP服务采用服务器端/客户端的方式,以下实验中PC1为服务器端,IP为192.168.10.10,PC2为客户端

    1、在PC1服务器端安装TFTP的软件包

    [root@PC1 ~]# yum install tftp-server.x86_64 tftp
    Loaded plugins: langpacks, product-id, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    rhel7                                                    | 4.1 kB     00:00     
    Resolving Dependencies
    --> Running transaction check
    ---> Package tftp.x86_64 0:5.2-11.el7 will be installed
    ---> Package tftp-server.x86_64 0:5.2-11.el7 will be installed
    --> Processing Dependency: xinetd for package: tftp-server-5.2-11.el7.x86_64
    --> Running transaction check
    ---> Package xinetd.x86_64 2:2.3.15-12.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package             Arch           Version                 Repository     Size
    ================================================================================
    Installing:
     tftp                x86_64         5.2-11.el7              rhel7          35 k
     tftp-server         x86_64         5.2-11.el7              rhel7          44 k
    Installing for dependencies:
     xinetd              x86_64         2:2.3.15-12.el7         rhel7         128 k
    
    Transaction Summary
    ================================================================================
    Install  2 Packages (+1 Dependent package)
    
    Total download size: 207 k
    Installed size: 373 k
    Is this ok [y/d/N]: y
    Downloading packages:
    --------------------------------------------------------------------------------
    Total                                              560 kB/s | 207 kB  00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : 2:xinetd-2.3.15-12.el7.x86_64                                1/3 
      Installing : tftp-server-5.2-11.el7.x86_64                                2/3 
      Installing : tftp-5.2-11.el7.x86_64                                       3/3 
    rhel7/productid                                          | 1.6 kB     00:00     
      Verifying  : 2:xinetd-2.3.15-12.el7.x86_64                                1/3 
      Verifying  : tftp-5.2-11.el7.x86_64                                       2/3 
      Verifying  : tftp-server-5.2-11.el7.x86_64                                3/3 
    
    Installed:
      tftp.x86_64 0:5.2-11.el7            tftp-server.x86_64 0:5.2-11.el7           
    
    Dependency Installed:
      xinetd.x86_64 2:2.3.15-12.el7                                                 
    
    Complete!

    2、在PC1服务器端开启tftp服务(tftp服务是使用xinetd服务程序来管理的)

    [root@PC1 ~]# vim /etc/xinetd.d/tftp
    # default: off
    # description: The tftp server serves files using the trivial file transfer \
    #       protocol.  The tftp protocol is often used to boot diskless \
    #       workstations, download configuration files to network-aware printers, \
    #       and to start the installation process for some operating systems.
    service tftp
    {
            socket_type             = dgram
            protocol                = udp
            wait                    = yes
            user                    = root
            server                  = /usr/sbin/in.tftpd
            server_args             = -s /var/lib/tftpboot
            disable                 = no    ## 此处改为no
            per_source              = 11
            cps                     = 100 2
            flags                   = IPv4
    }

    3、在PC1服务器端重启xinetd服务

    [root@PC1 ~]# systemctl restart xinetd.service 
    [root@PC1 ~]# systemctl enable xinetd

    4、在PC1服务器端将69端口加入防火墙允许策略中

    [root@PC1 ~]# firewall-cmd --permanent --add-port=69/udp
    success
    [root@PC1 ~]# firewall-cmd --reload
    success

    5、PC2客户机中安装tftp

    [root@PC2 test]# yum install tftp-server.x86_64 tftp
    Loaded plugins: langpacks, product-id, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    Resolving Dependencies
    --> Running transaction check
    ---> Package tftp.x86_64 0:5.2-11.el7 will be installed
    ---> Package tftp-server.x86_64 0:5.2-11.el7 will be installed
    --> Processing Dependency: xinetd for package: tftp-server-5.2-11.el7.x86_64
    --> Running transaction check
    ---> Package xinetd.x86_64 2:2.3.15-12.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package             Arch           Version                 Repository     Size
    ================================================================================
    Installing:
     tftp                x86_64         5.2-11.el7              rhel7          35 k
     tftp-server         x86_64         5.2-11.el7              rhel7          44 k
    Installing for dependencies:
     xinetd              x86_64         2:2.3.15-12.el7         rhel7         128 k
    
    Transaction Summary
    ================================================================================
    Install  2 Packages (+1 Dependent package)
    
    Total download size: 207 k
    Installed size: 373 k
    Is this ok [y/d/N]: y
    Downloading packages:
    --------------------------------------------------------------------------------
    Total                                              1.4 MB/s | 207 kB  00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : 2:xinetd-2.3.15-12.el7.x86_64                                1/3 
      Installing : tftp-server-5.2-11.el7.x86_64                                2/3 
      Installing : tftp-5.2-11.el7.x86_64                                       3/3 
      Verifying  : 2:xinetd-2.3.15-12.el7.x86_64                                1/3 
      Verifying  : tftp-5.2-11.el7.x86_64                                       2/3 
      Verifying  : tftp-server-5.2-11.el7.x86_64                                3/3 
    
    Installed:
      tftp.x86_64 0:5.2-11.el7            tftp-server.x86_64 0:5.2-11.el7           
    
    Dependency Installed:
      xinetd.x86_64 2:2.3.15-12.el7                                                 
    
    Complete!

    6、 在PC2客户机中清空防火墙策略并保存

    [root@PC2 test]# iptables -F
    [root@PC2 test]# service iptables save
    iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

    7、tftp服务远程登录的默认路径为/var/bin/tftpboot, 在PC1服务器端创建测试数据

    [root@PC1 tftpboot]# pwd
    /var/lib/tftpboot
    [root@PC1 tftpboot]# ls
    [root@PC1 tftpboot]# echo "i am pc1.file" > pc1.file
    [root@PC1 tftpboot]# ls
    pc1.file

    8、在PC2服务端创建测试数据,并测试传输

    [root@PC2 test]# pwd
    /home/test
    [root@PC2 test]# echo "i am pc2" > pc2.file
    [root@PC2 test]# ls
    pc2.file
    [root@PC2 test]# pwd
    /home/test
    [root@PC2 test]# echo "i am pc2" > pc2.file
    [root@PC2 test]# ls
    pc2.file
    [root@PC2 test]# tftp 192.168.10.10
    tftp> get pc1.file  ## 测试传输至本地
    tftp> quit
    [root@PC2 test]# ls
    pc1.file  pc2.file
    [root@PC2 test]# cat pc1.file 
    i am pc1.file
    [root@PC2 test]# ls
    pc1.file  pc2.file
    [root@PC2 test]# tftp 192.168.10.10
    tftp> put pc2.file
    Error code 1: File not found    ## 上传报错 
    tftp> 

    9、在PC1服务器端修改配置文件

    [root@PC1 tftpboot]# vim /etc/xinetd.d/tftp
    # default: off
    # description: The tftp server serves files using the trivial file transfer \
    #       protocol.  The tftp protocol is often used to boot diskless \
    #       workstations, download configuration files to network-aware printers, \
    #       and to start the installation process for some operating systems.
    service tftp
    {
            socket_type             = dgram
            protocol                = udp
            wait                    = yes
            user                    = root
            server                  = /usr/sbin/in.tftpd
            server_args             = -s /var/lib/tftpboot -c
            disable                 = no
            per_source              = 11
            cps                     = 100 2
            flags                   = IPv4
    }

    10、在PC1服务器端重启xinetd服务

    [root@PC1 tftpboot]# systemctl restart xinetd.service 

    11、 在PC2客户端继续测试上传

    [root@PC2 test]# ls
    pc1.file  pc2.file
    [root@PC2 test]# pwd
    /home/test
    [root@PC2 test]# tftp 192.168.10.10
    tftp> put pc2.file 
    Error code 0: Permission denied   ## 上传继续报错,这次显示权限问题
    tftp> 

    12、在PC1服务器端修改路径权限

    [root@PC1 lib]# ll -d /var/lib/tftpboot/
    drwxr-xr-x. 2 root root 21 Dec 15 00:38 /var/lib/tftpboot/
    [root@PC1 lib]# chmod -R 777 /var/lib/tftpboot/
    [root@PC1 lib]# ll -d /var/lib/tftpboot/
    drwxrwxrwx. 2 root root 21 Dec 15 00:38 /var/lib/tftpboot/

    13、在PC2客户端继续测试上传

    [root@PC2 test]# ls
    pc1.file  pc2.file
    [root@PC2 test]# tftp 192.168.10.10
    tftp> put pc2.file 
    tftp> 
    [root@PC1 tftpboot]# ls
    pc1.file  pc2.file
    [root@PC1 tftpboot]# cat pc2.file 
    i am pc2
    [root@PC1 tftpboot]# pwd
    /var/lib/tftpboot

    终于实现上传。

  • 相关阅读:
    牛客训练三:处女座的训练(贪心)
    牛客训练二:处女座的砝码(数学题)
    牛客训练二:处女座的签到题(STL+精度+三角形求面积公式)
    牛客训练:小a与黄金街道(欧拉函数+快速幂)
    数论二(快速幂)
    数论一(欧拉函数+费马小定理)
    字典树模板
    springboot在idea的RunDashboard如何显示出来
    网关集成Swagger出现404错误
    maven一直加载2.0.0.M7 的 config server 失败
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14136556.html
Copyright © 2020-2023  润新知