构建tftp服务器

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]

命令:sudo service iptables restart

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

命令: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 (policyACCEPT)

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

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

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

iptables:未运行防火墙。

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

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

5、tftp命令测试

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

命令:tftp 192.168.1.1(服务器IP) GET test.txt

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

命令:tftp 192.168.1.1(服务器IP) PUT test.txt(D:\test.txt)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值