tftp配置----精简版配置


tftp配置----精简版配置
 
Redhat Linux下tftp服务器配置其实很容易。现以RedHat 7.3为例说明。
1. 如何启动tftp服务?1
执行ntsysv命令,选中tftp服务,再执行service xinetd restart命令。tftp服务就启动了,容易吧。
2. 如何下载文件?
先分析一下tftp的配置文件。
打开/etc/xinetd.d/tftp文件,如下所示:
service tftp
{
    disable = no
    socket_type     = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server          = /usr/sbin/in.tftpd
    server_args     = -s /tftpboot
    per_source      = 11
    cps         = 100 2
}
这就是tftp的配置文件,其中,server_args     = -s /tftpboot是tftp服务器运行时的参数。-s /tftpboot表示服务器默认的目录是 /tftpboot,当你执行put a.txt时,文件会被放到服务器的/tftpboot/a.txt,省去你敲put a /tftpboot/的麻烦。你也可以加其它服务器运行参数到这,具体可以执行man tftpd命令查阅。
要下载文件,执行如下命令:(下载文件的默认路径为/tftpboot)
>tftp <tftp server address or name>
>get <filename>
3. 如何上传文件?
上传文件时,需要先把服务器上的/tftpboot目录和这个目录下的文件变成可读可写权限,如下命令所示:
>cd /
>chmod 777 tftpboot
>cd tftpboot
>chmod 777 *
(这里用777权限有些高,可以用666,不过无所谓)
上传文件用put命令,但是默认情况下,只能上传远程tftp服务器已有的文件,例如,在tftp服务器上有/tftpboot/a.txt这个文件,你可以执行
>put a.txt
将本地的a.txt文件上传上去并覆盖服务器上的原文件。所以这个时候要先在服务器上建一个同名文件,如下命令所示:
>cd /tftpboot
>touch a.txt
>chmod 666 *
 
如果想上传原来目录中没有的文件,需要修改tftp服务器的配置文件并重起服务,如下操作所示:
打开/etc/xinetd.d/tftp文件,在 server_args 增加-c参数,如下所示:
service tftp
{
    disable = no
    socket_type     = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server          = /usr/sbin/in.tftpd
    server_args     = -s /tftpboot -c
    per_source      = 11
    cps         = 100 2
}
存盘退出。
重起tftp服务,如下所示:
>service xinetd restart
可以了。现在就可以上传新文件了。
 
如果是Windows下的tftp服务器,建议用3CDaemon,配置方法不做介绍了。
 
 
 
 
 
再附一篇文章
 
用Linux 架设TFTP Server备份路由器的配置文件
 
作者:李晨光 来源:www.netadmin.com.cn (2005-04-06 14:17:15)
 
 
 
 
 
TFTP (普通文件传输协议或一般文件传输协议) 大家一定记得在2003年8月12日全球爆发冲击波(Worm.Blaster)病毒,这种病毒会监听端口69,模拟出一个TFTP服务器,并启动一个攻击传播线程,不断地随机生成攻击地址,进行入侵。另外tftp被认为是一种不安全的协议而将其关闭,同时也是防火墙打击的对象,这也是有道理的。不过 tftp还是有用武之地的,下面讲的文件传输和备份router配置文件都时实际应用,它也只时一种手段而已。
 
一、用TFTP实现文件传输
 
环境:服务器A :rhas11
 
客户机B: rhas101
 
首先用rpm –qa | grep tftp看一下tftp有没安装,没有的话安 装一下。
 
A:在服务器端设置
 
#vi /etc/xinetd.d/tftp
 
service tftp
 
{
 
disable = no
 
socket_type = dgram
 
protocol = udp
 
wait = yes
 
user = root
 
server = /usr/sbin/in.tftpd
 
server_args = -s /test
 
per_source = 11
 
cps = 100 2
 
flags = IPv4
 
}
 
或用chkconfig tftp on 也可以打开xinetd代理的tftp服
 
#mkdir /test
 
#service xinetd restart 从启xinetd服务,因为TFTP服务受控与xinetd, xinetd是管服务的服务,它是不开端口的。
 
验证一下TFTP是否起来了:
 
[root@rhas11 tftp]# netstat -nlp
 
Active Internet connections (only servers)
 
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
 
tcp 0 0 0.0.0.0:32768 0.0.0.0:* LISTEN 3122/rpc.statd
 
tcp 0 0 127.0.0.1:32781 0.0.0.0:* LISTEN 4035/xinetd
 
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 3103/portmap
 
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3324/httpd
 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3255/sshd
 
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3213/cupsd
 
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3295/sendmail: acce
 
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 3415/0
 
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 3324/httpd
 
