Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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      -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
up vote 5 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.

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


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.