# connecting two networks



## hamba (Apr 17, 2009)

Hi

I have two networks, both have there own internet connection and I would like to make a connection between the two routers.

This is the idea

```
internet1-(       )
          (router1)-lan1=10.0.5.0/24
internet2-(       )
                 |
                 |=10.0.5.7
internet1-(router2)-lan2=172.16.1.0/24
```

Router2 is plugged in to the network of router1 and can access it like any other client on the network, what I would like to do is get the clients on the 172.16.1.0/24 to talk to the clients on 10.0.5.0/24 and visa versa.
example: I have an Apache server on 10.0.5.2 and I would like to access it from 172.16.1.100

Each network on there own is working perfectly.
All this is done internally, I have both the routers here with me.

Thanks
hamba


----------



## varda (Apr 17, 2009)

If you want to connect two remote offices over the Internet and don't have public IP addreses for all computers/routers then you need to establish kind of VPN connection between them. At least one side should to have real/public IP address routable/accessible from Internet. Then use from another or at both end VPN software which you familiar with. It may be IPSEC, OpenVPN, VTUN, OpenSSH tunnel, many others. Which will create tun device/interface or similar. Set some peer to peer IP tunnel 10.0.0.1 <---> 10.0.0.2 for 1st and 2nd offices and direct routing between peers like:


```
route add 10.0.5.0/24 10.0.0.2 #router1
route add 172.16.1.0/24 10.0.0.1 #router1
[code]

Do you need working exampe of SSH? You can search Google for this by yourself.

If your routers are in LAN, interconnected and router2 has address 10.0.5.7 (as it on your scheme) then you need to set on router1 address from the same subnet, for example 10.0.5.1. In this case router2 will be with router1 in one subnet. Then again set proper routing between subnets. Now router2 knows about 10.0.5.0/24 but router1 don't knows about 172.16.1.0/24. So we need to point router1:

[code]
route add 172.16.1.0/24 10.0.5.7
[code]

That's all.
```


----------



## hamba (Apr 22, 2009)

Hi

Thanks for the reply, I got everything working, well kinda, I had to add static routes to all the 10.0.5.0/24 clients that I want to access from 172.16.1.0/24.

With out the route I get ping messages like this

```
# ping 172.16.1.199
PING 172.16.1.199 (172.16.1.199): 56 data bytes
36 bytes from fire (10.0.5.1): Redirect Host(New addr: 10.0.5.7)
Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
 4  5  00 0054 69c7   0 0000  40  01 4608 10.0.5.2  172.16.1.199

36 bytes from fire (10.0.5.1): Redirect Host(New addr: 10.0.5.7)
Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
 4  5  00 0054 69cb   0 0000  40  01 4604 10.0.5.2  172.16.1.199

36 bytes from fire (10.0.5.1): Redirect Host(New addr: 10.0.5.7)
Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
 4  5  00 0054 69d0   0 0000  40  01 45ff 10.0.5.2  172.16.1.199

36 bytes from fire (10.0.5.1): Redirect Host(New addr: 10.0.5.7)
Vr HL TOS  Len   ID Flg  off TTL Pro  cks      Src      Dst
 4  5  00 0054 69d3   0 0000  40  01 45fc 10.0.5.2  172.16.1.199

^C
--- 172.16.1.199 ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss
```

When I add the route to 10.0.5.2 then I can ping 172.12.1.199 perfectly.


----------

