LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-14-2014, 02:33 PM   #1
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Rep: Reputation: 46
iptables drop all traffic except......


Ladies & Gents

I am trying to develop a script that will drop all traffic except to and from two specific web-sites.

This is what I have so far.

Code:
#!/bin/bash
#--------------------------------------------------
# Script to flush all existing firewall rules and limit all traffic to the online stream 
# and the Shabbat service stream.  There may be as much as 12 hours before the normal cron 
# job that reloads the droplist from Spamhous.org kicks in and downloads the new list as
# the currently used list may be 37 hours old.
#
# We need to make this script run 21 minuets prior to sundown, probably with an "at" job.

# First we need to stop Arno Iptables Firewall with something like.

/etc/init.d/arno-iptables-firewall stop

# not sure that is correct since the adoption of systemd by debian.

# Second I think I need to flush all the existing rules with something like.

iptables --flush

# Then we need to build the new rule set for the coming Shabbat.  Since we only
# want to allow traffic to and from the online radio stream and the online service I think
# we should do something like this.

iptables -I FORWARD -s 216.118.106.247 -j ALLOW
iptables -I FORWARD -s s2.voscast.com -j ALLOW
iptables -I INPUT -d 216.118.106.247 -j ALLOW
iptables -I INPUT -d s2.voscast.com -j ALLOW
iptables -I OUTPUT -s 216.118.106.247 -j ALLOW
iptables -I OUTPUT -s s2.voscast.com -j ALLOW
iptables  INPUT -s eth1 -j DROP
iptables  FORWARD -s eth1 -j DROP
iptables  OUTPUT -s eth1 -j DROP
iptables  INPUT -s eth0 -j DROP
iptables  FORWARD -s eth0 -j DROP
iptables  OUTPUT -s eth0 -j DROP
iptables  INPUT -s eth2 -j DROP
iptables  FORWARD -s eth2 -j DROP
iptables  OUTPUT -s eth2 -j DROP

# After the Shabbat is over we need to restart the firewall with something like.
# And scheduled to run 45 minuets after sundown with an "at" job.

/etc/init.d/arno-iptables-firewall start

# I am not sure that is correct since the adoption of systemd by debian.  I want long term
# durability here.  So if they are going to drop the above in favor of something else I want
# to use that instead.
The "at" jobs will be scheduled by a different script.

I guess my biggest questions are:

1. Do I have a lot of extra iptables rules that I don't need?

2. Is what I have going to drop all traffic except that to and from the two desired sites?

All traffic except what goes to and from these two sites is to be unconditionally dropped and not allowed.

I am hoping to get this setup before the next Shabbat if possible.

Thanks

Last edited by rbees; 10-15-2014 at 05:10 AM.
 
Old 10-14-2014, 11:17 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
as a start change 'FOWARD' to 'FORWARD'
 
Old 10-15-2014, 05:08 AM   #3
rbees
Member
 
Registered: Mar 2004
Location: northern michigan usa
Distribution: Debian Squeeze, Whezzy, Jessie
Posts: 921

Original Poster
Rep: Reputation: 46
Thanks NevemTeve.

I'd like to think I would have seen that at some point but........

I have not tried to actually run the script. I am not convinced that it will do what I want. The traffic to and from those two allowed sites may/must/need(s) to be NATed to the proper internal host that needs to access them depending on which host it is and what time of the day it is. Is what I have going to allow that.

I am not any kind of iptables specialist. That's why I use Arno's to build my normal firewall and restarting it after the Shabbat will re-enable normal traffic when the work week starts again.

Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to find why application is loosing CPU causing network traffic drop JagsN Linux - Kernel 9 09-11-2013 12:58 PM
Is it necessary to drop specific flags in IPTABLES with an INPUT DROP policy? rootaccess Linux - Networking 5 08-22-2012 08:10 PM
[SOLVED] Q: How to Drop inbound traffic to port 80 (http) from source ports less than 1024? snowfish Linux - Security 1 02-01-2011 02:59 AM
[HELP] redirect traffic to spesific port based on Traffic Content using iptables summersgone Linux - Server 2 06-22-2009 11:26 AM
iptables - drop all -> allow needed OR allow all -> drop specific lucastic Linux - Security 5 12-21-2004 02:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration