Routing between different aliases of a NIC without lo

ip-aliasingrouting

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

Best Answer

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.

Related Topic