LinuxQuestions.org
Visit Jeremy's Blog.
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 03-09-2010, 07:53 AM   #1
khaan
LQ Newbie
 
Registered: Feb 2007
Distribution: ubuntu
Posts: 24

Rep: Reputation: 15
How to set how long iptables remembers?


Hi,

I've got a box with 2 interfaces, with IP1 = 192.168.100.1 and IP2 = 10.1.1.1 respectively on them.
I've got an iptables rule that looks like:

Code:
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -d 10.0.0.0/8 -p udp -j SNAT --to-source 10.1.1.1 --random
If I get 2 consecutive packets from the same address and port from 192.168.100.0/24, they get SNAT-ed and come out of the same port on 10.1.1.1. If then I get another packet from the same address and port 10 minutes later, then it gets SNAT-ed, but comes out of a different port on 10.1.1.1.

My question is: how can I set the time delay I would like iptables to remember its incoming address/port to outgoing port mappings?
 
Old 03-09-2010, 08:10 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
I don't think you can if you're using random.
You can use
--average percent

Quote:
random
This module randomly matches a certain percentage of all packets.

--average percent
Matches the given percentage. If omitted, a probability of 50%
is set.
 
Old 03-09-2010, 10:09 AM   #3
khaan
LQ Newbie
 
Registered: Feb 2007
Distribution: ubuntu
Posts: 24

Original Poster
Rep: Reputation: 15
smoker: I don't think we're talking about the same thing. I am using the --random argument to the SNAT target.

Code:
       --random
              If  option --random is used then port mapping will be randomized
              (kernel >= 2.6.21).
 
Old 03-09-2010, 10:17 AM   #4
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
man iptables
 
Old 03-09-2010, 10:56 AM   #5
khaan
LQ Newbie
 
Registered: Feb 2007
Distribution: ubuntu
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by smoker View Post
man iptables
errmmm... yeees, that's where
Code:
       --random
              If  option --random is used then port mapping will be randomized
              (kernel >= 2.6.21).
comes from.
 
Old 03-09-2010, 11:32 AM   #6
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
percentage of time ?

You can't set the time ,but you can set how many times on average a packet gets matched by the random rule.
 
Old 03-09-2010, 11:48 AM   #7
sarin
Member
 
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
Not too sure, but have you tried state?

iptables -t nat -A POSTROUTING -m state --state ESTABLISHED,RELATED -s 10.0.0.0/24 -p udp -j SNAT --to 10.1.0.100

Btw, Working on SIP?
 
Old 03-09-2010, 01:23 PM   #8
mpier
Member
 
Registered: Jan 2008
Location: Poland
Distribution: Slackware, Arch
Posts: 38

Rep: Reputation: 17
Hi,
/proc/sys/net/ipv4/netfilter/ip_conntrack_udp_timeout, /proc/sys/net/ipv4/netfilter/ip_conntrack_udp_timeout_stream.
 
1 members found this post helpful.
Old 03-10-2010, 06:14 AM   #9
khaan
LQ Newbie
 
Registered: Feb 2007
Distribution: ubuntu
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by mpier View Post
Hi,
/proc/sys/net/ipv4/netfilter/ip_conntrack_udp_timeout, /proc/sys/net/ipv4/netfilter/ip_conntrack_udp_timeout_stream.
Thanks, that's exactly what I was looking for.
 
  


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-save, iptables-restore, how to set up them in some script sarajevo Linux - Networking 1 03-24-2008 11:39 PM
The forum never remembers me... shame LQ Suggestions & Feedback 7 06-11-2007 03:27 AM
LXer: The World Remembers 9/11 LXer Syndicated Linux News 0 09-11-2006 06:21 PM
OLD hardware trivia - who remembers EGA? rose_bud4201 Linux - Hardware 7 10-15-2004 11:19 AM
KDE never remembers my file associations agustin Mandriva 5 11-07-2003 01:19 PM

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

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