udp 0 0 0.0.0.0:32768 0.0.0.0:* 3122/rpc.statd
 
udp 0 0 0.0.0.0:69 0.0.0.0:* 4035/xinetd
 
udp 0 0 0.0.0.0:69 0.0.0.0:* 4012/in.tftpd
 
udp 0 0 0.0.0.0:111 0.0.0.0:* 3103/portmap
 
udp 0 0 0.0.0.0:754 0.0.0.0:* 3122/rpc.statd
 
udp 0 0 0.0.0.0:631 0.0.0.0:* 3213/cupsd
 
A:服务器端 新建一文件file
 
#cd /test
 
[root@rhas11 test]# ls -l
 
总用量 4
 
-rw-r--r-- 1 root root 19 5月 15 18:26 file
 
B客户端:
 
下载:
 
[root@rhas101 tmp]# tftp 172.31.0.11
 
tftp> get 1
 
Received 72 bytes in 0.0 seconds
 
tftp>
 
上传当前目录下文件”aaa”
 
[root@rhas101 client]# ls -l
 
总用量 4
 
-rw-r--r-- 1 root root 15 5月 20 21:49 aaa
 
[root@rhas101 client]# tftp 172.31.0.11
 
tftp> put aaa
 
Error code 1: File not found
 
tftp>
 
奇怪当前目录却是有aaa文件???让我想一下
 
哦,原来服务器/test目录下没有文件aaa,那就touch一个吧
 
[root@rhas11 test]# touch aaa
 
[root@rhas11 test]# ls -l
 
总用量 4
 
-rw-r--r-- 1 root root 0 5月 15 18:46 aaa
 
-rw-r--r-- 1 root root 19 5月 15 18:26 file
 
好了再试一试
 
[root@rhas101 client]# tftp 172.31.0.11
 
tftp> put aaa
 
Error code 1: File not found
 
tftp> put aaa
 
Error code 2: Access denied
 
tftp>
 
细心的读者一定想到这是权限问题
 
再到服务器上设置
 
(===========================================
 
小插曲:#chown -R nobody.nobody /test
 
#vi /etc/xinetd.d/tftp
 
service tftp
 
{
 
disable = no
 
socket_type = dgram
 
protocol = udp
 
wait = yes
 
user = nobody
 
server = /usr/sbin/in.tftpd
 
server_args = -u nobody -s /test
 
per_source = 11
 
cps = 100 2
 
flags = IPv4
 
}
 
chmod 777 -R /test
 
====================================================)
 
#service xinetd restart
 
)
 
[root@rhas11 test]# chmod 007 aaa 其实只要有可写的权限就行了
 
[root@rhas11 test]# ls -l
 
总用量 4
 
-------rwx 1 root root 0 5月 15 18:46 aaa
 
-rw-r--r-- 1 root root 19 5月 15 18:26 file
 
[root@rhas101 client]# tftp 172.31.0.11
 
tftp> put aaa
 
Error code 1: File not found
 
tftp> put aaa
 
Error code 2: Access denied
 
tftp> put aaa
 
Sent 16 bytes in 0.0 seconds
 
tftp>
 
二、 特殊应用:上传和下载路由器(或交换机)配置文件
 
配使用Linux的tftp功能配置cisco route
 
在局域网环境中,如果有Cisco 路由器和Linux服务器。也许你需要利用Linux的
 
TFTP服务去下载Cisco router配置文件 startup-config,在服务器上编辑后再上载
 
到路由器,在实现中有一些特别注意的地方。
 
所用软、硬件:Redhat Linux AS 3.0 ,Cisco 2611 路由器
 
BEIJING#copy run tftp
 
Address or name of remote host []? 172.31.0.11
 
Destination filename [beijing-confg]? beijing-route
 
!!
 
1968 bytes copied in 0.581 secs (3387 bytes/sec)
 
别忘了在tftp server 上创建beijing-route权限为777
 
BEIJING#copy tftp flash
 
Address or name of remote host []? 172.31.0.11
 
Source filename []? beijing-route
 
Destination filename [beijing-route]?
 
Accessing tftp://172.31.0.11/beijing-route...
 
Erase flash: before copying? [confirm]
 
Erasing the flash filesystem will remove all files! Continue? [confirm]
 
Erasing device... eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ...erased
 
Erase of flash: complete
 
Loading beijing-route from 172.31.0.11 (via FastEthernet0/0): !
 
[OK - 1968 bytes]
 
Verifying checksum... OK (0x5248)
 
1968 bytes copied in 0.285 secs (6905 bytes/sec)
 
BEIJING#  
 
 

相关内容

    暂无相关文章