手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下FTP和TFTP服务配置

[日期:2014-05-05] 来源:Linux社区  作者:Linux [字体:大 中 小]

FTP和TFTP是我们经常使用的文件传输协议。在Linux中,sftp协议由于其安全性的优点,被作为默认的链接协议。但是,一些场合下,我们依然需要使用ftp和tftp协议进行文件传输。本篇主要介绍配置方法,供有需要的朋友待查。

--------------------------------------分割线 --------------------------------------

相关阅读:

Ubuntu下tftp服务搭建 http://www.linuxidc.com/Linux/2012-08/67933.htm

TFTP服务器配置 http://www.linuxidc.com/Linux/2012-07/64785.htm

Ubuntu Linux配置TFTP下载服务器 http://www.linuxidc.com/Linux/2010-12/30394.htm

Ubuntu 11.10 配置tftp Server http://www.linuxidc.com/Linux/2012-05/60808.htm

Ubuntu 12.04 搭建TFTP服务 http://www.linuxidc.com/Linux/2014-04/100144.htm

Ubuntu 12.04 搭建tftp服务器的安装、设置、调试 http://www.linuxidc.com/Linux/2014-04/100114.htm

--------------------------------------分割线 --------------------------------------

1、 环境准备

 

我们选择Linux 2.6内核进行测试。

 

[root@SimpleLinuxUp ~]# uname -r

2.6.18-128.el5

 

当前OS运行在level 3模式下。

 

[root@SimpleLinuxUp ~]# grep init /etc/inittab

# inittab      This file describes how the INIT process should set up

#  0 - halt (Do NOT set initdefault to this)

#  6 - reboot (Do NOT set initdefault to this)

id:3:initdefault:

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit

 

默认情况下,tftp服务器包是安装上的,而FTP服务器没有安装。

 

[root@SimpleLinuxUp Server]# rpm -qa | grep ftp

tftp-server-0.42-3.1

ftp-0.17-35.el5

lftp-3.5.1-2.fc6

 

2、TFTP服务器安装配置

 

TFTP是一种比较特殊的文件传输协议。相对于FTP和目前经常使用的SFTP,TFTP是基于TCP/IP协议簇,用于进行简单文件传输,提供简单、低开销的传输服务。TFTP的端口设置为69。
 
相对于常见的FTP,TFTP有两个比较好的优势:

ü  TFTP基于UDP协议,如果环境中没有TCP协议,是比较合适的;

ü  TFTP执行和代码占用内存量比较小;

默认情况下,Linux内部是安装了tftp服务器包的。但是默认是不启动的。

 

[root@SimpleLinuxUp ~]# chkconfig --list tftp

tftp            off

 

启用和禁用tftp服务是通过配置文件/etc/xinetd.d/tftp,将其中参数设置。

 

[root@SimpleLinuxUp ~]# vi /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 /tftpboot -c

        disable                = no

        per_source              = 11

        cps                    = 100 2

        flags                  = IPv4

}

 

配置文件中,将disable默认值从yes改为no。适当修改server_args参数,主要是其中的tftp根目录地址。

Tftp服务是不需要单独启动的,是作为xinetd服务的一个附属对象连带启动。

 

 

[root@SimpleLinuxUp ~]# service xinetd status

xinetd (pid 2194) is running...

[root@SimpleLinuxUp ~]# cd /

[root@SimpleLinuxUp /]# mkdir /tftpboot

mkdir: cannot create directory `/tftpboot': File exists

[root@SimpleLinuxUp /]# cd /tftpboot/

[root@SimpleLinuxUp tftpboot]# cd ..

[root@SimpleLinuxUp /]# chmod -R 777 /tftpboot/

 

由于连接使用UDP端口,我们将防火墙和SELinux配置关闭。

 

[root@SimpleLinuxUp /]# service iptables stop

[root@SimpleLinuxUp /]# service iptables status

Firewall is stopped.

 

对xinetd服务重启,连带将tftp服务启动。

 

[root@SimpleLinuxUp /]# service xinetd restart

Stopping xinetd: [  OK  ]

Starting xinetd: [  OK  ]

 

[root@SimpleLinuxUp /]# chkconfig --list tftp

tftp            on

 

使用netstat判断UDP端口开启。

 

[root@SimpleLinuxUp /]# netstat -nlp | grep udp

udp        0      0 0.0.0.0:772                0.0.0.0:*                              1868/rpc.statd     

udp        0      0 0.0.0.0:775                0.0.0.0:*                              1868/rpc.statd     

udp        0      0 0.0.0.0:69                  0.0.0.0:*                              3869/xinetd       

(篇幅原因,有省略……)

 

从远程服务器启动连接,笔者从windows环境客户端启动。TFTP是可以不输入用户名和密码的,所以对于安全文件传输是不满足的。

 

 

C:\Documents and Settings\liuzy>tftp

Transfers files to and from a remote computer running the TFTP service.

TFTP [-i] host [GET | PUT] source [destination]

 

  -i              Specifies binary image transfer mode (also called

                  octet). In binary image mode the file is moved

                  literally, byte by byte. Use this mode when

                  transferring binary files.

  host            Specifies the local or remote host.

  GET            Transfers the file destination on the remote host to

                  the file source on the local host.

  PUT            Transfers the file source on the local host to

                  the file destination on the remote host.

  source          Specifies the file to transfer.

  destination    Specifies where to transfer the file.

 

测试客户端与服务器根目录之间的文件互相拷贝传输。

 

C:\Documents and Settings\liuzy>tftp 192.168.0.100 put cogtrwin.ini

Transfer successful: 536 bytes in 1 second, 536 bytes/s

 

[root@SimpleLinuxUp tftpboot]# ls -l

total 12

-rw-rw-rw- 1 nobody nobody  507 Jan 28 10:39 cogtrwin.ini

drwxrwxrwx 4 root  root  4096 Dec 26 09:46 linux-install

 

D:\>tftp 192.168.0.100 get cogtrwin.ini

Transfer successful: 536 bytes in 1 second, 536 bytes/s

 

TFTP是一种简单的文件传输解决方案。

 更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2014-05/1012p2.htm

linux
相关资讯       tftp 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款