Restrict ssh access using Iptable

ww‮‬w.lautturi.com
Restrict ssh access using Iptable

To restrict ssh access using Iptables, you can follow these steps:

  1. Connect to your Linux server via ssh as a user with root privileges.

  2. Check if Iptables is installed by running the following command:

iptables --version

If Iptables is not installed, you can install it using your system's package manager. For example, on CentOS, you can use the following command:

yum install iptables-services

On Ubuntu, you can use the following command:

apt-get install iptables
  1. Once Iptables is installed, you can use the following command to allow ssh access only from a specific IP address:
iptables -A INPUT -s IP_ADDRESS -p tcp --dport 22 -j ACCEPT

Replace "IP_ADDRESS" with the IP address that you want to allow ssh access from.

  1. To block ssh access from all other IP addresses, use the following command:
iptables -A INPUT -p tcp --dport 22 -j DROP
  1. Save the Iptables rules by running the following command:
service iptables save
  1. Finally, restart the Iptables service to apply the changes:
service iptables restart

Now, ssh access to your server will be allowed only from the IP address specified in step 3. All other IP addresses will be blocked.

Note: If you want to allow ssh access from multiple IP addresses, you can repeat step 3 for each IP address.

Created Time:2017-10-30 14:27:16  Author:lautturi