How to configure dual homed server in order for both network segments to communicate?

74

There are two problems with this setup:

  1. The hosts on LAN1 know nothing about the LAN2 segment. When you ping a host on LAN1 (let's call it host1) from SRV-02, the packet will be routed through SRV-01 and will reach host1. However, host1 will send the reply to it's default gateway (ISP router) as it doesn't have a specific route to LAN2. (The ISP router will either a) also send it to it's default gateway as it also doesn't know about LAN2, or b) drop the packet as it comes from an unknown source not it's local LAN.)
  2. When trying to reach WAN from LAN2, the packets will be routed through SRV-02 to ISP router where two situations are possible:
    • The router will not NAT translate the packet as the source of the packet (LAN2) is not it's local LAN (this is the more probable situation), or
    • The router will NAT translate the packet and send it to the Internet. However, when the reply comes and the destination is translated back to the LAN2 address, the packet will not be delivered as the ISP router doesn't have a route for that network. The packet will be sent incorrectly to the default gateway (ISP).

These issues could be fixed by adding a static route to LAN2 to ISP router and adding a source NAT configuration for LAN2 on SRV-01. However, that is not possible due to no admin access to the ISP router.

There are two solutions that get around it:

A. Make SRV-01 a full router for LAN1 and LAN2 hosts

  • Add another network adapter to SRV-01 (making it 3 in total)
  • Change the topology as follows:

.

WAN -> ISP router -> LAN1 -> SRV-01 +-> LAN3 (for hosts originally in LAN1)
                                    +-> LAN2 -> SRV-02

Basically, we're making SRV-01 a router for both LAN segments.

  • This will require moving hosts originally in LAN1 to a new subnet LAN3 - let's say we use 10.0.1.0/24
  • The network configuration of SRV-01 will need to be changed as follows:

/etc/network/interfaces:

# LAN1 - to ISP router
auto eth0
iface eth0 inet dhcp
# we can even use dhcp as the IP address is not really important
# - there are no more hosts on LAN1 apart from ISP router and SRV-01

# LAN3 - for hosts originally in LAN1
iface eth1
    address 10.0.1.1
    netmask 255.255.255.0

# LAN2
iface eth2
    address 10.0.2.1
    netmask 255.255.255.0

iptables rules to make WAN access work:

iptables -t nat -A POSTROUTING -o eth0 -s 10.0.1.0/24 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -s 10.0.2.0/24 -j MASQUERADE

Alternatively, if you choose to keep the static IP address on SRV-01 on eth0 the rules could be changed (although MASQUERADE would still work):

iptables -t nat -A POSTROUTING -o eth0 -s 10.0.1.0/24 -j SNAT --to-source 192.168.5.8
iptables -t nat -A POSTROUTING -o eth0 -s 10.0.2.0/24 -j SNAT --to-source 192.168.5.8
  • DHCP will need to be configured on SRV-01 on eth1 (LAN3, for hosts originally on LAN1), and possibly on eth2 (LAN2) as well if required. (In both cases the gateway will be the local address of eth1 or eth2 respectively, but that goes without saying :)

This will make communication possible between LAN3 and LAN2 (via SRV-01 which is the default gateway for both). WAN access will also work from both LAN3 and LAN2 thanks to the double source NAT.

B. Make SRV-01 a DHCP server for LAN1

This approach is not as clean as above but is slightly simpler. It assumes you are able to disable DHCP on ISP router

  • Disable DHCP on ISP router
  • Set up DHCP for LAN1 on SRV-01 and make SRV-01 (192.168.5.8) the default gateway for LAN1
  • Set up source NAT translation for LAN2 on SRV-01 so that the WAN access works from LAN2:

.

iptables -t nat -A POSTROUTING -o eth0 -s 10.0.2.0/24 -d 192.168.5.4 -j SNAT --to-source 192.168.5.8
iptables -t nat -A POSTROUTING -o eth0 -s 10.0.2.0/24 ! -d 192.168.5.0/24 -j SNAT --to-source 192.168.5.8

The first line enables SNAT so that LAN2 hosts can access the ISP router itself and the second line disables SNAT for LAN2-LAN1 access.

Again, this approach is not as clean as the one above as there are two routers in the same subnet (SRV-01, ISP router). When I used this approach myself I noticed my second router (SRV-01 in this scenario) would send ICMP redirects to the ISP router as it would see that the client (host on LAN1) and the upstream router (ISP router) are on the same LAN. This might not be desired as network policies implemented on SRV-01 could be circumvented.

Hope that helps.

Share:
74

Related videos on Youtube

GalaxyGamerYT
Author by

GalaxyGamerYT

Updated on September 18, 2022

Comments

  • GalaxyGamerYT
    GalaxyGamerYT almost 2 years

    I'm trying to get a right click menu to appear by right clicking a button, while still allowing left click to do something else.

    Main.py

    from kivy.config import Config
    Config.set('input', 'mouse', 'mouse,disable_multitouch')
    
    from kivy.app import App
    from kivy.uix.floatlayout import FloatLayout
    from kivy.uix.bubble import Bubble
    
    class MainWidget(FloatLayout):
    
        def onpressed(self, widget, touch):
            if touch.button == 'left':
                print("LEFT")
            elif touch.button == 'right':
                print("RIGHT")
                ccp = CutCopyPaste
                self.add_widget(ccp)
    
    class CutCopyPaste(Bubble):
        pass
    
    class RightClickApp(App):
        pass
    
    if __name__ == "__main__":
        RightClickApp().run()
    

    rightclick.kv

    MainWidget:
    
    <MainWidget>:
        Button:
            text: "A"
            on_touch_down: root.onpressed
    
    <CutCopyPaste>:
        size_hint: (None, None)
        size: (160, 160)
        pos_hint: {'center_x': .5, 'y': .6}
        BubbleButton:
            text: 'Cut'
        BubbleButton:
            text: 'Copy'
        BubbleButton:
            text: 'Paste'
    

    All the ways I've found to do this haven't worked. Please help.

  • g0lem
    g0lem over 8 years
    Thanks for the detailed & educational answer. What if it would be possible with our current topology to: ( a ) Desactivate DHCP on ISP router ( b ) Set SRV-01 to provide DHCP for LAN1 (192.168.5.0/24) & LAN2 (10.0.2.0/24) plus default gateway to 192.168.5.4 (ISP router eth1 - LAN1) ( c ) Set hosts on LAN1 default gateway to 192.168.5.8 (SRV1 eth0) ( d ) Set hots on LAN2 default gateway to 10.0.2.1 (SRV1 eth1) or 192.168.5.8 (SRV1 eth0). Are there routing tweaks missing here, what would be the impact on security & performances?
  • piit79
    piit79 over 8 years
    My pleasure. This approach would work as well - in fact I used it myself with my stupid cable modem that didn't have a static route option. I edited my answer and added this simpler approach - note the SNAT config required for LAN2. If at all possible I would use the cleaner first option though. PS: if my answer was helpful could you perhaps upvote it/mark it as accepted? :) Thanks!
  • g0lem
    g0lem over 8 years
    I'm note sure why use MASQUERADE if keeping DHCP enabled for LAN1 as proposed within solution A (first solution), could you elaborate?
  • GalaxyGamerYT
    GalaxyGamerYT about 2 years
    Thank you. I tried it with the () and it didn't work but what I didn't know was I had to have (*args) in the kv file.