Previously I asked how to block all traffic except for specific IPs however that wasn't enough. I need to block all outbound/inbound except for my IPs. I don't want to be able to ping/connect to any IP not listed.

This is what I used before

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -s -j ACCEPT
iptables -A INPUT -j DROP    # or REJECT
service iptables save
service iptables restart

How can I stop all the outbound traffic except for also?

2 Answers 2

iptables -A INPUT -s -j ACCEPT
iptables -A OUTPUT -d -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT DROP
service iptables save
service iptables restart

Delete line #2 and add the following lines:

iptables -A OUTPUT \! -s -j REJECT
iptables -A FORWARD \! -s -j REJECT
  • That lost me connection to the server. Should there be double space after -s?
    – Teddy77
    Jun 14, 2015 at 3:00
  • So it's work fine.... No single space or double space no differ. Jun 14, 2015 at 3:05
  • It doesn't work fine should be able to communicate with the server
    – Teddy77
    Jun 14, 2015 at 3:07
  • I'm confusing, Do you want to access to net or not? Jun 14, 2015 at 3:13
  • test with above changes (\!) Jun 14, 2015 at 3:21

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.