您的位置:首页 > 运维架构 > Linux

centos安装配置tftp服务器

2016-07-28 10:02 1746 查看
PC机系统:Win7  虚拟机linux系统:centosx86

1.tftp概论

TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务。端口号为69。

TFTP是一个传输文件的简单协议,它基于UDP协议而实现,但是我们也不能确定有些TFTP协议是基于其它传输协议完成的。此协议设计的时候是进行小文件传输的。因此它不具备通常的FTP的许多功能,它只能从文件服务器上获得或写入文件,不能列出目录,不进行认证,它传输8位数据。

在嵌入式开发中,tftp服务器常用于通过PC机服务端的tftp目录中下载文件到开发板中,以待烧写或运行,操作方便,并且速度也可以。

2.linux下的tftp安装

首先确认系统上是否安装了tftp软件包:

[zzx@localhost ~]$ rpm -qa | grep tftp

tftp-server-0.49-8.el6.i686

若没显示安装,则使用sudo yum install -y tftp-server进行安装。

3.建立tftp服务主工作目录

使用命令mkdir建立tftp的主工作目录(这个目录用于存放宿主机与目标机之间使用tftp时传递的文件)



4.配置tftp

linux下的tftp服务是由xinetd(还有openbsd-inetd等其他服务)所设定的,默认情况下tftp是处于关闭状态。所以要修改tftp的配置文件,开启tftp服务。

tftp的配置文件在/etc/xinetd.d/tftp下:

[zzx@localhost ~]$ sudo 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

{

        disable                 = no               #添加这一项

        socket_type             = dgram

        protocol                = udp

        wait                    = yes

        user                    = root

        server                  = /usr/sbin/in.tftpd

        server_args             = -s /home/zzx/tftp -c      
#修改这一项,这里-s指tftp服务器的根目录,我这里根目录就上上面建立的tftp文件夹,-c指能创建文件

        disable                 = yes       #可以去掉这一项,和添加的第一项重复设置了,控制tftp服务器的关闭和启动,默认值为“yes”,即关闭tftp服务器,这里修改为“no”,即开启tftp服务器

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

说明:修改项server_args=-s    <path>   -c,其中<path>处可以改为你的tftp-server的根目录,参数-s指定chroot,-c指定了可以创建文件。

5.开启xinetd服务
使用命令:sudo service xinetd restart 使上面的更改生效



使用netstat命令查看69端口,确认tftp服务是否开启



出现udp   0   0 0.0.0.0:69  0.0.0.0:*   3092/ 则开启成功。

6.SeLinux策略修改

SeLinux保持开启状态的话,系统有可能会阻止tftp客户端的下载,可以将它暂时关闭:

[zzx@localhost ~]$ sudo setenforce 0      #这里0表示设置SeLinux为permissive模式,1代表设置SeLinux为enforcing模式

可以使用getenforce 命令查看SeLinux状态

[zzx@localhost ~]$ getenforce

Permissive

如果想彻底禁用SeLinux,修改其配置文件将它禁用

[zzx@localhost ~]$ sudo vim /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

SELINUX=disable    #此处设置为disable即可

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

7.防火墙策略修改

系统开启了防火墙也有可能会阻止tftp客户端的下载,我们可以在防火墙规则中使能tftp,只需要使能tftp所使用的69端口即可。

[zzx@localhost ~]$ sudo /sbin/iptables -I INPUT -p tcp --dport 69 -j ACCEPT

[zzx@localhost ~]$ sudo /sbin/iptables -I INPUT -p udp --dport 69 -j ACCEPT

[zzx@localhost ~]$ sudo /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

[zzx@localhost ~]$ sudo /sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT

[zzx@localhost ~]$ sudo /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT

保存

[zzx@localhost ~]$ sudo /etc/rc.d/init.d/iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]

重启防火墙

[zzx@localhost ~]$ sudo service iptables restart

iptables:将链设置为政策 ACCEPT:filter [确定]

iptables:清除防火墙规则:[确定]

iptables:正在卸载模块:[确定]

iptables:应用防火墙规则:[确定]

查看防火墙状态

[zzx@localhost ~]$ sudo service iptables status

如果希望在系统启动时防火墙不启动,我们可以用ntsysv关闭防火墙服务,同时还可 以设置tftp服务在系统启动时就开启

[zzx@localhost ~]$ sudo ntsysv

  [ ] ip6tables             

  [ ] iptables

  [*] tftp   

  [*] xinetd

#使用空格键进行选中或取消

8.本机测试tftp服务器功能

首先,在你之前设置的tftp根目录下创建一个文件,我自己的是在/home/zzx/tftp/下用vim tt.c创建文件并写入“hello,zzx! ”使用ifconfig查看本机ip地址



通过命令tftp 192.168.127.128进入tftp命令模式,输入help命令,查看tftp支持的命令,通过命令get tt.c 就可以将/home/zzx/tftp下的tt.c文件下载到当前目录下(我当前在/home/zzx/目录下),用ls命令查看当前目录下是否存在tt.c,用cat tt.c查看tt.c的内容





OK!

遇到的问题:

1.没有tftp命令!



解决:安装的是tftp server包 ,但是没有安装tftp命令包

使用命令sudo yum install -y tftp安装

安装后如下有了



注意:是tftp和tftp server的版本要是一样的!

2.使用tftp获取超时



解决:原来是我自己之前的SeLinux未配置好,上面的是正确配置。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: