how to connect 3 servers under two private networks

server2 (10.0.0.2) <--> **server1** <--> server3 (10.0.1.3)

output in server1.

netstat -rn

Kernel IP routing table Destination     Gateway         Genmask        Flags   MSS Window  irtt Iface
10.0.0.0        0.0.0.0         255.255.255.0   U         0 0          0 enp131s0f1
10.0.1.0        0.0.0.0         255.255.255.0   U         0 0          0 enp131s0f0

ip route

10.0.0.0/24 dev enp131s0f1 proto kernel scope link src 10.0.0.1 metric 102
10.0.1.0/24 dev enp131s0f0 proto kernel scope link src 10.0.1.4 metric 103

I have 3 servers. Server 2 and server 3 are connected to server 1 via 10G ethernet cables.

Now, server 2 and server 3 can communicate with the server 1. But, I am not sure how to let server 3 and server 2 communicate with each other directly through server 1. I am not able to connect them with more cables. I guess I can use a bridge to accomplish this. But, I have not made it work yet.


server2 and server3 are different IP subnets, so a bridge is not (normally) what you would use there. You would want server1 to act as a router, not a bridge.

It looks like server1 already has the IP 10.0.0.1 on server2's net and 10.0.1.4 on server3's net.

First, turn on IP forwarding on server1:

sysctl -w net.ipv4.ip_forward=1

Next, you need routing. If server1 is the default gateway for both server2 and server3 already, then you're done. If it isn't, you'll need to setup routing somehow. Static routes are the simplest:

On server2:

ip route add 10.0.1.0/24 via 10.0.0.1 dev XXX

On server3:

ip route add 10.0.0.0/24 via 10.0.1.4 dev YYY

Where XXX and YYY are the appropriate ethernet interface names on those servers.