How to stop every incoming traffic except from 1 ip, on an ubuntu server [closed]

I have 1 server that runs Redis on port 7632. I want to block all incoming traffic to that server, for this port, except from my web server and from localhost.

My web server ip is, for this example, 123.43.45.6.

Can anyone tell me how I can do this in ubuntu?

Thanks!

Answer

Add the following three firewall rules in this order:

iptables -A INPUT -p tcp -s 127.0.0.1 --dport 7632 -j ACCEPT
iptables -A INPUT -p tcp -s 123.43.45.6 --dport 7632 -j ACCEPT
iptables -A INPUT -p tcp --dport 7632 -j DROP

That should do the trick.

Attribution
Source : Link , Question Author : user158052 , Answer Author : Dennis Kaarsemaker

Leave a Comment