The purpose of this article is to explain the procedure of manipulating Iptables in order to grant access to a particular server only through a specific IP address. To do this you need to append a rule into the Iptables chain. Follow the article to successfully achieve this.
Step 1: Login to the server that needs to be accesed from a single IP.
# ssh root@xxx.xxx.xxx.xx
Step 2: Check the iptables rules by using the following command
# sudo iptables -S
Step 3: Identify the IP address of the primary server that you want to use to access the server with IP xxx.xxx.xxx.xx. Let this IP be yyy.yyy.yyy.yy.
Step 4:To add new rule use the command
# sudo vim /etc/sysconfig/iptables
Press the key I to enter edit mode.
Add the following rule to the Iptables rule of server with IP xxx.xxx.xxx.xx
-A INPUT -m tcp -p tcp -s yyy.yyy.yyy.yy --dport 22 -j ACCEPT
Purpose: This rule will allow access via port 22 only from the IP yyy.yyy.yyy.yy
Step 5: To save, press ESC key followed by :wq! and the hit the ENTER key.
/etc/init.d/iptables restart
Now the above added rule will only allow ssh access to the server with IP yyy.yyy.yyy.yy and block all other ssh input traffic.
[ht_message mstyle="danger" title="" " show_icon="" id="" class="" style="" ]Make sure to replace xxx.xxx.xxx.xx and yyy.yyy.yyy.yy with your corresponding IP Addresses.[/ht_message]