{"id":23,"date":"2025-03-29T12:48:27","date_gmt":"2025-03-29T10:48:27","guid":{"rendered":"https:\/\/www.24x7serverguard.com\/blog\/?p=23"},"modified":"2025-03-29T12:48:27","modified_gmt":"2025-03-29T10:48:27","slug":"block-ftp-access-using-the-iptables","status":"publish","type":"post","link":"https:\/\/www.24x7serverguard.com\/blog\/cpanel\/block-ftp-access-using-the-iptables\/","title":{"rendered":"Block FTP access using the IPtables"},"content":{"rendered":"\n<p>Sol.: 1) If you want to completely disable the FTP access on the server then run the command :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] iptables -A INPUT -p tcp \u2013dport 21 -j DROP<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>2) If you want to block FTP access for a Specific IP then run the below command :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] iptables -A INPUT -p tcp -s 10.10.10.10 \u2013dport 21 -j DROP<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>3) If you want to Disable FTP access for Specific Subnet then run the below command :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] iptables -I INPUT -p tcp -s 10.10.10.10\/24 \u2013dport 21 -j DROP<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>After adding the adding rules you need to save the rules by running the command :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] \/etc\/init.d\/iptables save<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>Then to apply the above saved rules , restart the IPtables by running the command :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] \/etc\/init.d\/iptables restart<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p><strong>Block FTP access using the CSF firewall<\/strong><br>1) If you want to completely disable the FTP access on the server then follow the steps :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] vi \/etc\/csf\/csf.conf<\/strong><br>Search for the lines :<br># Allow incoming TCP ports<br>TCP_IN =<br>and remove the port 21 from the list<br>Save and quit .<\/p>\n<\/blockquote>\n\n\n\n<p>And then restart the CSF firewall using the below command :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] csf -r<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>2) If you want to block FTP access for a Specific IP then follow the below steps :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] vi \/etc\/csf\/csf.deny<\/strong><br>and add the line :<br><strong>tcp:in:d=21:s=10.10.10.10<\/strong><br>save and quit<\/p>\n<\/blockquote>\n\n\n\n<p>And then restart CSF firewall using the below command :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] csf -r<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>3) If you want to allow FTP access for only one ip on the server and denied for all other ips<br>follow the steps :<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] vi \/etc\/csf\/csf.conf<\/strong><br>Then search for the line :<br><strong># Allow incoming TCP ports<\/strong><br>and the remove the&nbsp;<strong>ports : 21 and 22<\/strong><br>and also search for the line :<br><strong># Allow outgoing TCP ports<\/strong><br>and remove the&nbsp;<strong>ports : 21 and 22<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p><strong>Save and quit<\/strong><br>Then open the csf.allow file<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] vi \/etc\/csf\/csf.allow<\/strong><br>and add the entry as :<br><strong>tcp:in:d=21:s=10.10.10.10<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p><strong>Save and Quit.<\/strong><br>And then restart the CSF service<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>root@server[#] csf -r<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>Note : Replace the IP 10.10.10.10 with the Actual IP.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sol.: 1) If you want to completely disable the FTP access on the server then run the command : root@server[#] iptables -A INPUT -p tcp \u2013dport 21 -j DROP 2) If you want to block FTP access for a Specific IP then run the below command : root@server[#] iptables -A INPUT -p tcp -s 10.10.10.10 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-cpanel"],"_links":{"self":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/comments?post=23"}],"version-history":[{"count":1,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":24,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/23\/revisions\/24"}],"wp:attachment":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media?parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/categories?post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/tags?post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}