IPTABLES how to allow/block private/public IPs
Posted: Thu Dec 17, 2020 2:26 pm
Dear Expert
Having NagiosXI 5.x.x
Centos 6.x
assume localhost = 192.168.50.50
how to allow/block private/public IPs via IPTABLES
allow from all Private IPs <<<<<<< Full Access to this localhost = 192.168.50.50
allow from some Public IPs x.x.x.x/32 <<<<<< Full Access to this localhost = 192.168.50.50
allow from some Public IPs x.x.x.x/16 just ping (ICMP Echo) to this server (localhost=192.168.50.50)
allow telnet/ping/ssh from this localhost=192.168.50.50 to anyone <<<< you can say if initiated from this server , allowed
the below is current config, just for your reference to guide on above
more /etc/sysconfig/iptables.save
# Generated by iptables-save v1.4.7 on
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:END - [0:0]
:RULES - [0:0]
-A INPUT -j RULES
-A FORWARD -j RULES
-A OUTPUT -j RULES
-A END -j REJECT --reject-with icmp-port-unreachable
-A END -j REJECT --reject-with icmp-port-unreachable
-A RULES -s 198.144.0.0/16 -p tcp -m tcp --dport 3334 -j REJECT --reject-with icmp-port-unreachable
-A RULES -s 198.144.0.0/16 -p udp -m udp --dport 3334 -j REJECT --reject-with icmp-port-unreachable
-A RULES -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 3334 -j REJECT --reject-with icmp-port-unreachable
-A RULES -s 192.168.x.x/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -s 172.16.1.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -s 100.100.100.100/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -s 127.0.0.1/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -s 172.16.x.x/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -p tcp -m tcp --dport 22 -j REJECT --reject-with icmp-port-unreachable
-A RULES -m state --state RELATED,ESTABLISHED -j ACCEPT
-A RULES -p icmp -j ACCEPT
-A RULES -s 127.0.0.1/32 -j ACCEPT
-A RULES -s 200.200.200.200/32 -j ACCEPT
-A RULES -s 10.0.0.0/8 -j ACCEPT
-A RULES -s 192.168.0.0/16 -j ACCEPT
-A RULES -s 172.16.0.0/12 -j ACCEPT
-A RULES -p tcp -m multiport --dports 25,53,161,5667,5666 -j ACCEPT
-A RULES -p udp -m multiport --dports 53,123,161 -j ACCEPT
-A RULES -j END
COMMIT
# Completed on Thu Feb 14
# Generated by iptables-save v1.4.7 on Feb 14
*nat
:PREROUTING ACCEPT [1116:61961]
:POSTROUTING ACCEPT [18301:146671]
:OUTPUT ACCEPT [18301:146671]
COMMIT
# Completed on Feb 14
Regards
Having NagiosXI 5.x.x
Centos 6.x
assume localhost = 192.168.50.50
how to allow/block private/public IPs via IPTABLES
allow from all Private IPs <<<<<<< Full Access to this localhost = 192.168.50.50
allow from some Public IPs x.x.x.x/32 <<<<<< Full Access to this localhost = 192.168.50.50
allow from some Public IPs x.x.x.x/16 just ping (ICMP Echo) to this server (localhost=192.168.50.50)
allow telnet/ping/ssh from this localhost=192.168.50.50 to anyone <<<< you can say if initiated from this server , allowed
the below is current config, just for your reference to guide on above
more /etc/sysconfig/iptables.save
# Generated by iptables-save v1.4.7 on
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:END - [0:0]
:RULES - [0:0]
-A INPUT -j RULES
-A FORWARD -j RULES
-A OUTPUT -j RULES
-A END -j REJECT --reject-with icmp-port-unreachable
-A END -j REJECT --reject-with icmp-port-unreachable
-A RULES -s 198.144.0.0/16 -p tcp -m tcp --dport 3334 -j REJECT --reject-with icmp-port-unreachable
-A RULES -s 198.144.0.0/16 -p udp -m udp --dport 3334 -j REJECT --reject-with icmp-port-unreachable
-A RULES -p tcp -m state --state NEW,RELATED,ESTABLISHED -m tcp --dport 3334 -j REJECT --reject-with icmp-port-unreachable
-A RULES -s 192.168.x.x/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -s 172.16.1.0/24 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -s 100.100.100.100/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -s 127.0.0.1/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -s 172.16.x.x/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A RULES -p tcp -m tcp --dport 22 -j REJECT --reject-with icmp-port-unreachable
-A RULES -m state --state RELATED,ESTABLISHED -j ACCEPT
-A RULES -p icmp -j ACCEPT
-A RULES -s 127.0.0.1/32 -j ACCEPT
-A RULES -s 200.200.200.200/32 -j ACCEPT
-A RULES -s 10.0.0.0/8 -j ACCEPT
-A RULES -s 192.168.0.0/16 -j ACCEPT
-A RULES -s 172.16.0.0/12 -j ACCEPT
-A RULES -p tcp -m multiport --dports 25,53,161,5667,5666 -j ACCEPT
-A RULES -p udp -m multiport --dports 53,123,161 -j ACCEPT
-A RULES -j END
COMMIT
# Completed on Thu Feb 14
# Generated by iptables-save v1.4.7 on Feb 14
*nat
:PREROUTING ACCEPT [1116:61961]
:POSTROUTING ACCEPT [18301:146671]
:OUTPUT ACCEPT [18301:146671]
COMMIT
# Completed on Feb 14
Regards