Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like to configure my VPS in the way that it ONLY accepts connections from outside on port 22 (where sshd listens) and ICMP requests. Everything else from outside should be rejected. Inside the server, everything should be allowed. Do the following rules create the desired behaviour?

# iptables -A INPUT -p all             -s 127.0.0.1      -j ACCEPT
# iptables -A INPUT -p tcp  --dport 22                   -j ACCEPT
# iptabels -A INPUT -p icmp                              -j ACCEPT
# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# iptables -A INPUT -p all                                -j REJECT

I am not completely sure if ACCEPT rules will "win" over the last overall REJECT

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You are correct.

The rules will be processed in line order of the file. If there is a match for a rule no other rules will be processed for that IP packet in your case.

http://en.wikipedia.org/wiki/Iptables

Each rule in a chain contains the specification of which packets it matches. It may also contain a target (used for extensions) or verdict (one of the built-in decisions). As a packet traverses a chain, each rule in turn is examined. If a rule does not match the packet, the packet is passed to the next rule. If a rule does match the packet, the rule takes the action indicated by the target/verdict, which may result in the packet being allowed to continue along the chain or it may not

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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