LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-21-2015, 12:56 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Best Practice when creating iptables rules


So more and more at work I'm working with iptables. I'm having to modify existing rules along with implementing brand new rules for new servers.

I'm wondering what are best practices for setting up new iptables firewall rules, other then say allow ssh and icmp traffic.

thanks
 
Old 02-21-2015, 06:54 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
You're welcome to read my blog post on my take of using iptables. In general, your question is too vague to get an effective answer. "Best practices" for iptables are best practices on security and networking. Limit the scope as to who can talk to the system. The rules will vary depending on the type of system it is. Requirements for a system change based on what it does (e.g. PCI compliance). Perhaps, asking a more pointed question will get you a more useful answer.
 
Old 02-22-2015, 07:10 AM   #3
yzT!
Member
 
Registered: Jan 2013
Distribution: Debian
Posts: 168

Rep: Reputation: 2
There is no such thing as best practices for creating iptables rules. A best practice is what the above post states, principle of least privilege.

However, I recommend you two things to bear in mind. First, always follow the same structure on your rules, and second, make use of the states. For example, you may not want new incoming connections to be accepted, only those established and related.
 
Old 02-23-2015, 07:02 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
In addition to what sag47 wrote in his web log post about using 'iptables-restore' note you can also easily test a temporary rule set and revert back to a state after a period of time.

First make a backup before making changes to the current rule set:
Code:
umask 0027
iptables-save > /etc/sysconfig/iptables.backup
Now modify your rule set and before you reload it execute this:
Code:
echo "/sbin/iptables-restore < /etc/sysconfig/iptables.backup"|/usr/bin/at now + 5 minutes
which will restore your previously saved rule set in 5 minutes.

*On the subject of testing: the easiest way to test a rule set is to watch counters and intersperse your rule set with "-j LOG" rules before any jumps. That way you can see what hits the filter (or not).


As for the "best practices" I agree: apart from iptables-sepcific best practices (see frozentux) a firewall comprises of more than "plain" blocking ports (source and state filters, rate limiting, ipset buckets to name a few) and therefore should be based on not only what services a machine provides but more than that on what your hardening regime dictates in terms of network policies, access restrictions, auditing rules, etc, etc.


**More detailed questions are welcome, but note that would start with you posting more detailed information.
 
  


Reply

Tags
iptables



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
How can I tell if these iptables rules already exist? iptables -P INPUT ACCEPT iptabl abefroman Linux - Security 1 10-21-2013 03:00 PM
[SOLVED] during system startup, iptables rules not loaded from /etc/sysconfig/iptables danyim Linux - Security 3 04-13-2013 02:09 AM
Advice on best practice for creating sysadmin scripts pernest Linux - Server 5 03-06-2012 06:03 AM
using iptables in practice pqzha1 Linux - Security 3 05-16-2008 03:36 PM
Is this good iptables practice ? michaelsanford Linux - Security 1 05-21-2005 09:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 11:28 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