0

I have computer A, computer B and computer C. Computer A and B are connected, and computer B and C are connected. How can I get computer A and C to communicate with each other? I'm assuming I need to add some routes to each machines but i'm unsure exactly what they should look like. For the sake of examples lets say computer A is 10.0.1.1 and computer C is 10.0.2.1 and computer B is 10.0.1.2. Don't get them mixed up!

Thank you

3
  • Do you mean, they're connected to each other? or to a switch? Does computer B have two nics? why does C's network need to be different from A and B?
    – l0c0b0x
    Aug 11, 2009 at 16:43
  • 1
    Is this a thought experiment exercise in routing, or are you trying to achieve something simple like have all 3 computers communicate with each other on the same LAN? Aug 11, 2009 at 17:13
  • 1
    Once again, does Computer B have two network interface cards? Are you assuming Ethernet and TCP/IP?
    – kmarsh
    Oct 8, 2009 at 11:41

6 Answers 6

1

You'll need another NIC on computer B with an address on the same network as computer C, so lets say you have that & its ip is 10.0.2.5

lets also assume that these networks are subnetted as class C's /24

make computer A have a default gateway of 10.0.1.2 (computer B)
make computer C have a default gateway of 10.0.2.5 (computer B)

run this on computer B:

 echo 1 > /proc/sys/net/ipv4/ip_forward
 ip route add 10.0.2.0/24 via 10.0.2.5
 ip route add 10.0.1.0/24 via 10.0.1.2
2
  • 3
    Those routes should exist simply by virtue of adding the IP address(es) to the network interfaces.
    – Vatine
    Aug 11, 2009 at 17:46
  • i think it depends on the distro. either way, you can check with the route command to show you whats there in case adding these is redundant Aug 11, 2009 at 18:17
1

change the subnet mask to 255.255.0.0 and connect all the machines to the same switch, no need for any routing

1
  • Good answer. To anyone implementing this, be careful though. It applies in this particular case, given the example IPs, not generally.
    – Lee B
    Oct 8, 2009 at 9:21
1

This could be very simply a matter of merging subnets (by either changing IPs or relaxing the subnet masks), depending on your setup.

Assuming it's not that easy, then basically, you need to do three things for the general case:

  1. Tell computer B to act as a router. That's the "echo 1 > /proc/sys/net/ipv4/ip_forward" that's been mentioned. This just tells the linux kernel to accept packets for other machines, and to send them on to their destination using the machine's routing tables.

  2. Tell A to talk to C through B. Working on A, "ip route add c_ip via b_ip" should do it.

  3. Tell C to talk to A through B. Working on C, "ip route add a_ip via b_ip" should do it.

However, if A and C both use B as their default gateway, then they will (by definition) assume that everything should go through B, so steps 2 and 3 are unnecessary in that case.

0

add a second address to computer b on the same network range as computer c and enable ip routing, this will turn computer b into a router on a stick. no need for a second NIC

0

This question was actually posted by a colleague of mine. Here's the issue, all of our servers have Intel Pro/1000s, and it's cheaper to link those directly together than to buy a switch capable of handling the server-to-server load (tbh, we can't afford such a switch). We have ip_forward set to 1 on all servers. We're using Gentoo with iproute2. Server C is Gentoo with ifconfig. Here's copies of their conf.d/net's, with the server names being the only thing changed:

Server map:

Server A eth1 -> Server B eth1
Server B eth0 -> Server C eth2

Server A:

config_eth1="10.0.2.1 netmask 255.255.255.0"
routes_eth1="add 10.0.2.2 dev eth1
add -net 10.0.1.0/24 dev eth1"

Server B:

config_eth1="10.0.2.2 netmask 255.255.255.0"
routes_eth1="10.0.2.0/24 dev eth1"
config_eth0="10.0.1.1 netmask 255.255.255.0"
routes_eth0="10.0.1.2 dev eth0"

Server C:

config_eth2="10.0.1.2 netmask 255.255.255.0"
routes_eth2=10.0.1.1 dev eth2
10.0.2.0/24 via 10.0.1.2"

Server A has no problem talking with Server B, and server B has no problem talking with Server C, but A and C cannot communicate via B. During a communication attempt, tcpdump shows unanswered arp who-has requests. I've never used Linux as a router before, so my knowledge on the topic is quite limited.

1
  • Have you considered simply connecting A to C as well? Then each machine has a dedicated gigabit link to each other machine, and you don't have to deal with routing or server B becoming a point of failure for A-C communication.
    – mattdm
    Nov 19, 2010 at 4:31
-1

on machine B:

echo 1 > /proc/sys/net/ipv4/ip_forward
1
  • That simply allows machine B to act as a router. Teaching the other machines to USE that router is another matter.
    – Lee B
    Oct 8, 2009 at 9:22

You must log in to answer this question.