tftp(client、server)配置详解

来源:互联网 发布:西门子系统编程入门 编辑:程序博客网 时间:2024/05/14 13:28

tftp服务器,默认规则是可以下载,但是上传文件的话, 必须在tftpboot中,有一个相同名字的文件,而且具备相应的可读写(覆盖)的权限.这样才能上传文件

tftp 

第一步:安装tftp tftpd 软件包

 apt-get install tftp tftpd xinetd    前者是客户端,后者是服务程序。


Setting up tftpd (0.17-17ubuntu1) ...

 

所以一共是安装了三个软件包。

tftd 服务程序

tftp  客户端程序

openbsd-inetd  inetd服务器的debian移植版本。

 

===========================================

关于penbsd的inetd软件包的说明如下:

OpenBSD 互联网超级服务器

inetd 服务器是一个专门管理入网连接网络后台程序.它的配置文件定义了当收到入 网连接时运行什么程序.任何服务端口都可以用TCP或UDP协议配置.

这是一个有 Debian 专用特色的 OpenBSD 后台移植版.该软件包支持 IPv6,内建的 libwrap 访问控制,绑定到特定地址,UNIX 域套接字和套接字缓冲调解.

 

=================================================

第二步:   配置

root@ubuntu:~# vi /etc/inetd.conf

 

==================================================

第三步 : 新建/tftpboot文件夹

 

文件夹的权限如下:

root@ubuntu:~# ls -l

total 4

drwxrwxrwx 2 root root 4096 2011-02-27 18:37 tftpboot

 

root@ubuntu:~# ll tftpboot

total 8

drwxrwxrwx  2 root root 4096 2011-02-27 18:37 ./

drwx------ 19 root root 4096 2011-02-27 18:38 ../

 

 

据说要改写这个命令。

 tftp        dgram   udp wait    nobody  /usr/sbin/tcpd  /usr/sbin/in.tftpd /tftpboot

我并没有使用这个命令,而是重新加载inetd进程:

 

sudo /etc/init.d/inetd reload

 

 

 

重启inetd服务的几种方法:

 

openbsd-inetd是个可执行文件。

 

root@ubuntu:/etc/init.d# openbsd-inetd restart

openbsd-inetd: command not found

root@ubuntu:/etc/init.d# ./openbsd-inetd restart

 * Restarting internet superserver inetd                                 [ OK ] 

root@ubuntu:/etc/init.d# 

 

这样是可行的:

root@ubuntu:~/tftpboot# sudo /etc/init.d/openbsd-inetd restart

 * Restarting internet superserver inetd                                 [ OK ] 

root@ubuntu:~/tftpboot# 

 

=========================

这个命令,不知道做什么的。

root@ubuntu:/etc/init.d# in.tftpd -l /tftpboot

in.tftpd自己也是个命令.

 

 

一些操作细节中的知识点和遇到的问题的解决办

 



安装inetd的目的是为了控制tftp的运行。


只这样是不行的,因为tftp是要inetd来控制的,而ubuntu或debian类的系统,默认是没有安装inetd的,安装一下:

root@ubuntu:/etc/init.d# apt-get install netkit-inetd

Reading package lists... Done

Building dependency tree       

Reading state information... Done

Package netkit-inetd is a virtual package provided by:

  inetutils-inetd 2:1.6-3

  openbsd-inetd 0.20080125-4ubuntu2

You should explicitly select one to install.

E: Package netkit-inetd has no installation candidate

 

这个包,ubuntu是通过自己的包来提供的.

 

(3)=============================================================================

tftp传输文件需要给文件设置权限,这个报错的一个原因是位置错了,参看(5)

 

出现了Error code 2: Access violation的错误.



(4)==========================

通过natstat和grep命令查看tftpd是否运行

 

root@ubuntu:~/tftpboot# netstat -a | grep tftp

udp        0      0 *:tftp                  *:*

 

看上去tftp是在运行的.

 

 

(5)==============================

 

原因是,我/tftpboot文件,应是在/下,我把它放在了/root下。

改为/tftpboot就行了。

================================================

 

(6)文件存取访问要注意的问题


【1】tftp的使用,,在任何一个目录下,使用tftp的客户端,访问某个ip的机子上的tftp服务器,访问这个ip的tftpboot目录下的文件。


因此,我在/home/zhangbin下,获取/tftpboot下的hello.txt文件。使用的是get命令。获取成功。

 

下载文件成功.

root@ubuntu:/home/zhangbin# vi /tftp/hello.txt

root@ubuntu:/home/zhangbin# vi /tftpboot/hello.txt

root@ubuntu:/home/zhangbin# tftp 127.0.0.1

tftp> get hello.txt

Received 34 bytes in 0.0 seconds

tftp> q 退出  tftpd的命令

 

===============================

【2】上传文件失败,文件权限报错的解决办法(解决办法见 下面的 3))

 

想吧new.txt上传到tftp服务器中。

Error code 2: Access violation 错误。

 

