I
need to restrict ssh port (22) and mongod port (27017) to be accessible
from my office network only, our office network range is 192.168.1.*
and 192.168.2.*.
Mevalal Yadav
<mevalal.yadav@gmail.com># Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -s 192.168.1.0/255.255.255.0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -s 192.168.2.0/255.255.255.0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -s 192.168.1.0/255.255.255.0 -p tcp -m tcp --dport 27017 -j ACCEPT
-A INPUT -s 192.168.2.0/255.255.255.0 -p tcp -m tcp --dport 27017 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j REJECT
-A INPUT -p tcp -m tcp --dport 27017 -j REJECT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Devendra Joshi
<devendra.joshi9987@gmail.com>you can user TCP wrapper as well as iptables for this or both.
/etc/hosts.deny
iptables -A OUTPUT -d 192.1681.0/24,192.168.2.0/24 -p tcp --sport 22 -m state ESTABLISHED -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24,192.168.2.0/24 -p tcp --dport 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d 192.1681.0/24,192.168.2.0/24 -p tcp --sport 27017 -m state ESTABLISHED -j ACCEPT
Nilesh Chavan
<nileshdc8@gmail.com>
Thanks for your reply, I have below doubts :
1. do i need to run all the commands one after anothere
2. do i need to prefix iptables cmd before each line abov.
Mevalal Yadav
<mevalal.yadav@gmail.com>
Edit iptables files, then paste following 6 iptables rules which are mark bellow,
u have to put 6 rules before -A INPUT -j REJECT --reject-with icmp-host-prohibited this rule[root@server ~]# vi /etc/sysconfig/iptables
-A INPUT -s 192.168.1.0/255.255.255.0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -s 192.168.2.0/255.255.255.0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -s 192.168.1.0/255.255.255.0 -p tcp -m tcp --dport 27017 -j ACCEPT
-A INPUT -s 192.168.2.0/255.255.255.0 -p tcp -m tcp --dport 27017 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j REJECT
-A INPUT -p tcp -m tcp --dport 27017 -j REJECT
[root@server ~]# /etc/init.d/iptables restart
No comments:
Post a Comment