LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 05-28-2011, 05:11 AM   #1
satish
Member
 
Registered: Jan 2006
Posts: 172

Rep: Reputation: 15
Iptables Question


I want some explanation for the iptables which is given below.

1)
iptables -A FORWARD -i eth2 -o eth3 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth3 -o eth2 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE

2)
iptables -A FORWARD -i eth3 -o eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth2 -o eth3 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth3 -j MASQUERADE

3)
iptables -A FORWARD -i eth1 -o eth0 -p tcp --sport 1024:65535 -d 192.168.1.249 --dport 4899 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -p tcp ! --syn -s 192.168.1.249 --sport 4899 --dport 1024:65535 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -p tcp --sport 1024:65535 -d 114.143.28.204 --dport 4899 -j DNAT --to-destination 192.168.1.249

This 3 iptables commands is given by linux questions when i put questions in the forum and they replied me positively thanks for the cooperation.

As I am a newbie in linux whenever i got the problem i asked to linuxquestions, now i don't know the explanation of this commands

I want to ask you that in the 3rd command we had used PREROUTING why we not used POSTROUTING.

If possible please give me the explanation for the above commands

Thanking You,

Satish
 
Old 05-28-2011, 07:12 AM   #2
pkrumins
LQ Newbie
 
Registered: Jan 2008
Location: Riga, Latvia
Posts: 3

Rep: Reputation: 0
Quote:
Originally Posted by satish View Post
I want some explanation for the iptables which is given below.

1)
iptables -A FORWARD -i eth2 -o eth3 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth3 -o eth2 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
The first rule says: all packets that come in eth2 and go out of eth3 and that are established should be accepted

The 2nd rule says: all packets going in eth3 and going out eth2 should be accepted

3rd rule: all traffic that goes out eth2 should be natted.

Quote:
Originally Posted by satish View Post
2)
iptables -A FORWARD -i eth3 -o eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth2 -o eth3 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth3 -j MASQUERADE
Same except eth2<->eth3 swapped.

Quote:
Originally Posted by satish View Post
3)
iptables -A FORWARD -i eth1 -o eth0 -p tcp --sport 1024:65535 -d 192.168.1.249 --dport 4899 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -p tcp ! --syn -s 192.168.1.249 --sport 4899 --dport 1024:65535 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -p tcp --sport 1024:65535 -d 114.143.28.204 --dport 4899 -j DNAT --to-destination 192.168.1.249
1st rule: all packets that go in eth1 and go out eth2 and proto is tcp and source port is in range 1024-65535 and destination is 192.168.1.249 and destination port is 4899 should be accepted.

2nd: all packets coming in eth0 and going out eth2 and proto is tcp and it's not syn (connection estabilishing) packet, and source is 192.168.1.249 and source port is 4899 and destination port is range 1024-65535 should be accepted.

3: nat all packets coming in eth1 with tcp proto and source port 1024-65535 and going to 114.143.28.204:4899, nat them all to 192.168.1.249.
 
Old 05-30-2011, 10:07 PM   #3
satish
Member
 
Registered: Jan 2006
Posts: 172

Original Poster
Rep: Reputation: 15
Iptables Question

you had given me good explanation,thanks for the reply now i want to ask you what is the POSTROUTING & PREROUTING

iptables -A FORWARD -i eth1 -o eth0 -p tcp --sport 1024:65535 -d 192.168.1.249 --dport 4899 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -p tcp ! --syn -s 192.168.1.249 --sport 4899 --dport 1024:65535 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -p tcp --sport 1024:65535 -d 114.143.28.204 --dport 4899 -j DNAT --to-destination 192.168.1.249


as you can see in the above iptables rules it is used PREROUTING why we used PREROUTING can we used POSTROUTING in the above rule.

Regards

Satish
 
Old 06-05-2011, 10:50 AM   #4
doru
Member
 
Registered: Sep 2008
Distribution: Ubuntu 8.04 LTS Server
Posts: 138

Rep: Reputation: 19
I believe that dnat is made in prerouting in order to allow routing decisions to be made correctly.

==============in
============prerouting
=========routing-decision
=======input
====local-process======forward
======output
==========routing-decision
===========postrouting
==============out

You should know the destination when you decide where you route the packet. Look at this diagram here: http://www.frozentux.net/iptables-tu...ERSINGOFTABLES (scroll down). You can't understand iptables without it. http://www.frozentux.net/documents/iptables-tutorial/

Last edited by doru; 06-05-2011 at 11:00 AM. Reason: bad alignment
 
Old 06-07-2011, 01:51 AM   #5
satish
Member
 
Registered: Jan 2006
Posts: 172

Original Poster
Rep: Reputation: 15
Iptables Question

Thanks for the reply you had given me good explnation and the link for the iptables book

Regrads

Satish
 
  


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 question.. ejd021 Linux - General 1 08-28-2010 11:35 AM
iptables question Mithrilhall Linux - Networking 10 08-12-2008 11:58 PM
iptables question lsu420luv General 2 03-23-2006 10:38 AM
iptables question ruben0076 Linux - Networking 2 01-16-2005 12:26 PM
Iptables question.. pembo13 Linux - Networking 2 09-24-2003 05:54 PM

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

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