<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body dir="ltr" bgcolor="#ffffff" text="#000000">
<p style="margin-bottom: 0cm; margin-top: 0pt;">Daniel Feiglin wrote:<br>
</p>
<blockquote cite="mid:49BA5663.8090102@inter.net.il" type="cite">
<pre wrap="">Hello folks!
I'm trying to use a Linux box as a packet traffic generator. It has two
NICs configured with fixed IP addresses, 192.168.2.100/101. For testing
purposes, I connected the two NICs to each other with a crossed network
cable (hardware loopback). For what it's worth, they can both be pinged
from the host and the ifconfig output looks fine.
</pre>
</blockquote>
Okay, I thought I had a simple answer for you. One that does not
involve multiple machines.<br>
<br>
Assuming we want eth0 to be .100 and eth1 to be .101, perform the
following operations:<br>
ifconfig eth0 192.168.2.98<br>
ifconfig eth1 192.168.2.99<br>
route add -host 192.168.2.100 dev eth1<br>
route add -host 192.168.2.101 dev eth0<br>
<br>
iptables -A POSTROUTING -t nat -o eth1 -d 192.168.2.100 -j DNAT
--to-destination 192.168.2.98<br>
iptables -A POSTROUTING -t nat -o eth0 -d 192.168.2.101 -j DNAT
--to-destination 192.168.2.99<br>
<br>
The idea is to assign one IP address to the interface card, and then
try and connect to another one. Then use iptables to rewrite the packet.<br>
<br>
The problem, as anyone trying to implement this will notice, is that
the DNAT rule is illegal in the POSTROUTING table. It is only legal in
the PREROUTING or OUTPUT table, at which point it is too early to make
this change (we will revert back to the original problem).<br>
<br>
You can probably rig something up using raw packet modifications, but I
cannot find anything about that.<br>
<br>
Another solution, one that requires more work on your part, is to use a
virtual interface (such as tun) for your work, and write the code for
the rewriting inside of it.<br>
<br>
Sorry, almost got it :-)<br>
<br>
Shachar<br>
<br>
<pre class="moz-signature" cols="72">--
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
<a class="moz-txt-link-freetext" href="http://www.lingnu.com">http://www.lingnu.com</a>
</pre>
</body>
</html>