N00b question about iptables
I have 2 Linodes (App1 and App2) running a web application behind a NodeBalancer. The two application servers connect to a database server (DB1) though a 2nd NodeBalancer. Both application servers were able to access the database server through the NodeBalancer until I implimented iptables to secure the database server (DB1).
I've included my iptables config below - please could someone help and advise a suitable rule? Would really appreciate your help.
In an attempt to get things working I implemented the "# Allow connections from other Linodes" section with all the Linode IP's but this doesn't seem to have worked.
*filter
# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -i lo -d 127.0.0.0/8 -j REJECT
# Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow all outbound traffic - you can modify this to only allow certain traffic
-A OUTPUT -j ACCEPT
# Allow SSH connections
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
# Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
# Log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Allow connections from other Linodes
# External Ip's
-A INPUT -s IPADDRESSHERE -j ACCEPT
-A INPUT -s IPADDRESSHERE -j ACCEPT
-A INPUT -s IPADDRESSHERE -j ACCEPT
-A INPUT -s IPADDRESSHERE -j ACCEPT
# Internal Ip's
-A INPUT -s IPADDRESSHERE -j ACCEPT
-A INPUT -s IPADDRESSHERE -j ACCEPT
-A INPUT -s IPADDRESSHERE -j ACCEPT
-A INPUT -s IPADDRESSHERE -j ACCEPT
# Balancers
-A INPUT -s IPADDRESSHERE -j ACCEPT
-A INPUT -s IPADDRESSHERE -j ACCEPT
# External Ip's
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
# Internal Ip's
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
# Balancers
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
-A OUTPUT -s IPADDRESSHERE -j ACCEPT
# Reject all other inbound - default deny unless explicitly allowed policy
-A INPUT -j REJECT
-A FORWARD -j REJECT
COMMIT
3 Replies
I've managed to fix this with;
-A INPUT -p tcp -m tcp -s 192.168.0.0/16 –dport 3306 -j ACCEPT
After establishing with Linode support that NodeBalancer IP addressers are not static, but operate within the 192.168.0.0/16 range.
Thanks,
Adam.
@mnordhoff:
Um… 192.168.0.0/16 also covers the private IPs of every other customer in the data center, and a /17 that isn't used at all. That's a really bad idea. You should ask Linode for a more specific address range that's only used by NodeBalancers -- IIRC they used to be on 192.168.255/24 or so.
Yes, NodeBalancers do use 192.168.255.0/24.