0

I have an alias for eth0 called eth0:0.

Short version: I want to route packets from one virtual interface to another through an external gateway and not through the loopback interface.

Detailed: I want to route packets from eth0:0 (by using LD_PRELOAD, I can change the src IP address) to eth0. But this is handled by lo interface and I don't want that. What I want is that packets from eth0:0 should go to some default gateway which will then send process the packets and then send to eth0.

I can send packets with the source IP address of the eth0:0 alias but the complete setup is not working since I cannot allocate different MAC addresses for the eth0 and eth0:0 and so when the external gateway has to send the packets back, it can't figure out where to send the packets to.

What is a good way of achieving this?

EDIT: I have been told that the question was not clear.

eth0: IP address: 10.0.0.1
eth0:1: IP address: 10.0.0.2
Gateway: 10.0.0.10

I want to send packets from 10.0.0.2 to 10.0.0.1 through the external gateway 10.0.0.10 so that I can do some processing on the packets and then send to 10.0.0.1.

Basically, 10.0.0.0.2 <-> gateway <-> 10.0.0.1

user110
  • 13
  • 3
  • 1
    Confusing question. Add a second nic and don't use an alias then you'll have 2 separate MAC addresses. Although I don't really get your question. – hookenz Jan 07 '14 at 22:10
  • @Matt: I have updated the question. – user110 Jan 07 '14 at 22:34
  • 1
    The problem with this is that they are on the same subnet. So even if you had two separate machines you might still have issues sending it via a gateway. And in your case the OS sees both addresses and knows it doesn't need to route so won't. I'm not even sure adding host routes will do it. – hookenz Jan 07 '14 at 22:42
  • user110, what is the reason you want packets between those addresses to route via an external gateway? this kind of config is unusual. More than likely there is better way of achieving what your end goal is without this unusual setup. – hookenz Jan 07 '14 at 22:44
  • @Matt: This is for an experiment. I want to process packets in the gateway and then route them. By processing, I mean add delays/drop packets and stuff. – user110 Jan 07 '14 at 22:47

3 Answers3

1

If the 2 interfaces are on the same subnet, then the packets won't be sent out across the wire - it's shortcutting the physical adapter - NOT using the loopback device. If you really want to route packets in this way (I can't imagine why) then they would have to be configured on seperate subnets (and connected to a router which knew where to send the packets).

I cannot allocate different MAC addresses for the eth0 and eth0:0 and so when the external gateway has to send the packets back, it can't figure out where to send the packets to.

I suppose that your router is consiering this as a bridge loop, in which case just use a reflector somewhere else on the network.

symcbean
  • 19,931
  • 1
  • 29
  • 49
  • I am sorry but I don't understand what do you mean by shortcutting the physical adapter? Also, I am able to send out the packets if that is what you meant. – user110 Jan 07 '14 at 21:52
  • 1
    Your whole question is actually pretty confusing user110. Maybe some diagrams and show some IP addresses and explain what you want in more detail and why and then it'll all make sense. – hookenz Jan 07 '14 at 22:09
1

It sounds like you're wanting a kind of development setup. The way I'd achieve this on the one host is to use virtualization.

If you're using a desktop version of Linux then simply install Virtual Box and install another copy of Linux into it. Set the VM to use a network bridge for networking.

Then use two different subnets like this

Host.

address 10.0.0.0.1
netmask 255.255.255.0
gateway 10.0.0.254

VM

address 10.0.1.1
netmask 255.255.255.0
gateway 10.0.1.254

Set up your router to be on both subnets using an ip alias.

hookenz
  • 14,132
  • 22
  • 86
  • 142
0

If you remove the IP from the local routing table, (this is possible and it will send out of eth0) then on its way back (debatable it will ever make its way back) Linux will consider it a packet to be forwarded and not locally delivered. You'll never process the packets you get back but try and forward them.

If you want to add network problems to a device. Try looking at the netem qdisc.

For example.

tc qdisc add dev lo parent root netem loss random 50

Will drop 50% of the packets destined for lo.

Matthew Ife
  • 22,927
  • 2
  • 54
  • 71