I have found the problem is related to the local routing table.
When you add an ip to a device, the kernel adds automatically an entry to the local routing table. You can see it with the command:
>ip route show type local table local
I tried to delete the entries for both, client and server,
>ip route del table local local <ip>
but when the routes are deleted, I cannot open a socket from the client.
Even, if I delete only the server's entry in that table, I see the message going outbox, to the gw I indicated in the main routing table. However, the gw cannot access the server side, because the server machine doesn't resolve the ARP request from the gw.
I think using the rules related with the routing policy database (RPDB) http://linux-ip.net/html/routing-selection.html,
I could get something. As I know, there are by default, this tables:
# ip rule show
0: from all lookup local
32766: from all lookup main
32767: from all lookup 253
The problem is that the rule 0 (local table) has the higher priority. I was thinking about deleting the entries in the local table, and to create two tables,
1. out_table (higher priority) a pseudo main table where I say to go thru the gw for destination the server or the client
2. in_table: a pseudo local table where I say that those IPs are mine, to handle those packets, with certain rules...
This way, the rules should be:
1: from <rule> lookup out_table
2: from <rule> lookup in_table
Do you see it possible? Could anybody suggest some idea?