centos6.3 安装tftp

来源:互联网 发布:sql 2005 初次登陆 编辑:程序博客网 时间:2024/05/22 09:01

1,安装tftp服务器

[root@centos6 centos6_iso]# mount -o loop CentOS-6.0-x86_64-bin-DVD1.iso mnt1/

[root@centos6 centos6_iso]# find -iname *tftp*.rpm

./mnt1/Packages/tftp-0.49-5.1.el6.x86_64.rpm

./mnt1/Packages/tftp-server-0.49-5.1.el6.x86_64.rpm

[root@centos6 centos6_iso]# rpm -ivh mnt1/Packages/tftp-server-0.49-5.1.el6.x86_64.rpm

Preparing...                ########################################### [100%]

        package tftp-server-0.49-5.1.el6.x86_64 is already installed


或者我们可以直接使用yum来自动下载并安装tftp服务器

[guowenxue@centos6 ~]$ sudo yum install -y tftp-server

Loaded plugins: fastestmirror, refresh-packagekit

base                                                                                                         | 3.7 kB     00:00     

base/primary_db                                                                                              | 4.5 MB     00:41     

extras                                                                                                       | 3.5 kB     00:00     

extras/primary_db                                                                                            | 6.3 kB     00:00     

updates                                                                                                      | 3.5 kB     00:00     

updates/primary_db                                                                                           | 3.0 MB     00:29     

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package tftp-server.x86_64 0:0.49-7.el6 set to be updated

--> Finished Dependency Resolution


Dependencies Resolved


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

Package                           Arch                         Version                            Repository                  Size

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

Installing:

tftp-server                       x86_64                       0.49-7.el6                         base                        39 k


Transaction Summary

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

Install       1 Package(s)

Upgrade       0 Package(s)


Total download size: 39 k

Installed size: 57 k

Downloading Packages:

tftp-server-0.49-7.el6.x86_64.rpm                                                                            |  39 kB     00:00     

warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY

base/gpgkey                                                                                                  | 3.3 kB     00:00 ...

Importing GPG key 0xC105B9DE "CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Warning: RPMDB altered outside of yum.

  Installing     : tftp-server-0.49-7.el6.x86_64                                                                                1/1


Installed:

  tftp-server.x86_64 0:0.49-7.el6                                                                                                   


Complete!

[guowenxue@coherentplus_dev ~]$

2, 配置并启动tftp服务

[root@centos6 ~]# vim /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

{

       disable = no

        socket_type             = dgram

        protocol                = udp

        wait                    = yes

        user                    = root

        server                  = /usr/sbin/in.tftpd

        server_args             = -s /tftp -c

        per_source              = 11

        cps                     = 100 2

        flags                   = IPv4

}

这里-s指 tftp服务器目录, -c指能够创建文件


[root@centos6 ~]# ls /tftp/

u-boot-2010.09-sam9260.bin  u-boot-2011.09-sam9260.bin

[root@centos6 ~]# service xinetd restart

Stopping xinetd:                                           [  OK  ]

Starting xinetd:                                           [  OK  ]

[root@centos6 ~]# netstat -nlp | grep 69

tcp        0      0 0.0.0.0:51469               0.0.0.0:*                   LISTEN      -                  

tcp        0      0 :::56942                    :::*                        LISTEN      -                  

udp        0      0 0.0.0.0:69                  0.0.0.0:*                               30426/xinetd        

udp        0      0 0.0.0.0:69                  0.0.0.0:*                               21902/in.tftpd      

udp        0      0 0.0.0.0:56669               0.0.0.0:*                               -                  

unix  2      [ ACC ]     STREAM     LISTENING     13692  2110/bonobo-activat /tmp/orbit-root/linc-83e-0-7e4618a7345fe

unix  2      [ ACC ]     STREAM     LISTENING     15201  2184/gnome-power-ma /tmp/orbit-root/linc-888-0-369f320967e51

unix  2      [ ACC ]     STREAM     LISTENING     15282  2162/pulseaudio     /root/.pulse/35fed7a869beed424297cf3100000017-runtime/native

unix  2      [ ACC ]     STREAM     LISTENING     9369   1381/avahi-daemon:  /var/run/avahi-daemon/socket


