linux搭建TFTP server及客户端
(2014-04-25 11:46:30)
分类: w~linux |
/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 -c #指定tftp服务器的目录,-c为指定为可以创建文件
per_source
= 11
cps
= 100 2
flags
= IPv4
}
创建tftp根目录,关闭防火墙,启动tftp-server #mkdir -m 777 /tftpboot
#/etc/init.d/iptables stop//关闭防火墙 #service xinetd restart //重启 xinetd 服务重启xinetd服务,因为TFTP服务受控与xinetd, xinetd是管服务的服务,它是不开端口的。
添加防火墙规则放通TFTP
vi /etc/sysconfig/iptables
-A INPUT -p udp -m state --state NEW -m udp --dport 69 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
重启iptables服务
service iptables restart
测试:
tftp -g -r 文件名 IP 端口
从服务器获取文件
2个Cenos之间通行提示:Error code 0: Permission denied
win XP的cmd里的tftp提示:Error on server : Permission denied
[root@localhost ~]# setenforce 0
tftp -p -r 文件名 IP 端口
上传文件到服务器
错误
tftp:server error:(0) permission denied
修TFTP目录所属组权限
chown -R nobody /tftpboot
或者错误
tftp:tftp:server error:(2)File must have globle write permissions
chmod -R 777 /tftpboot
参考:
http://www.centoscn.com/image-text/config/2013/1105/2062.html
http://zhidao.baidu.com/question/538407639
http://wiki.centos.org/HowTos/Network/IPTables
分类:
Linux
-
使用vmware workstation
OS版本:RHEL7.0
DHCP server 使用hostonly网卡
检查tftp包是否存在
[root@LiuZhen ~]# rpm -qa tftp
yum安装tftp
[root@LiuZhen ~]# yum install tftp
安装超级守护进程
[root@LiuZhen xinetd.d]# rpm -qa xinetd
[root@LiuZhen xinetd.d]#
[root@LiuZhen xinetd.d]# yum install xinetd
[root@LiuZhen xinetd.d]# rpm -qa tftp-server
[root@LiuZhen xinetd.d]# yum install tftp-server
[root@LiuZhen xinetd.d]#
查看配置文件
[root@LiuZhen xinetd.d]# cat /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 /var/lib/tftpboot
disable = yes
per_source = 11
cps = 100 2
flags = IPv4
}
修改yes 为no
[root@LiuZhen xinetd.d]# service xinetd restart
Redirecting to /bin/systemctl restart xinetd.service
[root@LiuZhen xinetd.d]#
[root@LiuZhen xinetd.d]#
[root@LiuZhen xinetd.d]# service xinetd status
Redirecting to /bin/systemctl status xinetd.service
xinetd.service – Xinetd A Powerful Replacement For Inetd
Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled)
Active: active (running) since Tue 2014-08-05 13:57:58 CST; 26s ago
Process: 7149 ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=0/SUCCESS)
Main PID: 7150 (xinetd)
CGroup: /system.slice/xinetd.service
?..7150 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: removing discard
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: removing discard
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: removing echo
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: removing echo
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: removing tcpmux
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: removing time
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: removing time
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: xinetd Version 2.3.15 started with libwrap loadavg labeled-networking o…d in.
Aug 05 13:57:58 LiuZhen.com xinetd[7150]: Started working: 1 available service
Aug 05 13:57:58 LiuZhen.com systemd[1]: Started Xinetd A Powerful Replacement For Inetd.
Hint: Some lines were ellipsized, use -l to show in full.
设置防火墙
配置完成
测试
配置文件中 如图所示是存放文件的目录
在另一台linux虚拟机上
安装tftp client
[root@LZ yum.repos.d]# yum install tftp
执行tftp到 192.168.220.222
提示timeout,防火墙没有设置,先关掉防火墙
再次测试,成功
查看帮助
分类:
Linux
FTP
和
TFTP
是我们经常使用的文件传输协议。在
Linux
中,
sftp
协议由于其安全性的优点,被作为默认的链接协议。但是,一些场合下,我们依然需要使用
ftp
和
tftp
协议进行文件传输。本篇主要介绍配置方法,供有需要的朋友待查。
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
是一种简单的文件传输解决方案。
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
的配置手段,留待需要朋友待查。