LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-19-2010, 01:20 PM   #1
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
New rules do not take effect with existing UDP streams


On my firewall I have DNAT for certain UDP streams. I have set up the DNAT and FORWARD rules:

Code:
#: Redirect port 6006 to TH2
$IPTABLES -A FORWARD -j ACCEPT -d $hst_stratus_th2  -p udp --dport $prt_mdi
$IPTABLES -t nat -A PREROUTING --dst $hst_ext_internet -p udp --dport $prt_mdi -j DNAT --to-destination $hst_stratus_th2:$prt_mdi
#:
These lines are called in a bash script. So far, so good, the redirection works. That is not the question.

However while I am experimenting I want to change the --to-destination. I can change that, but the existing stream continues to be redirected to the old --to-destination.
Worse, the FORWARD rule is changed and applied, so the packets are dnatted to the old host, but disallowed by the FORWARD rule.

Only when I discontinue the UDP stream at the source, wait a certain amount of time and restart the stream, it is DNAT-ted correctly to the new host.

This is awkward of course. The nature of this UDP stream is that it comes in continuously and that I should be able to choose where to send it.

I know that even while UDP is stateless, iptables is stateful in some aspects for UDP streams as it tracks existing connections.

I set up iptables in a bash script, and this script starts with:

Code:
echo "0" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD DROP
$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F FORWARD
$IPTABLES -F
$IPTABLES -X
$IPTABLES -t mangle -P PREROUTING ACCEPT
$IPTABLES -t mangle -P OUTPUT ACCEPT
$IPTABLES -t mangle -F PREROUTING
$IPTABLES -t mangle -F OUTPUT
$IPTABLES -t mangle -F POSTROUTING
$IPTABLES -t nat -P PREROUTING ACCEPT
$IPTABLES -t nat -P POSTROUTING ACCEPT
$IPTABLES -t nat -P OUTPUT ACCEPT
$IPTABLES -t nat -F PREROUTING
$IPTABLES -t nat -F POSTROUTING
$IPTABLES -t nat -F OUTPUT
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -t filter -F
As you see, in desperateness I flush everything except the toilet.

Question: How to I tell iptables to discontinue redirecting the existing stream to one host and start redirecting it to a new host according to a new DNAT rule?

jlinkels
 
Old 02-19-2010, 01:25 PM   #2
jiobo
Member
 
Registered: Nov 2008
Posts: 180

Rep: Reputation: 36
You would have to delete the last rule, and then add the new rule. When you add a rule, unless you specify the rule location, it goes to the end of the list, so the rule before it is run first. You can also put the rule into the right location if you know the rule number to put it into. Read:
Code:
man iptables
 
Old 02-19-2010, 02:02 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by jiobo View Post
You would have to delete the last rule
AFAIK, by flushing all tables and chains I do delete all rules, or isn't that true?

Or is it important, as you say, to insert the new rule in exactly the same place as the old one?

jlinkels
 
Old 02-19-2010, 03:28 PM   #4
jiobo
Member
 
Registered: Nov 2008
Posts: 180

Rep: Reputation: 36
Quote:
Originally Posted by jlinkels View Post
AFAIK, by flushing all tables and chains I do delete all rules, or isn't that true?
You can flush all tables and chains, that is true. Then there are no rules in the tables and chains except the policies.

Code:
iptables -L
 
Old 02-19-2010, 04:44 PM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
When I have flushed all tables and chains and entered my new rules, and I do iptables -t nat -L and iptables -L I see my new rules. But still they are not applied to the existing stream.

Please don't talk in mysteries and tell me what I do wrong if I flush the tables and enter new rules. Do you mean that when I do iptables -L I should see some stuck rule after flushing? For sure not in the nat table, right?

jlinkels
 
  


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 rules against udp flood and ddos attack callbiz Linux - Networking 12 02-19-2010 08:13 AM
All UDP ports of my firewall are closed even without iptables rules, any clue? mfeoli Linux - Networking 2 01-05-2006 10:07 AM
Setting up router with IP based or TCP/UDP port rules raakjoer Linux - Networking 1 10-24-2005 08:51 AM
PVR with udp multicast streams? Fredde87 Linux - Software 1 08-20-2005 06:30 PM
IPTABLES how to add/edit/delete rules in existing chain? debug019 Linux - Newbie 1 11-11-2004 02:48 PM

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

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