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 04-18-2010, 11:46 AM   #1
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Rep: Reputation: 39
syntax error in firewall script


I have not used the word COMMIT in following firewall script.I want to know is it a syntax error.
Code:
# Generated by iptables-save v1.4.2 on Sun Feb 8 17:37:00 1889
*nat
:PREROUTING DENY [43476:6097270]
:POSTROUTING DENY [27683:1570355]
:OUTPUT ACCEPT [187:10649]
-A PREROUTING -i eth2 -p tcp -m tcp --dport 2029 -j DNAT --to-destination 192.1.0.22:22
-A PREROUTING -i eth2 -p tcp -m tcp --dport 2036 -j DNAT --to-destination 192.1.0.23:22
-A PREROUTING -i eth2 -p tcp -m tcp --dport 2032 -j DNAT --to-destination 192.1.0.24:22
-A PREROUTING -i eth2 -p tcp -m tcp --dport 2043 -j DNAT --to-destination 192.1.0.25:22
COMMIT
# Completed on Sun Feb 8 17:37:00 1889
# Generated by iptables-save v1.4.2 on Sun Feb 8 17:37:00 1889
*filter
:INPUT ACCEPT [122559:20425150]
:FORWARD ACCEPT [671748:150202498]
:OUTPUT ACCEPT [40042:13111931]
-A INPUT -i eth2 -p tcp -m tcp --dport 2029 -j ACCEPT
-A INPUT -i eth2 -p tcp -m tcp --dport 2036 -j ACCEPT
-A INPUT -i eth2 -p tcp -m tcp --dport 2032 -j ACCEPT
-A INPUT -i eth2 -p tcp -m tcp --dport 2043 -j ACCEPT
 
Old 04-18-2010, 09:07 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
The script is created by 'iptables-save', generally you are not supposed to edit these files by hand, just configure iptables how you want then 'iptables-save > /etc/sysconfig/iptables'. Another option is to edit /etc/sysconfig/iptables-config and change 'IPTABLES_SAVE_ON_STOP="no"' to 'IPTABLES_SAVE_ON_STOP="yes"' so it will save your rules when you stop it.

I would guess that a missing 'COMMIT' on the end could be a problem, try reloading iptables and see if there are any error messages and whether the rules are correct

cheers
 
Old 04-18-2010, 10:08 PM   #3
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by kbp View Post
The script is created by 'iptables-save', generally you are not supposed to edit these files by hand, just configure iptables how you want then 'iptables-save > /etc/sysconfig/iptables'. Another option is to edit /etc/sysconfig/iptables-config and change 'IPTABLES_SAVE_ON_STOP="no"' to 'IPTABLES_SAVE_ON_STOP="yes"' so it will save your rules when you stop it.

I would guess that a missing 'COMMIT' on the end could be a problem, try reloading iptables and see if there are any error messages and whether the rules are correct

cheers
I can not reboot the server that is a problem.
Secondly it is a
Debian server.We are having Xen running on it virtualization stuff.So what is happening is it is changing the vif bridges names a lot many times.After a reboot a IPTABLE rule that was applied to a vif bridge this vif bridge does not exist any more.
I want a few firewall rules to be active at the time of boot which I have configured.So should I write a shell script or how should I go for it.
 
Old 04-18-2010, 10:31 PM   #4
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Word "COMMIT" doesn't have not any relation to iptables rules.

If you want add rule permanently you need to find already existed config. file with default rules and add your rules there or write small script, which will be loaded at boot time, BUT after iptables activation. Otherwise it will erase them.
 
Old 04-18-2010, 11:05 PM   #5
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
If you're using a bridged connection you should be performing packet filtering that's specific to the guest within the guest, not within Dom0.

i.e.

Code:
Dom0 # iptables -L
[rules specific to Dom0]

Guest1 # iptables -L
[rules specific to Guest1]
 
Old 04-19-2010, 12:10 AM   #6
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by kbp View Post
If you're using a bridged connection you should be performing packet filtering that's specific to the guest within the guest, not within Dom0.

i.e.

Code:
Dom0 # iptables -L
[rules specific to Dom0]

Guest1 # iptables -L
[rules specific to Guest1]
Ya you are right the thing is I have configured IPTABLES to DNAT an SSH connection to DomU from Dom0 which is on a public IP.The rules I posted above are accepting connections at ports
2029
2036
2032
2043
and forwarding to inside DomU's at port 22
So it is like that.


Quote:
Originally Posted by nimnull22 View Post
Word "COMMIT" doesn't have not any relation to iptables rules.

If you want add rule permanently you need to find already existed config. file with default rules and add your rules there or write small script, which will be loaded at boot time, BUT after iptables activation. Otherwise it will erase them.
Okay this was helpful thanks can you give me some link so that I can be sure.

Last edited by tkmsr; 04-19-2010 at 02:26 AM.
 
Old 04-19-2010, 08:17 AM   #7
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Actually:
Code:
*filter
:INPUT ACCEPT [122559:20425150]
:FORWARD ACCEPT [671748:150202498]
:OUTPUT ACCEPT [40042:13111931]
-A INPUT -i eth2 -p tcp -m tcp --dport 2029 -j ACCEPT
-A INPUT -i eth2 -p tcp -m tcp --dport 2036 -j ACCEPT
-A INPUT -i eth2 -p tcp -m tcp --dport 2032 -j ACCEPT
-A INPUT -i eth2 -p tcp -m tcp --dport 2043 -j ACCEPT
Your default rule for INPUT chain is ACCEPT, so any other rules with ACCEPT decision in this chain - is useless.

Where can you find file with rules for iptable, it depends on distribution, for example for OpenSuse it is in:
/etc/sysconfig/scripts/SuSEfirewall2-custom
in Fedora 12 it is /etc/sysconfig/firewall...something
 
Old 04-19-2010, 09:19 AM   #8
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by nimnull22 View Post
Your default rule for INPUT chain is ACCEPT, so any other rules with ACCEPT decision in this chain - is useless.
Agreed right now it is like that but I will be changing that.That is why I am asking this question.
What I have found out is to be able to run firewall at boot I need to do
write a script in if-up.d on Debian
it will use iptables-restore< </path to where ever I saved iptable>

Or we need to add a line in interfaces before eth2
mentioning post boot what script it should load.

I manually deleted some of the entries so before I do some thing wanted to make sure that things are right I do not have a physical access to the server.
Any how thanks for your reply.
 
Old 04-19-2010, 05:05 PM   #9
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Do you have this:
/etc/init.d/iptables
if yes you can use "start" part of this script to read your rules or from any other places with "iptables-restore" command.
Unfortunately, I do not really know Debian.

Last edited by nimnull22; 04-19-2010 at 05:08 PM.
 
Old 04-19-2010, 11:12 PM   #10
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by nimnull22 View Post
Do you have this:
/etc/init.d/iptables
if yes you can use "start" part of this script to read your rules or from any other places with "iptables-restore" command.
Unfortunately, I do not really know Debian.
No I do not have the thing is I have to do it only once so I am a bit cautious.I can not take chances.
 
  


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
syntax error in VERSION script shariefbe Linux - Software 0 02-16-2010 10:44 PM
perl script syntax error matt007 Programming 2 09-17-2009 11:00 AM
why am getting error ksh: syntax error: `fi' unexpected while running script deb4you Linux - Newbie 4 09-06-2008 08:37 AM
Bash script syntax error snowman81 Programming 5 11-16-2007 02:35 AM
shell script help required syntax error sridhar11 Programming 1 10-31-2005 08:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

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