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