tftp,ftp服務搭建

linux搭建TFTP server及客戶端

 (2014-04-25 11:46:30)
  分類: w~linux
用yum -y install tftp
安裝客戶端命令
用yum -y install tftp-server
安裝TFPT服務器
配置TFPT服務器配置文件
/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 配置 TFTP服務 2014-08-05 15:06:04

分類: 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

clip_image001

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

 

設置防火牆

clip_image002

配置完成

 

測試

配置文件中 如圖所示是存放文件的目錄

clip_image003

 

clip_image004

 

在另一臺linux虛擬機上

安裝tftp client

[root@LZ yum.repos.d]# yum install tftp

執行tftp到 192.168.220.222

clip_image005

提示timeout,防火牆沒有設置,先關掉防火牆

clip_image006

再次測試,成功

clip_image007

查看幫助

clip_image008







 Linux下FTP和TFTP服務配置 2014-01-28 13:17:03

分類: Linux

 

FTPTFTP是我們經常使用的文件傳輸協議。在Linux中,sftp協議由於其安全性的優點,被作爲默認的鏈接協議。但是,一些場合下,我們依然需要使用ftptftp協議進行文件傳輸。本篇主要介紹配置方法,供有需要的朋友待查。

 

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

 

2TFTP服務器安裝配置

 

TFTP是一種比較特殊的文件傳輸協議。相對於FTP和目前經常使用的SFTPTFTP是基於TCP/IP協議簇,用於進行簡單文件傳輸,提供簡單、低開銷的傳輸服務。TFTP的端口設置爲69

相對於常見的FTPTFTP有兩個比較好的優勢:

ü  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是一種簡單的文件傳輸解決方案。

 

3FTP配置

 

目前成熟系統設計中,都將FTP協議和傳輸定性爲非安全傳輸協議。它和telnet登錄方式,逐漸爲SFTPSSH協議所取代。在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、結論

 

LinuxAIX中,很多的配置內容都是命令行+文本配置的方法來實現的。本篇介紹了Linux環境下tftpftp的配置手段,留待需要朋友待查。


發佈了7 篇原創文章 · 獲贊 14 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章