=========================
3)参考了文章之后,明白了一点,就是tftp服务器,默认规则是可以下载,但是上传文件的话,
必须在tftpboot中,有一个相同名字的文件,而且具备相应的可读写(覆盖)的权限.这样才能上传文件.
实验一下:
在tftpboot中,创建new.txt,忘记改写权限.
上传失败.
root@ubuntu:/home/zhangbin# vi /tftpboot/new.txt
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put new.txt
Error code 2: Access violation
tftp> q
root@ubuntu:/home/zhangbin# ls /tftpboot/
hello.txt  new.txt  test  test.txt
改写了权限之后,上传就成功了.
root@ubuntu:/home/zhangbin# chmod 777 /tftpboot/new.txt
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put new.txt
Sent 30319 bytes in 0.0 seconds
tftp> 
========================================
4)文件必须是644的权限。
root下,新建一个文件,001.txt,打算上传到tftp中.
root@ubuntu:/home/zhangbin# vi 001.txt
创建之后的权限是644,就是root可以读写,group和others只能读.
root@ubuntu:/home/zhangbin# ls -l
total 552872
-rw-r--r--  1 root     root             8 2011-02-27 20:12 001.txt
再在/tftpboot中,创建一个同名的
root@ubuntu:/home/zhangbin# vi /tftpboot/001.txt
权限默认是644,感觉,用root执行上传,可以覆盖.
root@ubuntu:/home/zhangbin# ls -l  /tftpboot/
total 36
-rw-r--r-- 1 root root     0 2011-02-27 20:14 001.txt
试试
居然不行
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put 001.txt
Error code 2: Access violation
tftp> 
tftpboot下的文件,改成666
root@ubuntu:/home/zhangbin# chmod 666 /tftpboot/001.txt
root@ubuntu:/home/zhangbin# ls -l  /tftpboot/
total 36
-rw-rw-rw- 1 root root     0 2011-02-27 20:14 001.txt
可以了
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put 001.txt
Sent 10 bytes in 0.0 seconds
tftp> 

这个实验说明了,root下,在tftpboot下,具有666的文件,才能被覆盖掉.

///////////////////////////////////////

 

参考文章和用到的知识如下

====================下面是我参考的一些文章=============================================
这个问题,参考了这位大牛的文章
http://blog.csdn.net/wfing/archive/2010/07/12/5729091.aspx

原文链接:http://os.51cto.com/art/201001/176508.htm

在向大家详细介绍tftp之前,首先让大家了解下Ubuntu tftp,然后全面介绍Ubuntu tftp,希望对大家有用。Ubuntu 团队对它的使用者公开的承诺:Ubuntu 永远免费 , 并且对于 "企业版本" 没有任何额外的费用, 在同样的自由团队上,将最好的工作成果带给每一个人。

配置Ubuntu tftp服务的步骤:

1、安装相关软件包:Ubuntu tftp(服务端),tftp(客户端),xinetd
sudo apt-get install tftpd tftp xinetd

2、建立配置文件
在/etc/xinetd.d/下建立一个配置文件tftp
sudo vi tftp
在文件中输入以下内容:
service tftp
{socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4}
保存退出

3、建立Ubuntu tftp服务文件目录(上传文件与下载文件的位置),并且更改其权限
sudo mkdir /tftpboot
sudo chmod 777 /tftpboot -R

4、重新启动服务
sudo /etc/init.d/xinetd restart
至此Ubuntu tftp服务已经安装完成了,下面可以对其进行一下测试。(假设在当前目录下有一个测试文件test.txt)
$tftp 127.0.0.1                      
tftp> put test.txt
Sent 1018 bytes in 0.0 seconds
tftp> get test.txt
Received 1018 bytes in 0.1 seconds
tftp> quit

通过get命令,可以把当前目录下的test.txt文件,通过Ubuntu tftp上传到它的服务文件目录。这时,在/tftpboot下面会出现test.txt文件。通过put命令,可以从/tftpboot下,下载 test.txt文件。这样就验证了Ubuntu tftp服务配置的正确性。当文件上传与下载结束后,可以通过quit命令退出。严格按照以上步骤配置Ubuntu tftp服务,一般都可以成功。如果出现无法get或者put的时候,可以查看一下防火墙是否关闭。

如果从tftp服务器下载失败,

要确保服务器的根目录有可执行的权限。

$ chmod -R 777 tftp


使用中发现能正常下载文件,

$ tftp 192.168.1.222
tftp> get zImage
Received 1692890 bytes in 0.2 seconds

可是上传文件不成功,

提示错误:

tftp> put dic.txt
Error code 2: Access violation

求助于google, 得下面一段说明,问题解决。

The tftp man page says:

Because there is no user-login or validation within the TFTP
protocol, the remote site will probably have some sort of
file-access restrictions in place. The exact methods are
specific to each site and therefore dif ficult to document here.

So apparently the site you're trying to get the file from has some
kind of access restrictions in place. Take a look at the tftpd man
page on the remote host. The linux tftpd manual says, in part, "Due to
the lack of authentication information, tftpd will allow only publicly
readable files to be accessed. Files may be written only if they
already exist and are publicly writable."

