Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm having some problems with routing with the following:

I have a server with 2 interfaces. It has 1-1 alias contains the same subnet. the 2 interface is connected to 2 switch, which are separated from each other. Infrastructure:

Eth0      192.168.16.2/20
Eth0:eth0 192.168.1.222/20
Eth1      192.168.32.3/20
Eth1:eth1 192.168.1.223/20

I have a PC which has the IP address: 192.168.1.3/24

The problem is the next:

  • If PC is on subnet 1, I can ping it.
  • If PC is on subnet 2, I can't ping it.

traceroute shows the route is across 192.168.1.222

ping -I 192.168.1.223 192.168.1.3 is not working on subnet 2.

arp entries show the MAC address belonging to the correct interface (eth1 on subnet 2)

How can I force the server to look on both interface same ranged subnet for specific IP?

It searches only in the first subnet.

The routing table has these 2 entries:

192.168.0.0/20 dev eth0 proto kernel scope link src 192.168.1.222
192.168.0.0/20 dev eth1 proto kernel scope link src 192.168.1.223

Update1:

So no way to linux kernel determine which interface has 192.168.1.3 ip. We solved the problem with connect the separated subnet switch with each other, but traffic goes now out on ETH0.

The final way will be reconfig pc ip adresses during test to fit to the subnet ip range.

Thanks to the answers.

share|improve this question
2  
Having two interfaces in the same subnet mean that unless you have separate routing tables, all traffic on that subnet will take the first matching entry. That would be 192.168.0.0/20 dev eth0 proto kernel scope link src 192.168.1.222. Search around here for "policy based routing", you will need to create multiple routing tables, each one with its own source address. A google search for the same terms(maybe include linux) will get you all the info you need. –  NickW Nov 4 '13 at 12:13
    
Can u show an example for that situation? I checked rt_talbel, policy based routing, but not get exactly what i need. –  Coolpet Nov 4 '13 at 13:03
    
Have a look at this response I typed up earlier: serverfault.com/questions/550516/… then make slight changes, table 1 for eth0, table 2 for eth1, and specify the source address in each one. –  NickW Nov 4 '13 at 13:07

2 Answers 2

We had the exact same configuration with different IP addresses. One host had an IP address configured on multiple interfaces, like:

10.0.0.0/24 dev eth1  proto kernel  scope link  src 10.0.0.10 
10.0.0.0/24 dev eth2  proto kernel  scope link  src 10.0.0.10 
10.0.0.0/24 dev eth3  proto kernel  scope link  src 10.0.0.10

I just had to add ip routes like:

> ip route add 10.0.0.123 dev eth3

So I had entries like:

> ip route show
...
10.0.0.123 dev eth3  scope link 
10.0.0.101 dev eth2  scope link 
10.0.0.136 dev eth1  scope link
...

After those, it should work. @nickw suggesting the policy based rules might also be right, but I find this approach a bit easier.


Note: IMHO this is a really bad practice, we ended up having a lot of trouble with it. Also AFAIK you will not be able to access the host on the other interface without changing ip route or rule entries, so you have to reconfigure the tables if you move the machine to the different (physical) network.

share|improve this answer

The problem is the next:

If PC is on subnet 1, I can ping it. If PC is on subnet 2, I can't ping it.

How can I force the server to look on both interface same ranged subnet for specific IP?

This is not possible. Not at the kernel level.

You cannot have two routes on a routing table and expect that the kernel will try both when you do not specify anything else, like which interface or source IP address to use.

The basic rule of thumb is this: If an host is not reachable through an interface, DO NOT add a route for this host on that interface. Hosts are not supposed to be "smart" or magically guess which interface to use. If there is a route, the kernel always selects that route, even if it does not work.

You can have multiple routing tables depending on the source IP address, an application-specified output interface or a mark, or a tos, or many other parameters, and even multiple network namespaces, but at the end, if you only do a simple "ping 192.168.1.3", the kernel will only pick a single route in one of your routing table and it will use it.

Even if Linux has the technical possibility to round-robin which route to use, it will do so for every packet. If you use that, you will have a 50% packet loss to reach your host.


If you need this somewhat broken setup to work, either:

  • Bridge the two network, on your servers or on your switchs, even if it is only on the point of view of your server.
  • Ensure that your 192.168.1.3 host can be seen from both networks
  • at layer 2, join your two interfaces and duplicate everything that get sent to eth0 to eth1. This is horrible, yes.
  • Stop moving 192.168.1.3 from your two subnets.
  • Run a routing protocol on your server and on 192.168.1.3, so that routing tables are automatically adjusted depending on where 192.168.1.3 is.
share|improve this answer

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.