Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

folks. Firstly, I really have done a lot of searching, but still couldn't find a problem which was exactly the same as mine, and I have tried some of their answers, but didn't work. Finally, I put my problem here.

I have a machine C with two NICs, namely eth0 and eth1, with CentOS 4.9 installed on it. Also I have a machine A connecting to C through eth0 and a machine B connecting to C through eth1. Now I want machine A to be in a subnet(e.g. 192.168.1.0/24) and machine B to be in another subnet(e.g. 192.168.2.0/24) and they could communicate with each other.

For example, here is a scenario

A:192.168.1.100 B:192.168.2.100

In machine A, the command ping 192.168.2.100 could return correctly, and vice vesa.

Above is my demand. But I don't know how to do it. Any suggestions will be appreciated. Hope make myself clear.

Thanks in advance.

Jfhu

share|improve this question
    
Can you show the output of cat /etc/sysconfig/network-scripts/ifcfg-eth0and cat /etc/sysconfig/network-scripts/ifcfg-eth1 ? What are you trying to accomplish? –  ewwhite Jul 29 '11 at 12:50

1 Answer 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.

share|improve this answer
    
I'd further add that instead of setting the default gateway, you could add a static route for 192.168.2.0/24 on A set to go through C, and the .1.0/24 on B going through C. But that only matters if you also have Internet connectivity through some host. If this is just a local network it doesn't matter. –  Michael Lowman Jul 29 '11 at 13:03
    
I took a literal interpretation of the question, mostly to keep the OP's head from exploding. –  womble Jul 29 '11 at 13:11
    
Thanks all for your help. To womble, could you please give me the iptables rules I should add in the case of my example in the answer. –  machinarium Jul 29 '11 at 13:52
    
Why not give it a go yourself, and if you get stuck, ask a new question on Server Fault? You'll learn more if you try it yourself first. –  womble Jul 29 '11 at 14:05
    
To womble, thanks, Now I haven't add any rules, but it works. –  machinarium Aug 2 '11 at 4:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.