阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下FTP和TFTP服务配置

144次阅读
没有评论

共计 10743 个字符,预计需要花费 27 分钟才能阅读完成。

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

3、FTP 配置

 

目前成熟系统设计中,都将 FTP 协议和传输定性为非安全传输协议。它和 telnet 登录方式,逐渐为 SFTP 和 SSH 协议所取代。在 Linux 流行版本中,SFTP 已经成为默认配置项目。
 
在 Linux 发行版的光盘中,已经包括了 vsftp 服务器安装包,是需要手工安装。

 

– 判断没有安装 vsftp

[root@SimpleLinuxUp ~]# rpm -qa | grep vsftp

 

加载安装光盘到一个目录中。

 

[root@SimpleLinuxUp /]# ls -l | grep rdcom

drwxr-xr-x  2 root  root      4096 Dec 26 10:29 rdcom

[root@SimpleLinuxUp /]# cd rdcom/

[root@SimpleLinuxUp rdcom]# ls -l

total 0

[root@SimpleLinuxUp rdcom]# mount /dev/cdrom /rdcom/

mount: block device /dev/cdrom is write-protected, mounting read-only

 

安装 vsftp-server 包。

 

[root@SimpleLinuxUp rdcom]# cd Server/

[root@SimpleLinuxUp Server]# pwd

/rdcom/Server

 

[root@SimpleLinuxUp Server]# ls -l | grep vsftp

-r–r–r–  99 root root  141003 Dec 17  2007 vsftpd-2.0.5-12.el5.i386.rpm

[root@SimpleLinuxUp Server]# rpm -ivh vsftpd-2.0.5-12.el5.i386.rpm

warning: vsftpd-2.0.5-12.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
 
Preparing…                ########################################### [100%]

  1:vsftpd                ########################################### [100%]

 

安装后,vsftpd 是没有自动启动的,作为系统服务也不能自动启动。

 

[root@SimpleLinuxUp Server]# service vsftpd status

vsftpd is stopped

 

[root@SimpleLinuxUp Server]# chkconfig –list vsftpd

vsftpd          0:off  1:off  2:off  3:off  4:off  5:off  6:off

 

启动服务,并且配置 vsftp 服务到适合的 level 等级。

 

[root@SimpleLinuxUp Server]# service vsftpd start

Starting vsftpd for vsftpd: [OK]

[root@SimpleLinuxUp Server]# service vsftpd status

vsftpd (pid 4030) is running…

 

[root@SimpleLinuxUp Server]# chkconfig –level 2345 vsftpd on

[root@SimpleLinuxUp Server]# chkconfig –list vsftpd

vsftpd          0:off  1:off  2:on    3:on    4:on    5:on    6:off

 

远程从客户端进行访问,直接使用 ftp 命令行客户端。

 

D:\>ftp

ftp> open 192.168.0.100

Connected to 192.168.0.100.

220 (vsFTPd 2.0.5)

User (192.168.0.100:(none)): Oracle

331 Please specify the password.

Password:

230 Login successful.

 

注意,处于安全的考虑,并不是所有的用户都可以使用 ftp 远程连接,比如 root。

 

D:\>ftp

ftp> open 192.168.0.100

Connected to 192.168.0.100.

220 (vsFTPd 2.0.5)

User (192.168.0.100:(none)): root

530 Permission denied.

Login failed.

 

如果确实需要 root 登录,可以修改配置文件 /etc/vsftpd/ftpusers 和 /etc/vsftpd/user_list,将其中的 root 屏蔽住。就可以支持登录。
 
 

[root@SimpleLinuxUp Server]# cat /etc/vsftpd/ftpusers

# Users that are not allowed to login via ftp

root

bin

daemon

adm

nobody

 

[root@SimpleLinuxUp Server]# cat /etc/vsftpd/user_list

# vsftpd userlist

# If userlist_deny=NO, only allow users in this file

# If userlist_deny=YES (default), never allow users in this file, and

# do not even prompt for a password.

# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers

# for users that are denied.

root

bin

daemon

adm

lp

sync

shutdown

halt

mail

news

uucp

operator

games

nobody

 

安装成功。

 

4、结论

 

在 Linux、AIX 中,很多的配置内容都是命令行 + 文本配置的方法来实现的。本篇介绍了 Linux 环境下 tftp 和 ftp 的配置手段,留待需要朋友待查。

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

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计10743字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中