LinuxQuestions.org
Help answer threads with 0 replies.
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-24-2007, 05:59 PM   #1
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Rep: Reputation: 31
iptables rules question...


I was looking for a way to block certain ip block ranges, and I found a guide online. The steps are shown below.

If I follow the steps, would that replace my current /etc/sysconfig/iptables? If not, how are the new firewall rules appplied?

Here are the steps...

# iptables -N KRFILTER
# iptables -N KRFILTERED

Run the shell script and append rules to KRFILTER chain.
NOTE: ALL.sh.txt just contains many lines of:
iptables -A KRFILTER -s 58.2.0.0/16 -j KRFILTERED

# sh ALL.sh.txt

Append a rule, accepting the packets which aren't caught by the filters, to KRFILER chain.

# iptables -A KRFILTER -j ACCEPT

Append a rule, discarding the packets caught by the filters, to KRFILERED chain.

# iptables -A KRFILTERED -j DROP

If you want to record the information of the dropping packets, use following commands instead. You can view the log by "dmesg" command (or in syslog).

# iptables -A KRFILTERED -j LOG --log-prefix "Rej-TCP "
# iptables -A KRFILTERED -j DROP

Append a rule, dispatching the SYN packets (which initiates new TCP connection), to INPUT chain.

# iptables -A INPUT -p tcp -m state --state NEW -j KRFILTER
 
Old 02-24-2007, 06:07 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by fw12
If I follow the steps, would that replace my current /etc/sysconfig/iptables? If not, how are the new firewall rules appplied?
when you execute iptables rules, they are applied to your active iptables configuration... in other words, they will have taken effect, but they will not be saved until you choose to do so... basically, one executes iptables rules, then makes sure everything is working fine... once one is satisfied that the rules are working properly then one proceeds to save them in order for them to survive reboot, etc... on red hat-based distros the command to save them is usually:
Code:
service iptables save
your /etc/sysconfig/iptables file will remain untouched until you perform a save operation...
 
Old 02-24-2007, 06:12 PM   #3
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Thanks for the info.

I was just wondering if my current /etc/sysconfig/iptables will be replaced, or if the new rules just get appended.
 
Old 02-24-2007, 07:25 PM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by fw12
I was just wondering if my current /etc/sysconfig/iptables will be replaced, or if the new rules just get appended.
appending only happens in the active configuration (ie, "iptables -A")... when you do a save, a complete snapshot of your active configuration (including counters, as shown below) at that moment replaces whatever you had previously saved...

Code:
root@candystore:~# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
root@candystore:~# iptables-save > /tmp/example-saved-config.txt
root@candystore:~# cat /tmp/example-saved-config.txt
# Generated by iptables-save v1.3.3 on Sat Feb 24 19:16:19 2007
*mangle
:PREROUTING ACCEPT [12:3163]
:INPUT ACCEPT [12:3163]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [13:2505]
:POSTROUTING ACCEPT [13:2505]
COMMIT
# Completed on Sat Feb 24 19:16:19 2007
# Generated by iptables-save v1.3.3 on Sat Feb 24 19:16:19 2007
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [1:60]
:OUTPUT ACCEPT [1:60]
COMMIT
# Completed on Sat Feb 24 19:16:19 2007
# Generated by iptables-save v1.3.3 on Sat Feb 24 19:16:19 2007
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [13:2505]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
COMMIT
# Completed on Sat Feb 24 19:16:19 2007
root@candystore:~# iptables -A INPUT -p TCP --dport 666 -j ACCEPT
root@candystore:~# iptables -P FORWARD ACCEPT
root@candystore:~# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:666

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
root@candystore:~# iptables-save > /tmp/example-saved-config.txt
root@candystore:~# cat /tmp/example-saved-config.txt
# Generated by iptables-save v1.3.3 on Sat Feb 24 19:18:08 2007
*mangle
:PREROUTING ACCEPT [1103:1517477]
:INPUT ACCEPT [1103:1517477]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [785:63209]
:POSTROUTING ACCEPT [785:63209]
COMMIT
# Completed on Sat Feb 24 19:18:08 2007
# Generated by iptables-save v1.3.3 on Sat Feb 24 19:18:08 2007
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [12:720]
:OUTPUT ACCEPT [12:720]
COMMIT
# Completed on Sat Feb 24 19:18:08 2007
# Generated by iptables-save v1.3.3 on Sat Feb 24 19:18:08 2007
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [785:63209]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m tcp --dport 666 -j ACCEPT
COMMIT
# Completed on Sat Feb 24 19:18:08 2007
root@candystore:~#
BTW: remember that you should never manually edit your /etc/sysconfig/iptables file...

Last edited by win32sux; 02-24-2007 at 07:29 PM.
 
Old 02-25-2007, 11:11 PM   #5
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Good info.

Quote:
remember that you should never manually edit your /etc/sysconfig/iptables file
Really?

I've been naively doing it for a long time with success.

I guess I just have to find the time to educate myself about iptables.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Question about iptables rules huanvnn Linux - Security 4 06-02-2006 10:05 PM
Question about IPtables/firewall rules ilan1 Linux - Security 3 02-21-2006 12:58 AM
IPTABLES - rules in /etc/sysconfig/iptables The_JinJ Linux - Newbie 6 11-20-2004 02:40 AM
IPTables rules dkny01 Linux - Networking 6 10-23-2003 01:52 AM
Full iptables rules flush question NetScripter Linux - General 7 09-17-2003 02:03 PM

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

All times are GMT -5. The time now is 05:04 PM.

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