LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-13-2002, 11:12 AM   #1
pollux0
LQ Newbie
 
Registered: Dec 2002
Posts: 10

Rep: Reputation: 0
is this iptables script correct?


Can anyone tell me how this iptable script looks? Is it correct? Is it efficient? Is there anything in there that does not look right or should not be there? Is there anything i should add?

I am trying to setup a firewall/Ip Masq. for an internal network. The firewall needs to accept ports 1444 & 1433 form 222.222.222.20

thanks in advance'


#!/bin/sh

echo 0 > /proc/sys/net/ipv4/ip_forward

LAN_IP_NET='192.168.1.1/24'
LAN_NIC='eth1'
WAN_IP='222.22.222.22'
WAN_NIC='eth0'

iptables -t nat -F POSTROUTING
iptables -t nat -F PREROUTING
iptables -t nat -F OUTPUT
iptables -F
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT

# Start additional Rules
iptables -A INPUT -p tcp --source-port 1433 -s 222.222.222.20 -j ACCEPT
iptables -A INPUT -p tcp --source-port 1444 -s 222.222.222.20 -j ACCEPT
# End additional rules

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -t nat -A POSTROUTING -s $LAN_IP_NET -j MASQUERADE
iptables -A FORWARD -j ACCEPT -i $LAN_NIC -s $LAN_IP_NET
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

echo 1 > /proc/sys/net/ipv4/ip_forward
 
Old 12-14-2002, 09:50 AM   #2
tarballedtux
Member
 
Registered: Aug 2001
Location: Off the coast of Madadascar
Posts: 498

Rep: Reputation: 30
Good enough. If the 2 ports you let through in the beginning are all you need to let through on the Internet interface then the firewall will hold on. You might want to try limiting the number SYN you take per second on ports 1433 and 1444.

--tarballedtux
 
Old 12-14-2002, 02:38 PM   #3
peter_robb
Senior Member
 
Registered: Feb 2002
Location: Szczecin, Poland
Distribution: Gentoo, Debian
Posts: 2,458

Rep: Reputation: 48
There are a few things I can see that won't work...
Quote:
iptables -A INPUT -p tcp --source-port 1433 -s 222.222.222.20 -j ACCEPT
iptables -A INPUT -p tcp --source-port 1444 -s 222.222.222.20 -j ACCEPT
Are you sure the source port will always be the same?
These rules would affect new connections coming in and should really refer to destination ports, ie server ports on your pc.
If they were intended for outgoing connections, they are covered by the iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT rule..
Quote:
iptables -t nat -A POSTROUTING -s $LAN_IP_NET -j MASQUERADE
This would cause problems when replies come back from forwarded connections. It should only apply to the outgoing interface eg
iptables -t nat -A POSTROUTING -o $WAN_NIC -j MASQUERADE

And you are making a lot of references to "-s ip.number.on.lan" . Only needs to be done if you are a router, not a host/gateway.
This is best handled by the reverse path filter
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter

Have a read of this tutorial and then a look at Firestarter and Shorewall packages..

Last edited by peter_robb; 12-14-2002 at 02:41 PM.
 
  


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
Problems getting a startup script starting at the correct time BrianK SUSE / openSUSE 3 11-13-2005 05:15 AM
Iptables - Finding the correct way? muppski Linux - Networking 1 07-18-2005 08:14 AM
cant get iptables nat/server script correct furryhit Linux - Networking 2 03-14-2004 09:00 AM
Is this iptables script correct?????? pollux0 Linux - General 0 12-13-2002 11:11 AM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

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

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