3,安装busybox里的tftp客户端命令

[root@centos6 apps_src]# wgethttp://www.busybox.net/downloads/busybox-1.19.3.tar.bz2

[root@centos6 apps_src]# tar -xjf busybox-1.19.3.tar.bz2

[root@centos6 apps_src]# cd busybox-1.19.3

[root@centos6 busybox-1.19.3]# export TERM=vt100

[root@centos6 busybox-1.19.3]# make menuconfig

不要做任何修改直接写保存退出即可。

[root@centos6 busybox-1.19.3]# make

[root@centos6 busybox-1.19.3]# file busybox

busybox: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), stripped

[root@centos6 busybox-1.19.3]# cp busybox /usr/local/bin/

[root@centos6 busybox-1.19.3]# cd

[root@centos6 ~]# cd /usr/local/bin/

[root@centos6 bin]# ln -s busybox tftp


4, 使用busybox里的tftp命令来测试

[root@centos6 ~]# tftp -gr u-boot-2010.09-sam9260.bin 192.168.1.78

u-boot-2010.09-sam92 100% |***********************************************************************************|   136k  0:00:00 ETA

[root@centos6 ~]# ls u-boot-2010.09-sam9260.bin

u-boot-2010.09-sam9260.bin


5.  SELinux策略修改

如果不能下载的话,看不是CentOS6的SELinux开启了,这时可以使用命令将他关掉:

[root@centos6 guowenxue]# setenforce 0

这里的/usr/sbin/setenforce 1设置SELinux为enforcing模式;

这里的/usr/sbin/setenforce 0设置SELinux为permissive模式;


如果要彻底禁用SELinux,可以讲SELINUX设为disalbed

[guowenxue@centos6 ~]$ sudo vim /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#     enforcing - SELinux security policy is enforced.

#     permissive - SELinux prints warnings instead of enforcing.

#     disabled - No SELinux policy is loaded.

#SELINUX=enforcing

SELINUX=disabled

# SELINUXTYPE= can take one of these two values:

#     targeted - Targeted processes are protected,

#     mls - Multi Level Security protection.

SELINUXTYPE=targeted

重启系统后,我查看SELinux的状态应该为:



[guowenxue@centos6 ~]$ getenforce
Disabled
[guowenxue@centos6 ~]$ sestatus
SELinux status:                 disabled
[guowenxue@centos6 ~]$

6. 防火墙策略修改

另外,如果开启了防火墙也可能会出现问题,这时我们可以在防火墙的规则中使能tftp,下面的只需要使能69号端口就行了(因为tftp使用的是这个端口):



[guowenxue@centos6 ~]$ sudo /sbin/iptables -I INPUT -p tcp --dport 69 -j ACCEPT  
[guowenxue@centos6 ~]$ sudo /sbin/iptables -I INPUT -p udp --dport 69 -j ACCEPT
[guowenxue@centos6 ~]$ sudo /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[guowenxue@centos6 ~]$ sudo /sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT
[guowenxue@centos6 ~]$ sudo /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
[guowenxue@centos6 ~]$ sudo /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[guowenxue@centos6 ~]$ sudo service iptables restart
iptables:清除防火墙规则:                                 [确定]
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]
[guowenxue@centos6 ~]$ sudo service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:21
3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80
4    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:69
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:69
6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:69
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:21

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         


当然,我们也可以使用命令,关闭Linux的防火墙:
[guowenxue@centos6 ~]$ sudo service iptables stop
iptables:清除防火墙规则:                                 [确定]
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:正在卸载模块:                                   [确定]
[guowenxue@centos6 ~]$ sudo service iptables status
iptables:未运行防火墙。
[guowenxue@centos6 ~]$

如果我们希望系统在启动的时候就不要启动防火墙,那么我们应该使用ntsysv命令(注意这条命令必须要使用root权限来执行)来关闭防火墙服务,同时我们还可以设置让系统启动的时候就开启tftp服务:

[ ] ip6tables

[ ] iptables


tftp


xinetd

[guowenxue@centos6 ~]$ getenforce
Disabled
[guowenxue@centos6 ~]$ sestatus