0

I'am using iptables in many server's but now stuck with this issue while using default Policy as DROP.

Here is my rules which i have used in VPS, Tried many time's everything seems fine but VPS getting disconnected when i use this rules.

Only i want ssh port 2222, and ntp for updating my time.

iptables -F
iptables -X LOGGING
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 2222 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 2222 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p udp --sport 2222 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p udp --dport 2222 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p udp --sport 123 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p udp --dport 123 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -j DROP
iptables -N LOGGING
iptables -A INPUT -j LOGGING
iptables -A LOGGING -m limit --limit 10/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 7

till logout from VPS i can access VPS it's still established, If once i used to logout and trying to login again i can't login. Will any one review the rules for me ?

1

Here's your rules with regard to incoming traffic on port 2222:

iptables -A INPUT -i eth0 -p tcp --sport 2222 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p udp --sport 2222 -m state --state ESTABLISHED -j ACCEPT  

You aren't allowing NEW connections, so you won't be able to connect from outside.

This question might now be of interest.

  • i have updated the above rules and tried after adding NEW, but still i can't login into the server. – Babin Lonston Jan 6 '15 at 20:29
  • fixed it but replacing INPUT chain to dport and OUTPUT to sport.. – Babin Lonston Jan 7 '15 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.