Hướng dẫn cài đặt TFTP Server trên CentOS 7 – Cuongquach.com | Ở bài viết này chúng ta sẽ cùng tìm hiểu cách cài đặt TFTP Server trên CentOS 7. Trivial File Transfer Protocol (TFTP) là một chương trình dịch vụ Internet giúp truyền tải file một cách đơn giản nhất hơn cả dịch vụ FTP. TFTP không yêu cầu chứng thực user và người dùng kết nối cũng không có khả năng liệt kê file trong thư mục TFTP Server. TFTP sử dụng giao thức UDP, bạn có thể tìm đọc thêm ở RFC 1350. Chương trình TFTP xài khá nhiều ở hệ thống PXE Server hay dùng để up flash đối với Router/Switch.
Các thao tác cài đặt TFTP Server trên CentOS 7
1. Cài đặt TFTP Server trên CentOS 7
Cài đặt các gói chương trình TFTP Server.
# yum install tftp tftp-server xinetd
Tắt SELinux nếu bạn không biết cấu hình hay sử dụng, bạn thường sẽ phải reboot lại hệ thống nhưng có thể tắt tạm thời SELINUX bằng lệnh ‘setenforce’ .
# vi /etc/selinux/config SELINUX=disabled # setenforce 0
2. Cấu hình dịch vụ TFTP
Khởi tạo user dành riêng cho thư mục chứa dữ liệu phục vụ dịch vụ TFTP Server.
# useradd --no-create-home -s /sbin/nologin tftp
Đầu tiên bạn có thể khởi tạo thư mục dành cho data sử dụng cho dịch vụ TFTP hoặc sử dụng thư mục mặc định trong cấu hình.
# mkdir -p /tftpdata # chmod 777 /tftpdata # touch /tftpdata/demo.txt # chown tftp:tftp -R /tftpdata
Cấu hình file dịch vụ TFTP và một số cấu hình chú thích.
# 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 = -c -v -u tftp -p -U 117 -s /tftpdata disable = disable per_source = 11 cps = 100 2 flags = IPv4 }
Chú thích :
– disable = disable
– server_args
+ ‘-c‘ : cho phép tạo file mới trên thư mục tftp.
+ ‘-s‘ : tự động change root directory cho người dùng kết nối đến TFTP, tức người dùng sẽ chỉ thấy nội dung file/thư mục trong thư mục /tftpdata đã được quy định trước.
+ ‘-u‘ : chỉ định user sử dụng cho thư mục TFTP.
+ ‘-p‘ : không thực hiện check quyền permission đối với user cụ thể như ‘tftp‘ đã tạo ở trên.
+ ‘-U‘ : chỉ định giá trị umask khi tạo mới 1 file.
+ ‘-v‘ : option giúp hiển thị các thông tin log khi kết nối TFTP Server.
Tham khảo các option tại : https://linux.die.net/man/8/tftpd
3. Khởi động dịch vụ TFTP và thêm vào danh sách startup service.
Chỉnh lại cấu hình systemd start service ở phần ‘ExecStart‘ mục [Service] cho giống cấu hình config phía trên.
# vi /usr/lib/systemd/system/tftp.service [Unit] Description=Tftp Server Requires=tftp.socket Documentation=man:in.tftpd [Service] ExecStart=/usr/sbin/in.tftpd -c -v -u tftp -p -U 117 -s /tftpdata StandardInput=socket [Install] Also=tftp.socket
Reload lại cấu hình systemd service đã chỉnh sửa.
# systemctl daemon-reload
Khởi động dịch vụ TFTP.
# systemctl start xinetd # systemctl start tftp
Thêm vào danh sách startup service.
# systemctl enable xinetd # systemctl enable tftp
Kiểm tra xem dịch vụ đã listen trên port UDP 69 chưa.
# netstat -antpu | grep 69 udp6 0 0 :::69 :::* 1/systemd
4. Cấu hình tường lửa allow port dịch vụ TFTP
Nếu bạn chạy dịch vụ TFTP sau 1 dịch vụ tường lửa thì bạn cần allow port incomming 69/UDP. Ví dụ với ‘iptables‘.
# iptables -I INPUT -p udp --dport 69 -j ACCEPT
5. Kiểm tra kết nối dịch vụ TFTP Server
Bạn có thể sử dụng chương trình WinSCP trên Windows để test. Hoặc nếu sử dụng Linux thì có thể test trực tiếp như sau. Sử dụng lệnh ‘get‘ – để lấy file về local ; ‘put‘ – để đẩy file lên hệ thống TFTP Server.
# tftp 192.168.1.42 get demo.txt
Như vậy bạn đã hoàn tất việc cài đặt TFTP Server trên CentOS 7 rồi đấy.
How to install TFTP Server on CentOS 7
How to install TFTP Server on CentOS 7 – Cuongquach.com | In this post i will show you how to install TFTP Server on CentOS 7. Trivial File Transfer Protocol (TFTP) is a small Internet service ultility that can help use to transfer file easier than FTP Service. TFTP does not require authentication from client and client cannot list file on directory of TFTP Server. TFTP use UDP Protocol at port number 69, you can read more from RFC 1350. TFTP Server is used a lots in PXE Server Environment or like a storage place to upload flash to Router/Switch.
Steps to install TFTP Server on CentOS 7
1. Install TFTP Server package
First of all, you need to install TFTP Server package on CentOS 7.
# yum install tftp tftp-server xinetd
Turn off SELinux feature if you dont know how to control and use it. You need to reboot os to apply new config of SELinux, however you can temporarily turn off it with command ‘setenforce‘.
# vi /etc/selinux/config SELINUX=disabled # setenforce 0
2. Config TFTP Service
I will create a user to be owner of data directory used by TFTP Service.
# useradd --no-create-home -s /sbin/nologin tftp
Now, a specific directory for TFTP Server ?! It’s up to you, follow me i will create one for service.
# mkdir -p /tftpdata # chmod 777 /tftpdata # touch /tftpdata/demo.txt # chown tftp:tftp -R /tftpdata
Configure file TFTP Service with below noticed config lines.
# 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 = -c -v -u tftp -p -U 117 -s /tftpdata disable = disable per_source = 11 cps = 100 2 flags = IPv4 }
Note :
– disable = disable :
– server_args
+ ‘-c‘ : allow client connect and create file on directory of TFTP Server.
+ ‘-s‘ : auto change directory when client connect to TFTP Server, to specific directory in the config file like /tftpdata. It’s secure feature.
+ ‘-u‘ : specific user owner of directory /tftpdata.
+ ‘-p‘ : Perform no additional permissions checks above the normal system-provided access controls for the user specified via the ‘-u’ option.
+ ‘-U‘ : setup Umask setting when client create or push new file.
+ ‘-v‘ : this option help print some logging verbose when client connect to TFTP Server.
References link : https://linux.die.net/man/8/tftpd
3. Start TFTP Service, add to list startup service
Edit file system start service of TFTP, change the configuration line ‘ExecStart‘ in [Service] section to be as same as the config of previous step (step 2).
# vi /usr/lib/systemd/system/tftp.service [Unit] Description=Tftp Server Requires=tftp.socket Documentation=man:in.tftpd [Service] ExecStart=/usr/sbin/in.tftpd -c -v -u tftp -p -U 117 -s /tftpdata StandardInput=socket [Install] Also=tftp.socket
Reload new configuration of systemd service file.
# systemctl daemon-reload
Start TFTP Service.
# systemctl start xinetd # systemctl start tftp
Add TFTP Service to startup service on CentOS 7.
# systemctl enable xinetd # systemctl enable tftp
Checking that TFTP is listenning on port UDP 69 or not.
# netstat -antpu | grep 69 udp6 0 0 :::69 :::* 1/systemd
4. Configure Firewall to allow TFTP Service
If you have local firewall on your server you need to set up allowing incomming port 69/UDP. For example with ‘iptables‘.
# iptables -I INPUT -p udp --dport 69 -j ACCEPT
5. Checking connecting to TFTP Server
If you are using Windows, you can use application like WinSCP to test connecting to TFTP Server. If you are using Linux OS, try using command ‘tftp’ to connect and use bot of tftp’s command like ‘get‘ – get file from TFTP Server ; ‘put‘ – push file from local to TFTP Server.
# tftp 192.168.1.42 get demo.txt
So now you finish tutorial how to install TFTP Server on CentOS 7.