上面主要意思就是: tftp服务器缺少必要的身份验证,

所以默认只允许下载文件,要上传文件,必须是服务器中已存在同名的文件,

且该文件权限允许被覆盖。


所以首先在服务中创建一个与要上传的文件同名的文件,并更改权限。

$ touch dic.txt

$ chmod 777 dic.txt

重新上传,成功。
tftp> put dic.txt
Sent 13770 bytes in 0.0 seconds

在网上看到有人配/etc/default/tftp,/etc/inetd.conf这些文件,实际上没这么复杂,用tftp和tftpd,加上xinetd监控,只需要配/etc/xinetd./tftp即可。

 

===========

也有牛人说

http://yuanfarn.blogspot.com/search/label/Linux

 

 

在 Ubuntu 上安裝 tftpd 伺服器是一件非常簡單的事,首先執行以下這個指令安裝需要的套件:

sudo apt-get install tftp tftpd openbsd-inetd

然後再執行以下的指令啟動 openbsd-inetd:

sudo /etc/init.d/openbsd-inetd start

基本上,這樣就可以使用 tftpd 了。不過,由於 Ubuntu 的 openbsd-inetd 預設將 tftpd 的路徑指定為/srv/tftp,我覺得有點不大方便,因此通常習慣再去修改 /etc/inetd.conf,將 /srv/tftp 修改成/tmp/tftproot,這樣一來,我也不用再去理會 /srv 這個目錄的權限,只要將要藉由 tftp 傳送的檔案直接複製到 /tmp/tftproot 目錄就行了,更方便許多呢!

 

===============================================================

参考了http://bbs.chinaunix.net/thread-655364-1-1.html

 

参考了这篇文章

tftp程序,对ubuntu用户来讲,配置这个不是很友好。

安装程序
代码:
sudo apt-get install tftp tftpd

前者是客户端,后者是服务程序。

只这样是不行的,因为tftp是要inetd来控制的,而ubuntu或debian类的系统,默认是没有安装inetd的,安装一下:
代码:
sudo apt-get install netkit-inetd



在/目录下建一个tftpboot, 把属性改成777。
代码:
cd /
sudo mkdir tftpboot
sudo chmod 777 tftpboot



修改/etc/inetd.conf
代码:
tftp    dgram   udp     wait    nobody  /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot


重新加载inetd进程
代码:
sudo /etc/init.d/inetd reload


测试一下,在/tftpboot文件夹下新建立一个文件
代码:
touch aaa


进入另外一个文件夹
代码:
tftp 10.0.0.1
tftp> get aaa

=====================================================

http://hi.baidu.com/%B0%D9%B8%F6%C8%AB%CA%E9/blog/item/0cb018ffec018e49d6887deb.html

 

新人学习Linux,近日在Fedora下学习使用Tftp,服务器、客户端配置完毕后,使用tftp上传、下载文件,

提示访问非法: Error code 2: Access violation 。

网上查了一些资料,大概明白问题在于文件的访问权限。几经周折,问题解决,将此过程细录如下,

以作成长之鉴证,也为后来学习者提供解决方法。以下为详细过程:

Tftp按照成熟解决方案配置,不再赘述;

问题:在tftpboot下建立文件1.txt, tftp 127.0.0.1访问本地tftp服务器,出现

Error code 2: Access violation。

解决:进入/tftpboot文件夹,使用命令 chmod 666 1.txt,将1.txt权限改为root、group、others均可读写。

至此,问题解决。

 

chmod命令

体会:chmod命令(在root用户下,共root、group、others)

指令名称 : chmod 
使用权限 : 所有使用者 
使用方式 : chmod [-cfvR] [--help] [--version] mode file...

chmod XYZ file

X:代表root对file的访问权限。X为3位2进制数据分别代表对文件的read、write、executed 权限。

0代表禁止,1代表允许,如7即允许root对file有rwx权限,6代表有rx权限,4代表r权限,以此类推;

Y:代表group对file的访问权限。数据定义参考X的数据定义;

Z:代表others对file的访问权限。数据定义参考X的数据定义;


  Ubuntu 9.10在配置tftp时,首先要安装4个软件包,安装到netkit-inetd,系统提示错误如下:
      
       正在读取软件包列表... 完成
       正在分析软件包的依赖关系树      
       正在读取状态信息... 完成      
       软件包 netkit-inetd 是一个由下面的软件包提供的虚拟软件包:
       inetutils-inetd 2:1.6-2
       openbsd-inetd 0.20080125-2ubuntu1
       请您明确地选择一个来进行安装。
       E: 软件包 netkit-inetd 还没有可供安装的候选者 

 
       原因:在ubuntu7.04以前版本下可以安装netkit-inetd软件包,但是在ubuntu 9.10上安装时,
会出现错误:
       所以我在ubuntu8.10中直接安装openbsd-inetd或者netkit-inetd软件包,我试了一下,只能
安装一个,若安装另一个,则前一个会自动删除。

原创粉丝点击