3

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 1.1.1.1 -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 1.1.1.1 also?

2 Answers 2

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

Delete line #2 and add the following lines:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .