Results 1 to 17 of 17

Thread: TCP connect to addresses on different subnets

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    10

    TCP connect to addresses on different subnets

    Hello.
    I currently have a vb.net application that communicates via modbusTCP.
    I am able to communicate with devices on my local network, but I am unable to communicate with devices on a different subnet.

    For example, if I configure my computer’s network interface with IP address 192.168.1.2, gateway 192.168.1.1, subnet 255.255.255.0, I am able to establish TCP connections to all devices on the 192.168.1.x subnet.

    How would I establish connections on a different subset? For example, a device with IP address 192.168.2.1.

    Does this require another piece of hardware like a router, or can this be accomplished purely with code using VB.net?

    Any insight would be appreciated

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,367

    Re: TCP connect to addresses on different subnets

    As described, this is outside of a VB.NET question.

    That being said, it completely depends on the network setup. It could be as simple as "widening" your subnet mask to something like 255.255.0.0, which means it will treat any address of 192.168.x.x as a local address not needing to route through your default gateway.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    10

    Re: TCP connect to addresses on different subnets

    Thanks for the reply and I apologize if this isn’t entirely a vb.net question.

  4. #4
    Frenzied Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,119

    Re: TCP connect to addresses on different subnets

    You can add to your PC network adaptor another address on the 192.168.2.x (with a subnet mask of 255.255.255.0). Then your PC will be able to access 192.168.1.x and 192.168.2.x networks.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,746

    Re: TCP connect to addresses on different subnets

    Quote Originally Posted by RadioscoutNews View Post
    Hello.
    I currently have a vb.net application that communicates via modbusTCP.
    I am able to communicate with devices on my local network, but I am unable to communicate with devices on a different subnet.

    For example, if I configure my computer’s network interface with IP address 192.168.1.2, gateway 192.168.1.1, subnet 255.255.255.0, I am able to establish TCP connections to all devices on the 192.168.1.x subnet.

    How would I establish connections on a different subset? For example, a device with IP address 192.168.2.1.

    Does this require another piece of hardware like a router, or can this be accomplished purely with code using VB.net?

    Any insight would be appreciated
    Might be easier to understand what your ultimate aim is on this one...

    Are you currently on a network with multiple subnets? If so the router etc. might already be in place and things might just work.

    Are you looking at taking an existing network and subnetting it into two (or more)? If so is there a reason for doing this?

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    10

    Re: TCP connect to addresses on different subnets

    Thanks for the reply.

    I apologize for my limited knowledge on networking. I have someone telling me they are unable to connect to controllers that are on a different subnet than the one their PC is on. They are asking me for a software solution to this issue. In my understanding, the PC will only be able to connect to devices it has a path or “rout” to. Aside from editing the network parameters of their PC’s network interface card, I don’t see anyway for the computer to be visible to controllers on a different subnet.

    I am unaware of their current network topology, so maybe we can speak in general terms. If a computer on one subnet wants to be visible to controllers on a different subnet, will this always require a router between to two subnets to join them? Assuming we do not know what ip address and subnet configuration they will be using, because it could be anything
    Last edited by RadioscoutNews; Jul 20th, 2024 at 09:54 AM.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    10

    Re: TCP connect to addresses on different subnets

    Are you saying I can assign two IP addresses to one network interface card?

  8. #8
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,367

    Re: TCP connect to addresses on different subnets

    Quote Originally Posted by RadioscoutNews View Post
    Thanks for the reply.

    I apologize for my limited knowledge on networking. I have someone telling me they are unable to connect to controllers that are on a different subnet than the one their PC is on. They are asking me for a software solution to this issue. In my understanding, the PC will only be able to connect to devices it has a path or “rout” to. Aside from editing the network parameters of their PC’s network interface card, I don’t see anyway for the computer to be visible to controllers on a different subnet.

    I am unaware of their current network topology, so maybe we can speak in general terms. If a computer on one subnet wants to be visible to controllers on a different subnet, will this always require a router between to two subnets to join them? Assuming we do not know what ip address and subnet configuration they will be using, because it could be anything
    There's no software solution to resolve a lack of proper network connectivity or configuration.

    There's also really no generic suggestions that can be given for a completely unknown network configuration to make this work.

    Your original post made it sound like this was all happening on *your* local LAN. Now it sounds like you are simply providing software for clients, and this is all happening on *their* LAN. Big difference there.

    Bottom line - the client would need to have their network properly configured (both from a hardware standpoint and a PC configuration standpoint) for this to work. You're already removed from the situation, and we're obviously further removed, so we know nothing about any specific details. So, good luck.

  9. #9
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,536

    Re: TCP connect to addresses on different subnets

    > If a computer on one subnet wants to be visible to controllers on a different subnet, will this always require a router between to two subnets to join them?

    Yes. The "router" can be a multi-homed machine though i.e. just a PC with two network cards.

    Also at this exact access point you might get NAT/firewall involved i.e. network A can address network B freely while network B cannot see anything inside network A (i.e. network A is protected).

    cheers,
    </wqw>

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    10

    Re: TCP connect to addresses on different subnets

    Understood.
    I will check back when I have a more detailed explication of the problem. I appreciate you taking the time to reply.

  11. #11
    Frenzied Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,119

    Re: TCP connect to addresses on different subnets

    Quote Originally Posted by RadioscoutNews View Post
    Are you saying I can assign two IP addresses to one network interface card?
    Yes. But note that you can only have 1 gateway address.

    Code:
    Ethernet adapter Local Area Connection:
    
       Connection-specific DNS Suffix  . :
       IPv4 Address. . . . . . . . . . . : 192.168.1.20
       Subnet Mask . . . . . . . . . . . : 255.255.255.0
       IPv4 Address. . . . . . . . . . . : 192.168.7.20
       Subnet Mask . . . . . . . . . . . : 255.255.255.0
       Default Gateway . . . . . . . . . : 192.168.7.1
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,367

    Re: TCP connect to addresses on different subnets

    Quote Originally Posted by wqweto View Post
    > If a computer on one subnet wants to be visible to controllers on a different subnet, will this always require a router between to two subnets to join them?

    Yes. The "router" can be a multi-homed machine though i.e. just a PC with two network cards.
    I would just add the caveat that having one device with an IP address of 192.168.1.10 and another device with an IP address of 192.168.2.10 doesn't guarantee that they are on a different subnet. There could be one "large" subnet that encompasses the entire 192.168.x.x range. In that case, the correct subnet mask would be 255.255.0.0. From a 192.168.1.x device, having an incorrect subnet mask of 255.255.255.0 would presumably prevent proper access to anything in the 192.168.Not1.x range, even though the configuration of the network gear itself would allow it if the mask were correct.

  13. #13

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    10

    Re: TCP connect to addresses on different subnets

    Okay. Thank you.
    After everyone’s replies and my own investigation over the last day or two, it appears that this is a networking solution and not a programming one.

    I’m thinking the best solution is to widen the subnet of the computer’s network interface card to include all possible IP addresses of the controllers (devices) on the network.
    Alternative, another piece of hardware like a router will be needed.

    When it comes down to it, the PC will not be able to communicate with anything on the network not visible to it.

    Thanks again for your reply

  14. #14

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    10

    Re: TCP connect to addresses on different subnets

    Yes, I’m thinking expanding the subnet mask will remedy the issue. Thank you

  15. #15
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,367

    Re: TCP connect to addresses on different subnets

    This isn't a guarantee, but if these are all devices that are located in a single physical location, then they could be on the same subnet. If they are in different physical locations, then they are almost certainly on different subnets and would need some sort of routing device in place to allow communication.

  16. #16

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    10

    Re: TCP connect to addresses on different subnets

    They are in the same physical location (per se), but they are spread over many acres. I believe the subnetting in this situation is being done to separate controllers into different groups, or possibly there are more than 255 devices that require use of a second octet in the IP address range to begin adding more devices.

  17. #17
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,536

    Re: TCP connect to addresses on different subnets

    Local segments of ethernet LAN have some length limitation -- ~100 m for the Cat. 5 cables so most probably the topology you are dealing with involves multiple segments connected over SFP (fiber).

    A single physical segment can be further subnetted using IP/mask settings but this can be easily circumvented by anyone on the physical segment widening the mask or just adding additional IP addresses on the machine (on the same network adapter) so this cannot be any security feature.

    When I have to connect external devices (printers, etc.) over ethernet these usually come preset with 192.168.0.x addresses while our LAN uses 172.x.y.z so I just add an additional IP address in 192.168.0.x/24 on my machine so that I can simultaneously stay on local LAN and connect to the device from my machine only. No one else (not having 192.168.0.x/24) can access the device which is convenient.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width