{"id":23548,"date":"2024-01-02T07:46:47","date_gmt":"2024-01-02T07:46:47","guid":{"rendered":"https:\/\/linuxways.net\/?p=23548"},"modified":"2024-01-03T04:47:42","modified_gmt":"2024-01-03T04:47:42","slug":"block-ssh-ftp-access-specific-ip-network-range-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/block-ssh-ftp-access-specific-ip-network-range-linux\/","title":{"rendered":"How to Block SSH and FTP Access to Specific IP and Network Range in Linux"},"content":{"rendered":"<p>Nowadays, protecting our Linux server is very important. Blocking the SSH and FTP access to specific IP addresses and network ranges is a very important step to improve security.<\/p>\n<p>Let us discuss why we should block the SSH and FTP access on our Linux operating system. We will also talk about two different types of methods to block the SSH and FTP access to specific IP and network ranges in our Linux system.<\/p>\n<h2><strong>Why Should We Block the SSH and FTP Access in Linux?<\/strong><\/h2>\n<p>For various convincing reasons, blocking the SSH (Secure Shell) and FTP (File Transfer Protocol) access in Linux is critical. First and foremost, security is very important. We limit the attack chances in our Linux by blocking the access and making it less vulnerable. Brute-force attacks and other unwanted access attempts frequently target the SSH and FTP. We prevent these attacks by blocking the access to specific IP and network ranges.<\/p>\n<p>Second, the regulatory compliance and privacy are the major issues. Many businesses must follow the strict industry or government rules such as GDPR, HIPAA, or PCI DSS. These rules often require the implementation of severe access controls by enterprises.<\/p>\n<p>Furthermore, we may adjust our server&#8217;s security measures to our organization&#8217;s specific needs by blocking the SSH and FTP\u00a0access to specified IP addresses or network ranges. This helps us access only the right individuals. We can use these methods since these methods reduce\u00a0the danger of data breaches and ensure a server stability.<\/p>\n<h2><strong>1. Using Iptables<\/strong><\/h2>\n<p>The iptables is an effective tool to control the network security on Linux. It works at the packet level, allowing us to establish the rules for blocking the traffic based on a variety of parameters such as the source and destination IP addresses.<\/p>\n<p>Let us see the steps on how we can block the SSH and FTP access with the help of iptables.<\/p>\n<p>We can create our rules by accessing the iptables configuration file which is usually located at \u201c\/etc\/sysconfig\/iptables\u201d or \u201c\/etc\/iptables\/rules.v4\u201d.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">nano<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>sysconfig<span class=\"sy0\">\/<\/span>iptables<\/div><\/div>\n<p>To block the SSH access from a specific IP address, type the following line to the configuration file:<\/p>\n<p>-A INPUT -s 192.168.2.101 -p tcp &#8211;destination-port 22 -j DROP<\/p>\n<p>To block the FTP access, we have to input a similar line for the FTP port:<\/p>\n<p>-A INPUT -s 192.168.2.101 -p tcp &#8211;destination-port 21 -j DROP<\/p>\n<p>After adding these rules, we have to save the configuration file and restart the \u201ciptables\u201d service.<\/p>\n<p>We have to type the following command to apply these changes:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> service iptables restart<\/div><\/div>\n<h2><strong>2. Using the TCP Wrappers<\/strong><\/h2>\n<p>Another way to block the SSH and FTP access is using the TCP Wrappers. TCP Wrappers is a simple yet the best host-based network access control method. The TCP Wrappers is integrated with SSH and FTP, both simplifying the process. We can easily manage them by changing these two important files: \u201c\/etc\/hosts.allow\u201d and \u201c\/etc\/hosts.deny\u201d.<\/p>\n<p>To block the access to specific IP and network range, we need to open the \u201c\/etc\/hosts.deny\u201d file using any text editor.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">vi<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>hosts.deny<\/div><\/div>\n<p>Then, we have to type two lines to block a specific incoming SSH connection.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">sshd: 192.168.2.101<br \/>\n<br \/>\nsshd: 192.168.2.0<span class=\"sy0\">\/<\/span>255.255.255.0<\/div><\/div>\n<p>To block the FTP access, we have to type the following lines in the same file:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">vsftpd: 192.168.2.101<br \/>\n<br \/>\nvsftpd: 192.168.2.0<span class=\"sy0\">\/<\/span>255.255.255.0<\/div><\/div>\n<p>Finally, we have to restart the SSH and FTP services. Now, the SSH and FTP access are blocked to some IP and Networks.<\/p>\n<p>We can restart SSH by typing the following commands in our terminal:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">$ service sshd restart<br \/>\n<br \/>\n$ systemctl restart sshd<\/div><\/div>\n<p>We can restart FTP by typing the following commands in our terminal:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">$ service vsftpd restart<br \/>\n<br \/>\n$ systemctl restart vsftpd<\/div><\/div>\n<p>The SSH and FTP access from the hosts with the IP address of 192.168.2.101 and the network range of 192.168.2.0 will be blocked.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Linux gives us various methods for personalized access control such as iptables or TCP Wrappers. We can easily reduce the vulnerabilities and the risk of unauthorized access by blocking the SSH and FTP access to specific IP addresses and network ranges. It is a good security practice that makes maintaining our server very simple.<\/p>","protected":false},"excerpt":{"rendered":"<p>Practical guide on the two different types of methods to block the SSH and FTP access to specific IP and network ranges in our Linux system along with examples.<\/p>","protected":false},"author":111,"featured_media":23553,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-23548","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/23548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=23548"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/23548\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/23553"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=23548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=23548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=23548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}