Jump to content

Connecting 2 LAN networks [solved]


Dinh Tran
 Share

Recommended Posts

Hi,

 

I have got stuck in this configuration for a while and I really dont know how to make it work. Please help me to solve out this problem.

 

I have the following system:

PC1==========PC2=============PC3=============PC4

eth0 eth1 eth0 eth1 eth0 eth0

x.240.5 x.240.1 x.240.2 x.240.3 x.242.3 x.242.1

 

I could not ping from PC1 and PC2 to PC3 and PC4. So, at the beginning, I tried to run this

PC2============PC3==============PC4

eth1 eth1 eth0 eth0

x.240.2 x.240.3 x.242.3 x.242.1

Using the configuration given on http://www.iwpcs.co.uk/simple_net_setup.html for PC2 and http://www.iwpcs.co.uk/ics.html for PC3, I made it worked. Then I added the PC1, from PC1 I can not ping PC2, PC3 and PC4.

 

From PC1, I ping 240.1 on eth1 of PC2 and then watch the tcpdump on that same eth1. I got a "arp who-has 192.168.240.1 tel 192.168.240.5".

 

Could you help me out please? I wonder if this is the problem of iptables but I am really not sure.

Thanks a lot and have a nice day,

Best regards,

 

Dinh Tran

Edited by Dinh Tran
Link to comment
Share on other sites

Hi,

 

I got the answer from Chris and it worked for me so I post it here for everyone in case that you need.

Thanks a lot Chris,

Best regard,

 

Dinh Tran

 

Hi!

First, do you need to do this, or can you use a hub/switch? (Perhaps you are doing it for the

exercise, in which case, good on you!!)

 

Each side of each PC must be on a different subnet:

PC1 eth0 192.168.1.1

PC2 eth0 192.168.1.2 eth1 192.168.2.2

PC3 eth0 192.168.2.3 eth1 192.168.3.3

PC4 eth0 192.168.3.4

 

Subnet masks should all be 255.255.255.0 in this scenario. If you have an allocated pool of IP

addresses you must use, then you will need to do subnetting - more complicated, but start off simple

to begin with and use the private address range 192.168.x.x ...

 

Each PC then needs to have either a routing protocol running or static routing set up, so that they

know where to find each network.

 

eg (on the command line):

 

#PC1

route add default gw 192.168.1.2 eth0

# As long as there are no other network connections on this PC, that is all you need. This will send

all unknown packets to PC2, which should route them onwards to the correct destination.

 

#PC2

route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.2.3 eth1

#This PC already knows about 192.168.1.x and 192.168.2.x because they are directly connected. We are

telling it about 192.168.3.x, and how to get to it. If you have an Internet connection, you can add

a default gateway using a similar line to PC1 - the interface and address will depend on which

direction the data needs to go.

 

#PC3

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.2.2 eth0

# same comment as PC2

 

#PC4

route add default gw 192.168.3.3 eth0

# same comment as PC1

 

You can view the routing table with route -n

 

It should look something like this on PC1:

 

[root@shower chris]# route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.1.0 0.0.0.0 255.255.255.0 U 10 0 0 eth0

127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo

0.0.0.0 192.168.1.2 0.0.0.0 UG 10 0 0 eth0

 

The first line is the PC1's own interface, 2nd line is the local pseudo interface, 3rd line is the

default gateway. The 3rd line means send any packet that has not matched line 1 or 2 to the device

at 192.168.1.2 through eth0.

 

When set up correctly, PC2 may look like something like this:

 

[root@shower chris]# route -n

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.3.0 192.168.2.3 255.255.255.0 U 10 0 0 eth1

192.168.2.0 0.0.0.0 255.255.255.0 U 10 0 0 eth1

192.168.1.0 0.0.0.0 255.255.255.0 U 10 0 0 eth0

127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo

 

#The default gateway (on PC2) may or may not be needed - if it is connecting to the Internet or

#other networks through PC1 it will be something like:

0.0.0.0 192.168.1.1 0.0.0.0 UG 10 0 0 eth0

#Or if going through PC4:

0.0.0.0 192.168.2.3 0.0.0.0 UG 10 0 0 eth1

# note the address is the next hop - PC3 in this case.

#You will also need a default gateway set up on the other PCs in this case, and set up routing

individually to each subnet on PC 1 & 4...

 

You will need to tell Iptables to allow packet forwarding too with this kind of thing:

 

iptables -A FORWARD -s 192.168.1 -j ACCEPT

needs to be added at the top of the forward chain

 

You also need to put the following command at the beginning of /etc/sysctl.conf

net.ipv4.ip_forward=1

to allow forwarding at all.

 

So what is probably happening at the moment is you have a default gateway set up on PC2 & 3 sending

the packets the wrong way, or no route at all.

 

Hope this makes sense, or at least gives you a clue!

 

Chris

 

PS. I haven't tested it... :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...