Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-24-2007, 05:59 PM
|
#1
|
Member
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175
Rep:
|
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
|
|
|
02-24-2007, 06:07 PM
|
#2
|
LQ Guru
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870
|
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...
|
|
|
02-24-2007, 06:12 PM
|
#3
|
Member
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175
Original Poster
Rep:
|
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.
|
|
|
02-24-2007, 07:25 PM
|
#4
|
LQ Guru
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870
|
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.
|
|
|
02-25-2007, 11:11 PM
|
#5
|
Member
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175
Original Poster
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 05:04 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|