LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2012, 09:48 AM   #1
Biederony
LQ Newbie
 
Registered: Jun 2012
Posts: 4

Rep: Reputation: Disabled
Routing from src IP to new interface


Hi guys,

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?

Thank you!
 
Old 12-07-2012, 12:58 PM   #2
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
I think the problem is not clear at all.

For starters, what are your network interfaces? What are the ip addresses and what is routing like?

Code:
ip link show
ip addr show
ip route show
Then.... what would you like to achieve?
 
Old 12-07-2012, 01:04 PM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
Anyways.... perhaps you could try with routing based on source/dest addresses. I think it's possible using routing tables plus rules.

It goes something like:

Code:
ip rule add to x.x.x.x table some_table
ip route add default via y.y.y.y table some_table
some_table can be a number (I think) or the name of a table predefined in /etc/iproute2/rt_tables.
 
Old 12-08-2012, 04:55 AM   #4
Biederony
LQ Newbie
 
Registered: Jun 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Hi! Thank you for your reply!

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 :-)

Thank you very much!
Attached Thumbnails
Click image for larger version

Name:	tmp.jpg
Views:	20
Size:	13.9 KB
ID:	11362  
 
Old 12-08-2012, 09:10 AM   #5
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
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
 
Old 12-09-2012, 11:22 AM   #6
Biederony
LQ Newbie
 
Registered: Jun 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
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?

Thank you!
 
Old 12-09-2012, 11:30 AM   #7
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Virtual interface Routing abakhiet Linux - Networking 20 07-26-2010 05:15 AM
routing over virtual interface noir911 Linux - Server 1 02-23-2009 10:47 AM
Per Interface Gateway Routing Jelloir Linux - Networking 2 11-17-2008 11:12 PM
why lo interface is not in routing table? montyleesam Linux - Networking 1 06-10-2008 01:06 AM
routing traffic from one interface to another a550ee Linux - Networking 0 07-08-2007 03:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration