LinuxQuestions.org
Help answer threads with 0 replies.
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 08-10-2004, 05:47 AM   #1
max_sipos
Member
 
Registered: Jul 2004
Posts: 96

Rep: Reputation: 15
Question iptables problem in a very simple script


Hi, this is a simple firewall for a single machine connected to internet. Unfortunately, it doesn't work (nothing works when rc.firewall start). Changing default policy for INPUT to ACCEPT works but then it's not protected, right? What am I doing wrong?

-----

#!/bin/bash

# My firewall script - Max
# using iptables

#iptables options:
# -A append to the type of chain: INPUT, OUTPUT or FORWARD
# -s source of packet: DNS or IP address (with INPUT)
# -j what to do: ACCEPT, DENY or DROP
# -d destination of packet (with OUTPUT)
# -p protocol: tcp
# --destination-port: telnet
# -F flush all
# --syn syn packet, packet sent when establishing connection (you want to drop these, when incoming)

case $1 in
start)
# flush all rules first:
iptables -F; iptables -t nat -F; iptables -t mangle -F;
# do not accept any services on my computer
iptables -A INPUT -p tcp --syn -j DROP
# only accept established and related connections
iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
# default policy: drop
iptables -P INPUT DROP
#don't forward anything
iptables -P FORWARD DROP
#allow output
iptables -P OUTPUT ACCEPT
;;
stop)
echo "WARNING: Firewall DOWN!"
iptables -F;
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
;;
*)
echo "Usage: $0 start|stop"
;;

esac

#end firewall
 
Old 08-10-2004, 06:19 AM   #2
ppuru
Senior Member
 
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
you need to exempt the local interface (lo) from your firewall rules

iptables -A INPUT -i lo -j ACCEPT and
iptables -A OUTPUT -o lo -j ACCEPT

immediately after your iptables -F
 
Old 08-10-2004, 06:58 AM   #3
max_sipos
Member
 
Registered: Jul 2004
Posts: 96

Original Poster
Rep: Reputation: 15
It turns out that this line was the problem:

# only accept established and related connections
iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT

Getting rid of "-p tcp" fixed the problem (I don't understand why, I just tryed everything).

ACCEPTing from lo allowed me to ping myself which is good

---
Thank you,
Maksim Sipos
 
  


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
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Problem with simple script petenyce Linux - Newbie 1 10-13-2005 09:00 AM
simple script problem jong357 Programming 2 09-24-2005 04:13 PM
Simple IPTABLES problem zahoo Linux - Networking 2 03-09-2005 09:43 PM
Simple shell script problem? Corallis Linux - Newbie 3 03-21-2004 11:25 PM

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

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