LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2009, 06:00 AM   #1
lasantha
Member
 
Registered: Oct 2005
Location: Sri Lanka
Distribution: Red Hat, Cent OS
Posts: 38

Rep: Reputation: 16
Smile iptables script not working


Dear All,

I asked to setup a firewall that have two zones. My LAN having 192.168.1.0/24 (firewall eth1 - 192.168.1.200) and router's connected ip 10.64.78.1/24 (firewall eth0 - 10.64.78.2).

I have written a script with drop policy. Internal (192.168.1.0/24) pcs need to access external SMTP/POP server ip a.b.c.d and also few pcs need to connect to it via SSH(putty).

I have tried to do this using following script and it is not working.(I am only having experience to write few rules for SMTP/POP servers using INPUT and OUTPUT chains that not FORWARD chain)


Code:
# Drop all
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

# Accept loop back address
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Forward SMTP/POP3,ssh traffic to and from OUT side
iptables -A FORWARD -i eth1 -o eth0 -p tcp -s 192.168.1.0/24 -d a.b.c.d --dport smtp,pop3,ssh -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A FORWARD -o eth0 -i eth1 -p tcp -s a.b.c.d -d 192.168.1.0/24 --sport smtp,pop3,ssh -m state --state ESTABLISHED -j ACCEPT

# Save and Start Iptables
service iptables save
service iptables start
Using following script I cant access the a.b.c.d server for smtp, pop3 and ssh.
Pls someone help meto correct this..

Lasantha
 
Old 03-04-2009, 10:04 AM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Replace those FORWARD rules with these:
Code:
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A FORWARD -p TCP -i eth1 -o eth0 -s 192.168.1.0/24 \
-d a.b.c.d -m multiport --dports 22,25,110 -m state --state NEW -j ACCEPT

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Then make sure you have IP forwarding enabled:
Code:
cat /proc/sys/net/ipv4/ip_forward
If it's not enabled, enable it:
Code:
echo 1 > /proc/sys/net/ipv4/ip_forward

Last edited by win32sux; 03-04-2009 at 10:14 AM.
 
Old 03-04-2009, 12:13 PM   #3
lasantha
Member
 
Registered: Oct 2005
Location: Sri Lanka
Distribution: Red Hat, Cent OS
Posts: 38

Original Poster
Rep: Reputation: 16
Thanks very much. I got the whole theory from the codes you have sent.
Its really helpful. I was stuck in there to apply nat for that. Now you have cleared the way. Thanks.....
 
Old 03-04-2009, 11:20 PM   #4
lasantha
Member
 
Registered: Oct 2005
Location: Sri Lanka
Distribution: Red Hat, Cent OS
Posts: 38

Original Poster
Rep: Reputation: 16
Dear win32sux,
I have done that and I am wondering way I cant integrate INPUT, OUTPUT rules that I have create for the firewall box listed bellow. If I run the following rules I cant log to firewall box via ssh because my link disconnects.

If you have time pls check and just guide me for corrections(Highly appreciate If you can correct). Any way thanks for the contribution that you have done for this thread.

Code:
# Drop all
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

# Enable IP FORWARDING
echo 1 > /proc/sys/net/ipv4/ip_forward

# Accept loop back address
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Rules for connect to SSH firewall box.
IPTABLES -A INPUT -i eth1 -p tcp -s 192.168.1.0/24 -d 192.168.1.200 \
--dport ssh -m state --state NEW, ESTABLISHED -j ACCEPT
IPTABLES -A OUTPUT -o eth1 -p tcp -d 192.168.1.0/24 -s 192.168.1.200 \
--sport ssh -m state --state ESTABLISHED -j ACCEPT

# Rules for Connect SMTP/POP3 and SSH for Admin works 
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -p TCP -i eth1 -o eth0 -s 192.168.1.0/24 \
-d a.b.c.d -m multiport --dports 22,25,110 -m state --state NEW -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# Save and Start Iptables
service iptables save
service iptables start
Thanks
Lasantha
 
Old 03-05-2009, 12:19 AM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
It wouldn't work with IPTABLES written in capital letters like that.
 
Old 03-05-2009, 06:45 AM   #6
lasantha
Member
 
Registered: Oct 2005
Location: Sri Lanka
Distribution: Red Hat, Cent OS
Posts: 38

Original Poster
Rep: Reputation: 16
Dear win32sux,

Actually this is a typing mistake and I am very sorry for that. Normally I do this with the simple letters only as like upper lines in the script.

script -> http://pastebin.com/m248994af

I would highly appreciate If you can correct.

Thanks

Lasantha
 
Old 03-05-2009, 12:03 PM   #7
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
It's so much better if you just paste here using CODE tags instead of on that website. In any case, troubleshooting this should be really easy. Change your OUTPUT policy to ACCEPT and try again. If it then works, you know the problem is with your OUTPUT rule. If it still doesn't work, are you positive that 192.168.1.200 is the IP of this box? Your last troubleshooting step will be to enable logging of filtered packets to see what exactly is going on here.
Code:
iptables -A INPUT -j LOG --log-prefix "INPUT DROP: "
iptables -A OUTPUT -j LOG --log-prefix "OUTPUT DROP: "
 
  


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
iptables-save, iptables-restore, how to set up them in some script sarajevo Linux - Networking 1 03-24-2008 11:39 PM
iptables script moved machine, stopped working dwynter Linux - Networking 12 02-05-2008 08:44 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Iptables firewall script stop working occassionally Niceman2005 Linux - Security 9 02-16-2007 12:35 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 - Networking

All times are GMT -5. The time now is 02:00 AM.

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