machines of two subnets communicate through CentOS(with two NICs)

Solution 1:

  • Give machine C an IP address on eth0 in the subnet 192.168.1.0/24, and an IP address on eth0 in the subnet 192.168.2.0/24 (I use .254 for all my routers, but others prefer .1 -- it's a personal choice).
  • Configure machine A to have a default gateway of whatever IP address you put on machine C's eth0, and give machine B the default gateway of the IP you put on machine C's eth1.
  • Make sure that machine C has IP forwarding turned on, and any relevant iptables rules are not going to block the traffic you want to allow through.

And you're away.