1

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

machinarium
  • 203
  • 1
  • 2
  • 6
  • Can you show the output of `cat /etc/sysconfig/network-scripts/ifcfg-eth0`and `cat /etc/sysconfig/network-scripts/ifcfg-eth1` ? What are you trying to accomplish? – ewwhite Jul 29 '11 at 12:50

1 Answers1

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.

womble
  • 96,255
  • 29
  • 175
  • 230
  • 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 02 '11 at 04:06
  • So sorry for reporting wrong results. Actually it doesn't work. Only machine C could ping machine A, and I have added one rule: iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE. It seems like all packets will go to the eth0, not eth1. I have not much knowledge about iptables. So any one guide me some tutorials? – machinarium Aug 02 '11 at 08:34
  • Questions go in questions, not comments. Protip, though: I didn't mention using NAT in my answer, because it is not required. Don't use it. – womble Aug 02 '11 at 09:16
  • Sorry for question nesting. I have read the manual of iptables command roughly. It seems to me that the iptables -t filter -A FORWARD -i eth0 -o eth1 -j ACCEPT should works default, however it didn't. So I still couldn't get machine A,B ping each other normally. Any specific instruction? Sorry for my stupidity – machinarium Aug 02 '11 at 12:24
  • Questions go in questions, not comments. – womble Aug 02 '11 at 22:14