[Help] [Debian] Replying on the same interface, IP config for newbe

Hello all !
Well, after some time of searching, testing, not understanding what i’m doing … i kinda gave up and looking for help ^^
So i’m working with vm and i’m building the main one that i will then duplicate over and over to use as a base.
This is my network :


My issue is on the routing of the vm. You see, i have 2 network, an “admin” one and a “user” one. With classic use, there is no problem, but when i want to access to the admin network from a computer in the user network, i’m having issue.
For example, is i want to ssh on the server from the computer (who is allowed to do so on the router) The network packet are routed from the user to the admin network, reach the vm from the admin interface, but because the vm see the packet from the user network, he reply on the user interface (shortest route). Then, because the router don’t see the reply, he cute the access after a couple a second.

I know almost nothing on ip route, table, rule … and i really need some help to configure the vm in order to reply on the same interface he receive the packet on, but also no mater what ip is assign on the interface (set by DHCP, and i don’t want to have to touch something when i duplicate it)

This is what i have found, and try without success …

ip rule add from AdmInterfaceIP table eth1
ip route add default via AdmInterfaceIP table eth1

I’m very tired so i hop i’m understandable …
Thank for your time and have a nice day

It would help if you would list your router’s main route table:

user@router:~$ip route show

and the routes in the route table you named eth1:

user@router:~$ip route show table eth1

and the address on the router’s interfaces:

user@router:~$ip address show

Because it didn’t work, i have rollback to the previous config, so eth1 table don’t existe.

ip route show
192.168.1.0/24 dev eth0 proto kernel scop link src 192.168.1.42
192.168.20.0/24 dev eth1 proto kernel scop link src 192.168.20.31

ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether REDACTED brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.42/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:feb8:849b/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether REDACTED  brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.31/24 brd 192.168.20.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:feb8:7209/64 scope link
       valid_lft forever preferred_lft forever

Thank’s

Presumably you were looking at this one: https://unix.stackexchange.com/questions/4420/reply-on-same-interface-as-incoming

In Linux unlike on some other systems, there’s support for multiple routing tables.
There’s also what are called “rules” that can help determine which table to use.

First, you need a second routing table (can be either a number or an alias).

ip route add default via 192.168.20.1 table 1234

Then, you can add a rule that says to use that table and route with the packets that match that rule

ip rule add from 192.168.20.0/24 lookup 1234

Then you need ip route flush cache most likely.

Here’s a book with a more complicated/complete example:
http://lartc.org/lartc.html#LARTC.RPDB.MULTIPLE-LINKS

So, what does this do ?
For what i understand, all trafic from the 20.0/24 net will have there default route to the routeur. but does that mean that all traffic from this network will go through the router ? and what about, witch is my actual issue, the trafic witch is not from the 20.0/24 network but just go through it ?

from x means traffic consisting of packets with source ip x

You will have 2 default routes in 2 routing tables, traffic from …20.0/24 will use the one in table 1234, making it go through the router. Other traffic will go as usual

that what i thought, but i don’t have issue with packet from 20.0/24 … but packet from 1.0/24 coming on the 20.0/24 interface

Add another table with another default gateway and another rule