Controlling which Network Card TCP/IP message are sent on

后端 未结 4 1096

The system I\'m currently working on consists of a controller PC running XP with .Net 2 connected to a set of embedded systems. All these components communicate with each ot

4条回答
  •  迷失自我
    2021-01-03 06:14

    If you have two network cards on the machine, then there shouldn't be a problem. Normal IP behaviour should ensure that traffic for your 'private' network (embedded systems in this case) is separate from your public network, without you having to do anything in your code. All that is required is for the two networks to be on different IP subnets, and for your 'public' NIC to be the default.

    Assuming your two NICs are configured as follows:

    NIC A (Public): 192.168.1.10 mask 255.255.255.0
    NIC B (Private): 192.168.5.10 mask 255.255.255.0
    

    The only configuration you need to verify is that NIC A is your default. When you try to send packets to any address in your private network (192.168.50.0 - 192.168.50.255), your IP stack will look in the routing table and see a directly connected network, and forward traffic via the private NIC. Any traffic to the (directly connected) public network will be sent to NIC A, as will traffic to any address for which you do not have a more specific route in your routing table.

    Your routing table (netstat -rn) should look something like this:

    IPv4 Route Table
    ===========================================================================
    Active Routes:
    Network Destination        Netmask          Gateway       Interface  Metric
              0.0.0.0          0.0.0.0      192.168.1.1     192.168.1.10    266 <<--
            127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
            127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
      127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
          169.254.0.0      255.255.0.0         On-link      192.168.1.10    286
      169.254.255.255  255.255.255.255         On-link      192.168.1.10    266
          192.168.1.0    255.255.255.0         On-link      192.168.1.10    266
         192.168.1.10  255.255.255.255         On-link      192.168.1.10    266
        192.168.1.255  255.255.255.255         On-link      192.168.1.10    266
          192.168.5.0    255.255.255.0         On-link      192.168.5.10    266
         192.168.5.10  255.255.255.255         On-link      192.168.5.10    266
        192.168.5.255  255.255.255.255         On-link      192.168.5.10    266
       255.255.255.255  255.255.255.255        On-link      192.168.1.10    276
       255.255.255.255  255.255.255.255        On-link      192.168.5.10    276
    ===========================================================================
    

    There will also be some multicast routes (starting with 224) which have been omitted for brevity. The '<<--' indicates the default route, which should be using the public interface.

提交回复
热议问题