构建tftp服务器

来源:互联网 发布:vivo网络授权书怎么 编辑:程序博客网 时间:2024/05/01 17:51

1、安装 tftp 服务器

1)使用 rpm 命令检查一下,在我们的 Linux 服务器上是否安装了 tftp 服务器软件包:

命令:rpm -qa | grep tftp

2)如果没有安装,我们可以直接使用 yum 来自动下载并安装 tftp 服务器

命令:yum -y install tftp-server

3若无网络,把安装光盘挂载起来后,从安装光盘中找到相应的RPM 包安装

命令:mounto o o -oloop CentOS-6.0-x86_64-bin-DVD1.isomnt1

命令:find-iname*tftp*.rpm

命令:rpm -ivhmnt1/Packages/tftp-server-0.49-5.1.el6.x86_64.rpm

2、配置并启动 tftp 服务

1)在/etc/xinetd.d/目录下配置tftp文件

命令:vim /etc/xinetd.d/tftp

# default: off
# description: Thetftp server servesfiles using thetrivial file transfer protocol.
#Thetftp protocol is often used to boot diskless 
#workstations, download configuration files to network-aware printers,\
#and to start theinstallation processfor someoperating systems.
servicetftp
{
disable = no
socket_type = dgram

protocol= udp

wait= yes

user= root

server= /usr/sbin/in.tftpd
server_args= -s/tftp -c#这里s s s -s 指 tftp服务器的根目录,c c c -c指能创建文件
per_source= 11
cps= 100 2

flags= IPv4
}

2)开启xinetd.d服务

命令:echo"HelloWorld" >>/tftp/test.txt
命令: ls/tftp/
命令:service
 xinetd restart
Stopping xinetd:[OK]
Starting xinetd:[OK]
命令:netstat
 -nlp | grep 69

3、SELinux 策略修改

1)如果系统开启 SELinux 的话,tftp 客户端在下载的时候可能会被阻止。如果是这样,我们可以使用下面命令将他临时关掉:
命令:setenforce 0 #这里的/usr/sbin/setenforce1 设置 SELinux 为 enforcing 模式;这里的/usr/sbin/setenforce0 设置 SELinux 为 permissive 模式;
2)如果要彻底禁用 SELinux,可以修改配置文件将 SELINUX 设为 disalbed
命令:vim /etc/sysconfig/selinux
# This file controls the stateof SELinux on the system.
# SELINUX= can takeone of these threevalues:
# 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 takeone of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
3)重启系统后,我查看 SELinux 的状态应该为:
命令: getenforce
Disabled
命令: sestatus
SELinux status:disabled

4.、防火墙策略修改
如果 Linux 开启了防火墙也可能会阻止 tftp 客户端的下载,这时我们可以在防火墙的规则中使能 tftp,下面的只需要使能 69 号端口就行了(因为 tftp 使用的是这个端口):

命令:sudo   /sbin/iptables -I INPUT -p  tcp --dport  69   -j   ACCEPT

命令:sudo   /sbin/iptables -I INPUT -p  udp --dport  69   -j   ACCEPT

命令:sudo   /sbin/iptables -I INPUT -p  tcp --dport  80   -j   ACCEPT

命令:sudo   /sbin/iptables -I INPUT -p  tcp --dport  21   -j   ACCEPT

命令:sudo   /sbin/iptables -I INPUT -p  tcp --dport  22   -j   ACCEPT

命令: sudo/etc/rc.d/init.d/iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables:[OK]

命令:sudoservice iptables restart

iptables:清除防火墙规则:[确定]
iptables:将链设置为政策 ACCEPT:filter[确定]
iptables:正在卸载模块:[确定]
iptables:应用防火墙规则:[确定]

命令:sudoservice iptables status

表格:filter
Chain INPUT (policy ACCEPT)
num targetprot   opt source destination

1ACCEPT tcp-- 0.0.0.0/00.0.0.0/0 tcp dpt:22
2 ACCEPTtcp -- 0.0.0.0/0 0.0.0.0/0tcp dpt:21

3ACCEPT tcp-- 0.0.0.0/00.0.0.0/0 tcp dpt:80

4ACCEPT udp-- 0.0.0.0/00.0.0.0/0 udp dpt:69

5ACCEPT tcp-- 0.0.0.0/00.0.0.0/0 tcp dpt:69

6ACCEPT tcp-- 0.0.0.0/00.0.0.0/0 tcp dpt:69

7ACCEPT tcp-- 0.0.0.0/00.0.0.0/0 tcp dpt:21

ChainFORWARD (policyACCEPT)

numtarget prot opt sourcedestination
Chain OUTPUT(policy ACCEPT)
num targetprot opt source destination

当然,我们也可以使用命令,关闭 Linux 的防火墙:

命令: sudoservice iptablesstop
iptables:清除防火墙规则:[确定]
iptables:将链设置为政策 ACCEPT:filter[确定]
iptables:正在卸载模块:[确定]
命令:sudo service iptablesstatus

iptables:未运行防火墙。

如果我们希望系统在启动的时候就不要启动防火墙,那么我们应该使用 ntsysv 命令来关闭防火墙服务,同时我们还可以设置让系统启动的时候就开启 tftp 服务

命令:sudo ntsysv
[ ] ip6tables
[ ] iptables
[*] tftp
[*] xinetd

5、tftp命令测试

1)在windows上,从服务器下载刚才新建的文件/tftp/test.txt,下载的文件在命令行所在目录

命令:tftp192.168.1.1(服务器IP) GETtest.txt

2)在windows上,上传到tftp服务器的/tftp目录,上传的文件路径可为相对路径或绝对路径

命令:tftp192.168.1.1(服务器IP) PUTtest.txt(D:\test.txt)



原创粉丝点击