LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-16-2001, 12:55 PM   #1
lostone
LQ Newbie
 
Registered: May 2001
Posts: 4

Rep: Reputation: 0

I have installed Red Hat 7.1 on a machine and begun attempting to create a firewall using iptables. I believe I know what I need to do to make it happen but I began to write a script file which does not work as I expect it to. I shortened the file up to try to figure out what's happening. This is my script named rc.firewall

#!/bin/sh
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
exit 0

iptables is the program name, -P means change the default policy of the chain, INPUT is the chain, and DROP is the policy I want.

If I type the lines for iptables from the prompt the policy changes as expected.

When I attempt to run my script by typing sh rc.firewall, from the appropriate directory, I get the following,

iptables: Bad policy name
iptables: Bad policy name
iptables: Bad policy name
'c.firewall: exit: bad non-numeric arg `0

It appears to me that iptables is run from the script, it recognizes the -P to change the policy, I believe it recognizes the chain name but drops the ball on the policy. Yes it is case sensitive and I am using the correct case. I have tried both. Further it does not seem to recognize 0 (zero) as a valid arguement after exit. However, typing sh to enter the shell then exit 0 doesn't generate an error message. Just for more info from the shell I typed exit n , a letter instead of a number and got the error message. Also I edited the script and put a semi-colon after the zero and that error message went away. Okay, what have I done wrong? Thanks in advance to whoever knows whats going on.
 
Old 05-17-2001, 07:11 PM   #2
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 46
Question No definate answer, just an idea...

Try using a different shell. Try say tcsh or specifiying bash directly (I assume that RH using bash to replace sh anyway [sorry - I'm a Slackware man]).

See if that changes anything. I use the follwing fine:

#!/bin/sh
#setup the masquerading rules using ipchains
echo "Activating IPv4 packet forwarding..."
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/ipchains -P forward DENY
/sbin/ipchains -A forward -s 192.168.1.0/24 -j MASQ

ipchains -A input -i eth1 --destination-port 123 -p tcp -j ACCEPT
ipchains -A input -i eth1 --destination-port 123 -p udp -j ACCEPT

#allow connections to my http server...
ipchains -A input -i eth1 --destination-port 80 -p tcp -j ACCEPT
ipchains -A input -i eth1 --destination-port 80 -p udp -j ACCEPT

#lets filter out some ports! DENY causes the packet to be dropped so
#the person trying to connect gets a long delay not just a rejected
#connection reply. Make port scanners have to wait a long time!
#filter anything coming into a port <=1024
/sbin/ipchains -A input -i eth1 -s 0.0.0.0/0 --destination-port 0:1024 -p tcp -
j DENY

<SNIP!>
.....
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Operator Precedence C++ Problem rovitotv Programming 9 03-21-2005 11:02 PM
Operator Overloading problem ashwinipahuja Programming 1 06-23-2004 06:59 AM
logical operator problem. Xiangbuilder Programming 5 09-07-2003 11:02 PM
Script file problem (or operator problem) HELP! lostone Programming 2 05-23-2001 03:30 PM
Script file problem (or operator problem) HELP! lostone Linux - Newbie 0 05-15-2001 08:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration