1

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
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
  • That lost me connection to the server. Should there be double space after -s? – Teddy291 Jun 14 '15 at 3:00
  • So it's work fine.... No single space or double space no differ. – PersianGulf Jun 14 '15 at 3:05
  • It doesn't work fine 1.1.1.1 should be able to communicate with the server – Teddy291 Jun 14 '15 at 3:07
  • I'm confusing, Do you want to 1.1.1.1 access to net or not? – PersianGulf Jun 14 '15 at 3:13
  • test with above changes (\!) – PersianGulf Jun 14 '15 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.