can two nic have same subnet but different network?

5,160

If you're talking about two (physically) separated networks with both the same subnet, and the same subnet mask, Eth0 has the 192.168.1.0/24 subnet, and Eth1 has the same 192.168.1.0/24 subnet, even though the two networks are physically seperated:

Yes. This will cause you issues, your linux computer will not necessarily know which interface to use for requests on the 192.168.1.0 subnet, in fact, it will probably assume that both interfaces are connected to the same physical network, prioritize one interface, and ignore the other.

The easiest work around is to change the third digit of the IP address of either eth1 or eth0 to ensure they are on different subnets, lest the linux box not know which interface to use to send packets.

Share:
5,160

Related videos on Youtube

Splash
Author by

Splash

1 year old Java programmer

Updated on September 18, 2022

Comments

  • Splash
    Splash over 1 year

    Business case:

    A computer has eth0 and eth1 and eth0 address is 192.168.1.2 (static). The eth0 is used by a configuration software to configure the address of eth1 in the field. eth0 is only for this purpose.

          PC ----  [eth0 Linux Computer  eth1]  ----- server  
    

    eth1 is to connect to a server and the customer will get data from this computer to store on the server. The PC shall not reach the server in any way. The Linux computer should NOT redeliver any packets from PC to the server, or from the server to the PC. The Linux computer is not a bridge.

    Question 1:

    If the eht1 IP assigned in the field is 192.168.1.100 and on same subnet with eth0, will it cause a problem? If the application software listens on the 192.168.1.2, and connected by PC 192.168.1.3, and if the application software use this connection to send back to PC, will the OS know which NIC it should use?

    If the field people set the eth1 to be 192.168.1.2, which is same IP address, will Linux application listen on eth0 and still respond correctly to PC?

    Or, should I restrict field people to assign eth1 to have same subnet?

    Question 2:

    Since it is believed that Question 1 is possible. Now can eth0 and eth1 have same IP address?

    The plan is for the Linux PC to listen on TCP port only, and only respond to connections from PC or server. So once connected, the software knows which NIC to go through to reply.

    Further, can PC and Server have same IP as well, if the Linux PC never initiate any IP activity, or even Ping.

  • Splash
    Splash over 8 years
    I am not trying to achieve a bridge. The two NIC are isolated
  • Splash
    Splash over 8 years
    Thanks. This is the direction of answers I was hoping for. So you do think it has problems which is what I think. The underlying layer may be able to send Ethernet packets to different NIC but the official network layer may not handle that.
  • IceMage
    IceMage over 8 years
    It all depends on the capabilities of the exact version of linux you are using. If your application requirements force you to leave both eth0 and eth1 on the same subnet, you're going to want to look into manually setting up your routing table, giving routes different weights, and a number of different problems that all stem from doing something that goes against best practice (doable, but unsupported, and you may find yourself on your own a lot).
  • IceMage
    IceMage over 8 years
    I don't know what kind of issues you're going to create for sharing the same IP address, but I would imagine that the TCP/IP stack of the OS will throw an error if you have two adapters with the same IP address. Remember, IP is layer 3, and Ethernet is layer 2. Your OS is going to complain about a lot of different issues if two layer 2 adapters have the same layer 3 address. Unless you're doing some kind of (advanced) teaming, do not share the IP addresses.