IPtables installation and configuration: Try this approach

Hi Guys, whoever is having issue with iptables installation and configuration task, please try this approach.I have had success with it.I am new to linux and I thought to share with the community. Anyway, this approach has worked for me.

1)install iptables in all three apps( stapp01, stapp02, stapp03)

sudo yum install –y iptables-services

systemctl enable iptables

systemctl enable ip6tables

systemctl start iptables

systemctl start ip6tables

sudo iptables -A INPUT -p tcp --destination-port (in question) -s 172.16.238.14 -j ACCEPT
sudo iptables -A INPUT -p tcp --destination-port (in question) -j DROP

  1. service iptables save

Please, let me know your thoughts.Thanks.

2 Likes

@nidhincn Hi, can we just do the accept command part as it will ultimately reject for other incoming connections on the port specified?
Why did you do the DROP part please let me know , im bit confused.

Sorry for getting back to you late.The question specifically asks for blocking the port in question, so I have explicitly used the DROP command here.As, i mentioned already, I am new to Linux and still learning the things.However, this approach has worked for me.Thanks.

1 Like

@nidhincn @akshayyw…I followed the above steps as it is on all app servers. But when i tried to curl/telnet from load balancer server its not connecting…plz suggest.

Hi @pratikshag you can refer this once where I have mentioned the steps for this task . It might help you to identify what you are doing wrong:

Hi @pratikshag,
Did you check your iptable rules are same in all app servers?Also, did you validate the curl command from load balancer to all other app servers, such as stapp02 and stapp03 ?
Regards
Nidhin