ubuntu tftp服务器配置

第一步:安装tftp tftpd 软件包

说明:这里需要网络配置,

以root身份进入/etc/network/interface 编辑ip,netmask,broadcast等,并保存。

以root身份进入/etc/resolv.conf编辑search:202.102.224.68,namesearch 202.102.227.68;

无root权限,可以使用超级权限用户:命令前加sudo.

网络配置完毕可以重启网络:

方法一:/etc/init.d/networking restart

方法二:(sudo) ifdown eth0

(sudo) ifup eth0

到此网络配置完毕,可以ping一下服务器,如果出现destion host unreachable,查看自己的ip网段是否符合要求。

具体的可以查看ubuntu网络配置方法

成功安装tftp服务器还没找到无网络安装方法,抱歉。

安装tftp:

新ubuntu系统需要更新一下自己的数据源,sudo apt-get update

若出现:无法解析或打开软件包的列表或是状态文件

解决方法:sudo rm /var/lib/apt/lists/* -vf //删除存在的更新源
sudo apt-get update //重新生成

到此系统的数据源更新完毕。

使用apt-get安装tftp

root@ubuntu:/home/zhangbin# apt-get installtftp tftpd xinetd 前者是客户端,后者是服务程序。

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following extra packages will be installed:

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

tftd 服务程序

tftp 客户端程序

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

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

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

OpenBSD 互联网超级服务器

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

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

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

第二步: 配置

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

在/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 = 1002
flags = IPv4}
保存退出

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

第三步 : 新建/tftpboot文件夹

cd / ; // 跳到root的根目录下

mkdir tftpboot; // 创建tftpboot目录

touch test.txt // 创建test.txt 文件

vi test.txt // 编辑test.txt 文件,随意输入一些字母,一会传输时有字节显示,

//若test.txt中时空文档,在传输时时不显示传输字节 数的

文件夹的权限如下:

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 ../


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

(1)===================================

关于tftpd

查询了下帮助手册:

TFTPD(8) BSD System Manager's Manual TFTPD(8)

NAME

tftpd ― DARPA Trivial File Transfer Protocol server

tftp 普通文件传送协议(Trivial File Transfer Protocol)


SYNOPSIS

tftpd [-n] [-s] [directory ...]

DESCRIPTION

Tftpd is a server which supports the DARPA Trivial File Transfer Proto�\ col. The TFTP server operates at the port indicated in the ‘tftp’ ser�\ vice description; see services(5). The server is normally started by

inetd(8).

The use of tftp(1) does not require an account or password on the remote system. 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. Note that this extends the concept of “public” to include all users on all hosts that can be reached through the network; this may not be appropriate on all systems,and its implications should be considered before enabling tftp service. The server should have the user ID with the lowest possible privilege.

Access to files may be controlled by invoking tftpd with a list of direc�\ tories by including pathnames as server program arguments in /etc/inetd.conf.In this case access is restricted to files whose names are prefixed by the one of the given directories. If no directories are supplied the default is /tftpboot. To give out access to the whole filesystem,should this be desired for some reason,supply / as an argu�\ ment.

Unfortunately,on multi-homed systems,it is impossible for tftpd to determine the address on which a packet was received. As a result,tftpd uses two different mechanisms to guess the best source address to use for replies. If the socket that inetd(8) passed to tftpd is bound to a par�\ ticular address,tftpd uses that address for replies. Otherwise,tftpd uses ``UDP connect''to let the kernel choose the reply address based on the destination of the replies and the routing tables. This means that

most setups will work transparently,while in cases where the reply address must be fixed,the virtual hosting feature of inetd(8) can be used to ensure that repliesGoout from the correct address. These con�\ siderations are important,because most tftp clients will reject reply packets that appear to come from an unexpected address.

The options are:

-n Suppresses negative acknowledgement of requests for nonexistent relative filenames.

-s All absolute filenames are treated as if they were preceded by the first directory argument,or /tftpboot if there is none.

SEE ALSO

tftp(1),inetd(8)

HISTORY

The tftpd command appeared in 4.2BSD.

LinuxNetKit (0.17) July 29,2000 Linux NetKit (0.17)

(2)==========================================

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


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

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

Package netkit-inetd isa virtual packageprovided 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的错误.

root@ubuntu:~# cd t*

root@ubuntu:~/tftpboot# ls

root@ubuntu:~/tftpboot# touch test

test

root@ubuntu:~/tftpboot# tftp 127.0.0.1

tftp> get test

Error code 2: Access violation

tftp>

tftpboot是给了 777的权限的.

tftpboot下的test文件,也给了666的权限.

(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的命令

root@ubuntu:/home/zhangbin# ls

7.wma ear.mpg hello.txt new.txt tftp.txt

code examples.desktop HetNet.wmv oldboy.flv tutorial01

DawnLightPlayer ffmpegjt.c jgs.mp3 oldboy.mp4 tutorial02

Desktop ffmpeg截图.c main.cc out.txt tutorial03

DLP-SVN frame1.ppm manffplay.txt pan.rmvb tutorial08

Documents frame2.ppm man-kill.txt Pictures Videos

dodge.mpg frame3.ppm man-ps.txt Public wavplay

Downloads frame4.ppm man-xargs.txt rjsq.wav whatsInside.wav

ear frame5.ppm Music Templates x264

root@ubuntu:/home/zhangbin# cat hello.txt

hello

hellp

ehll

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

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

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

Error code 2: Access violation 错误。

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

1)看了下文件权限:

new.txt应该是666的。

-rw-rw-rw- 1 root root 30278 2011-01-30 06:16 new.txt

还是报错:

root@ubuntu:/home/zhangbin# tftp 127.0.0.1

tftp> put new.txt

Error code 2: Access violation

tftp> q

改成666,还是报错

root@ubuntu:/home/zhangbin# chmod 666 new.txt

tftp>

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

重新来

新建立了一个0字节的文件,abc.txt,还是失败.

root@ubuntu:/home/zhangbin# vi abc.txt

root@ubuntu:/home/zhangbin# cat abc.txt

root@ubuntu:/home/zhangbin# tftp 127.0.0.1

tftp> put abc.txt

Error code 2: Access violation

tftp> q

更改权限666,也不行.

root@ubuntu:/home/zhangbin# chmod 666 abc.txt

root@ubuntu:/home/zhangbin# tftp 127.0.0.1

tftp> put abc.txt

Error code 2: Access violation

tftp>

更改权限777,还是不行.

root@ubuntu:/home/zhangbin# chmod 777 abc.txt

root@ubuntu:/home/zhangbin# tftp 127.0.0.1

tftp> put abc.txt

Error code 2: Access violation

tftp> q

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

2)从tftpboot找问题,

目录d 权限755

drwxr-xr-x 2 root root 4096 2011-02-27 19:11 tftpboot

更改d权限777

root@ubuntu:/# chmod 777 tftpboot

上传new.txt,还是不行.

root@ubuntu:/home/zhangbin# tftp 127.0.0.1

tftp> put new.txt

Error code 2: Access violation

tftp>

重启tftpd服务

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

* Restarting internet superserver inetd [ OK ]

不行

root@ubuntu:/home/zhangbin# tftp 127.0.0.1

tftp> put new.txt

Error code 2: Access violation

说明了不是tftpboot权限,也不是要上传的文件的权限的问题

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

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 上安�b tftpd 伺服器是一件非常��蔚氖拢�首先�绦幸韵逻@��指令安�b需要的套件:

sudo apt-get install tftp tftpd openbsd-inetd

然後再�绦幸韵碌闹噶��� openbsd-inetd:

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

基本上,�@�泳涂梢允褂� tftpd 了。不�^,由於 Ubuntu 的 openbsd-inetd �A�O�� tftpd 的路�街付��/srv/tftp,我�X得有�c不大方便,因此通常��T再去修改/etc/inetd.conf,��/srv/tftp修改成/tmp/tftproot,�@�右�恚�我也不用再去理�� /srv �@��目�的�嘞�,只要�⒁�藉由 tftp �魉偷�n案直接�}�u到 /tmp/tftproot 目�就行了,更方便�S多呢!

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

参考了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的数据定义;



转载出处:http://blog.csdn.net/cgzhello1/article/details/7850858

相关文章

文章浏览阅读2.3k次,点赞4次,收藏22次。最近安装了CARLA预...
文章浏览阅读6.3k次,点赞5次,收藏15次。在清华镜像中下载U...
文章浏览阅读5k次。linux环境, python3.7.问题描述: 安装...
文章浏览阅读4.2k次,点赞4次,收藏17次。要安装这个 standa...
文章浏览阅读894次,点赞51次,收藏31次。在安卓使用vscode主...