Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I´m trying to route from a specific src IP address
to a new network interface, but it´s not working
First, I tried to use iptables commands, my first thought was like this:
iptables -t nat -A PREROUTING 1 -i eth0 -s <src> -d <dst> -j DNAT --to <interface>
but that command is not available, I just can give IP addresses after the --to argument.
Furthermore, I think iptables is too 'high-level' for this task (?).
I tried to use ip route commands, but that seems to be too low-level and used to route between interfaces etc..
But I have to route dependent on a src IP address to an interface.
Can anyone give me a hint and tell me how to solve this problem?
I will try to explain the problem a bit more in detail:
I have two virtual machines running on a xen hypervisor.
The Xen hypervisor is in routing mode, that means it has two IP addresses 192.168.0.1 for the frontend network and 192.168.1.1 for the backend network.
First, there was a single VM having the IP address 192.168.1.2 and running behing the hypervisor in the back end network.
ip route shows:
192.168.1.2 dev vif1.0 scope link src 192.168.0.1
192.168.0.0/24 dev vif1.0 proto kernel scope link src 192.168.0.1
(so that means on the hypervisor layer, the VM has the network interface vif1.0)
Now the interessting part starts: I made a live clone of this VM which results in a second VM running
on the same hypervisor and having the same IP address but another virtual interface:
192.168.1.2 dev vif1.0 scope link src 192.168.0.1
192.168.0.0/24 dev vif1.0 proto kernel scope link src 192.168.0.1
192.168.1.2 dev vif2.0 scope link src 192.168.0.1
192.168.0.0/24 dev vif2.0 proto kernel scope link src 192.168.0.1
Now I want to route to the original-VM or to the cloned-VM dependent on the IP source address.
For example, Bob should be routed to the original-VM as normal and Alice should be routed to the cloned-VM while both communicating with the same destination IP address.
That means I can only route dependent on the interface and not on the target IP address (what my current problem is)
I attached a little illustration of the setup.. (its for research)
I know that there are some other problems considering network traffic,
and that I have to block certain replies, but acutally this is the main problem :-)
Why are there two routing items with the same network? Are they created that way by xen? To my not-bound-by-xen network knowledge, it feels like it's not gonna hold water. That sounds like you should bridge the virtual network interfaces and place the IP address (192.168.0.1/24) on the bridge instead, am I wrong?
Code:
192.168.0.0/24 dev vif1.0 proto kernel scope link src 192.168.0.1
192.168.0.0/24 dev vif2.0 proto kernel scope link src 192.168.0.1
Yes they are created by Xen running in routing mode.
You can run Xen in brdiging mode (which is more easy),
but we need Xen in routing mode for this project.
Do you know how I could solve the problem?
How can I route from a src IP address to a target VM through a specific interface?
Don't know the difference between both modes I can only see the routing problem as seen in your routing tables.
You have two interfaces with overlapping network segments. The IP addresses set for those two interfaces is the same on the host? Can you remove the IP address from those interfaces (on the host), bridge them and set the IP address on the bridge? You could, of course set the exact dst address to get in touch with a certain VM. Routing will use the best matching rule so if you set a rule to reach one single IP address it won't hesitate to use it instead of the defined /24.
So....
Code:
ip route add ipaddressvm1 dev devvm1 src myip
ip route add ipaddressvm2 dev devvm2 src myip
That should do. Perhaps using two different network segments? Anyway, hope it helps.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.