I have 2 servers, one for web requests (I named it the web
) and another one is for database (I named it the db
). Both servers are CentOS 7.
I want to make these rules in iptables
:
- all request to
db
server should be blocked (all IPs on all ports); - just
web
server (y.y.y.y
) can access thedb
server on ports5432
and6379
; - just a static ip (
x.x.x.x
) can access port22
.
So I wrote these rules but I'm not sure they are correct
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -p tcp --dport 5432 -s y.y.y.y -j ACCEPT
iptables -A INPUT -p tcp --dport 6379 -s y.y.y.y -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s x.x.x.x -j ACCEPT