Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to test a ethernet bridging device. I have multiple ethernet ports on a linux box. I would like to send packets out one interface, say eth0 with IP 192.168.1.1, to another interface, say eth1 with IP 192.168.1.2, on the same subnet.

I realize that normally you don't configure two interfaces on the same subnet, and if you do the kernel routes directly to each interface, rather than over the wire. How can I override this behavior, so that traffic to 192.168.1.2 goes out the 192.168.1.1 interface, and visa-versa?

Thanks in advance!

share|improve this question
why in Godsname would you want this? – Lucas Kauffman Jul 27 '12 at 18:51
I have a wireless device that bridges ethernet traffic. I have a box with several ethernet ports. I would like to do bandwidth testing of the wireless device. – rj75 Jul 27 '12 at 21:17
Isn't it a lot easier to just use a second device? – Lucas Kauffman Jul 27 '12 at 21:53
Scripts would be cleaner if everything happened on the same box. – rj75 Jul 31 '12 at 20:55

1 Answer

try

#mark packets from 192.168.1.1 to 192.168.1.2
iptables -t mangle -I OUTPUT -s 192.168.1.1 -d 192.168.1.2 -j MARK --set-mark 11
#mark packets from 192.168.1.2 to 192.168.1.1
iptables -t mangle -I OUTPUT -s 192.168.1.2 -d 192.168.1.1 -j MARK --set-mark 12

#add routing table for 192.168.1.1 
ip ru a fwmark 11 table 11
ip r a 192.168.1.2 dev eth0  t 11

#add routing table for 192.168.1.2
ip ru a fwmark 12 table 12
ip r a 192.168.1.1 dev eth1  t 12

man ip , man iptables for more info

share|improve this answer
A little more context would help round out your answer (Pretend you don't know what the ip command does and briefly explain what the alphabet soup means :). In a lot of answers on the site we go out of our way to discourage people from blindly typing things they find on the internet without really understanding it -- seems fair that our answers should encourage understanding over blind "type this" solutions... – voretaq7 Jul 31 '12 at 15:04
I pretend that OP already know 'man' command. why I should explain what iproute does ? – eicto Jul 31 '12 at 15:07
in fact it may be not full solution, will update the answer to make it worki better – eicto Jul 31 '12 at 15:17
Much better -- You'd be surprised how many people have not yet mastered the use of manual pages... – voretaq7 Jul 31 '12 at 16:30
I know, but I still not think that you need to read documentation of core utilites for anybody. as you not need to describe printf on stackoverflow :) – eicto Jul 31 '12 at 16:35
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.