1. 程式人生 > >實驗:搭建TFTP服務

實驗:搭建TFTP服務

搭建 col sys ava pcb transfer virbr0 pro var

註意:FTP 使用tcp協議,走的是tcp21端口,20端口或隨機端口,共兩個,TFTP使用udp協議,TFTP用udp69端口。TFTP是個非獨立服務。支持文件下載、共享,TFTP(Trivial File Transfer Protocol,簡單文件傳輸協議)是TCP/IP協議族中的一個用來在客戶機與服務器之間進行簡單文件傳輸的協議,提供不復雜、開銷不大的文件傳輸服務,端口號為69。

前期準備:網卡必須在橋接模式下才能連接到外網,下載TFTP服務,所以把網卡修改為172.20網段。

1、[root@centos7 ~]# yum install tftp-server
Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile
development | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
(1/2): epel/updateinfo | 956 kB 00:00:00
(2/2): epel/primary_db | 6.6 MB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package tftp-server.x86_64 0:5.2-22.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================
Package Arch Version Repository Size

Installing:
tftp-server x86_64 5.2-22.el7 development 47 k

Transaction Summary

Install 1 Package

Total download size: 47 k
Installed size: 64 k
Is this ok [y/d/N]: y
Downloading packages:
tftp-server-5.2-22.el7.x86_64.rpm | 47 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tftp-server-5.2-22.el7.x86_64 1/1
Verifying : tftp-server-5.2-22.el7.x86_64 1/1

Installed:
tftp-server.x86_64 0:5.2-22.el7

Complete!
[root@centos7 ~]# rpm -ql tftp-server
/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot

2、開啟TFTP服務,查看端口:
[root@centos7 ~]# systemctl start tftp
[root@centos7 ~]# ss -ntul
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 :5353 :
udp UNCONN 0 0
:49063 :
udp UNCONN 0 0 192.168.122.1:53 :
udp UNCONN 0 0 :67 :
udp UNCONN 0 0
%virbr0:67 :
udp UNCONN 0 0 :68 :
udp UNCONN 0 0
:111 :
udp UNCONN 0 0 :893 :
udp UNCONN 0 0 :::69 :::

udp UNCONN 0 0 :::111 :::
udp UNCONN 0 0 :::893 :::

tcp LISTEN 0 128 :111 :
查看是誰在監聽:
[root@centos7 ~]# ss -ntulp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0
:5353 : users:(("avahi-daemon",pid=6238,fd=12))
udp UNCONN 0 0 :49063 : users:(("avahi-daemon",pid=6238,fd=13))
udp UNCONN 0 0 192.168.122.1:53
: users:(("dnsmasq",pid=7400,fd=5))
udp UNCONN 0 0
:67 : users:(("dhcpd",pid=22547,fd=7))
udp UNCONN 0 0 %virbr0:67 : users:(("dnsmasq",pid=7400,fd=3))
udp UNCONN 0 0
:68 : users:(("dhclient",pid=23857,fd=6))
udp UNCONN 0 0 :111 : users:(("rpcbind",pid=6234,fd=5),("systemd",pid=1,fd=155))
udp UNCONN 0 0
:893 : users:(("rpcbind",pid=6234,fd=10))

udp UNCONN 0 0 :::69 :::* users:(("in.tftpd",pid=24131,fd=0),("systemd",pid=1,fd=24))

udp UNCONN 0 0 :::111 :::*
3、實現確保開機就啟動TFTP服務:
[root@centos7 ~]# systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.

註:筆記:(centos7 1、yum install tftp-server 2、systemctl start tftp 3、systemctl enable tftp)(centos6 1、yum install tftp-server 2、chkconfig tftp on 3、service xinetd restart )

4、我們在客戶端安裝TFTP
[root@Centos6 ~]# yum install tftp
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
base | 3.7 kB 00:00
centosplus | 3.4 kB 00:00
contrib | 2.9 kB 00:00
epel | 4.7 kB 00:00
epel/primary_db | 6.0 MB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 3.0 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package tftp.x86_64 0:0.49-8.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================
Package Arch Version Repository Size

Installing:
tftp x86_64 0.49-8.el6 base 32 k

Transaction Summary

Install 1 Package(s)

Total download size: 32 k
Installed size: 45 k
Is this ok [y/N]: y
Downloading Packages:
tftp-0.49-8.el6.x86_64.rpm | 32 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : tftp-0.49-8.el6.x86_64 1/1
Verifying : tftp-0.49-8.el6.x86_64 1/1

Installed:
tftp.x86_64 0:0.49-8.el6

Complete!
[root@Centos6 ~]# rpm -ql tftp
/usr/bin/tftp
/usr/share/doc/tftp-0.49
/usr/share/doc/tftp-0.49/CHANGES
/usr/share/doc/tftp-0.49/README
/usr/share/doc/tftp-0.49/README.security
/usr/share/doc/tftp-0.49/README.security.tftpboot
/usr/share/man/man1/tftp.1.gz
[root@Centos6 ~]# chkconfig tftp on
[root@Centos6 ~]# service xinetd restart
Stopping xinetd: [FAILED]
Starting xinetd: [ OK ]

5、我們找到他的工作目錄,裏面無東西,拷貝一份文件過來,命名為f1
[root@centos7 ~]# cd /var/lib/tftpboot/
[root@centos7 tftpboot]# ls
[root@centos7 tftpboot]# cp /etc/fstab f1
[root@centos7 tftpboot]# ll
total 4
-rw-r--r-- 1 root root 655 Feb 3 11:44 f1

[root@Centos6 ~]# tftp 192.168.141.130
tftp> get f1
tftp> quit 此時centos6上就可以接收到f1 文件。

至此,tftp服務搭建完成!!

實驗:搭建TFTP服務