Use IPTables to force TCP packets over router

1

To test a TCP-stack program, I need to get the TCP packets via the router. When I try to connect to my server program via the router, the OS does not hit the router as the destination IP is the same as the source IP.

Can I make a temporary rule to tell the Linux stack to use a specific adapter (wlan0) and a specific router address for outgoing TCP packets with a specific target port (5101)?

Lanbo

Posted 2014-02-03T12:29:52.417

Reputation: 157

Linux will use wlan0 if that is the route for the IP. Does it need to be port 5101, or can all traffic be temporarily routed through the router? Why don't you try man ip-route? – BenjiWiebe – 2014-02-03T13:51:35.430

@BenjiWiebe: I checked with wireshark, and there is definitively no packet going over wlan0 when accessing the computer's own IP. – Lanbo – 2014-02-05T08:21:43.770

Answers

0

I am not sure I understood your problem, but it seems to me (if I have understood it right), that a simpler oslution is to have your program listen on loopback (127.0.0.1), and then send your packets to loopback (with the appropriate port, of course).

MariusMatutiae

Posted 2014-02-03T12:29:52.417

Reputation: 41 321

Unfortunately, no, as I am testing a self-written TCP/IP stack and I need to receive the packet via the router on the specified adapter. – Lanbo – 2014-02-03T13:27:56.557