Development User Help

Custom routing based on destination IP and/or port

I have a Linux server with multiple VLANs configured on it. They are like:

  • VLAN1 – – GW: eno1
  • VLAN2 – – GW: eno2
  • VLAN3 – – GW: eno3
  • VLAN4 – – GW: eno4

And each network interface has an IP from the VLAN/network shown above.

I am trying to connect to VLAN4 over the Internet and the network port has a NAT to a public IP address, for example, -> VLAN4 IP address (eno4 – and it is listening on port 80.
The server is listening on port 22 only on the interface belonging to VLAN1 – eno1.

I want to be able to access TCP port 80 over the public and private IP address on eno4 from my PC which also has a private IP and at the same time to be able to connect over SSH to my server over eno1 which is not exposed to the Internet.

So my understanding is that in order to make the public IP address of the server reachable from outside, I need to define a default GW via eno4. In order to be able to connect to the SSH, I need to make a custom routing over the VLAN1 gateway but then I won’t be able to reach any more port 80 on eno4 because my traffic will be re-routed over the custom routing over eno1. So my setup is something like that.

ip r add default via dev eno4
ip r add via dev eno1

How can I make the routing table more specific and when I try to reach eno1 over the private IP to use GW1 and when I try to reach the private IP of eno4 from my PC the traffic to be routed over GW4?

Leave a Reply

Your email address will not be published. Required fields are marked *