简体   繁体   中英

Perform Connect on specific NIC in a two NIC Linux system

Business case:

This is year 2015, and I am using Linux kernel 3.17. My ARM Linux has two NIC, eth0 and eth1. eth0 is for configuration purpose locally for a person next to it, and eth1 is for configuration purpose from remote. So they are basically same function, except eth0 has a person to plug in the cable in the field.

Local PC ------ [eth0 My ARM Linux Computer eth1] ------ Remote PC

Using eth0, the PC software can configure eth1 IP address and port for configuration. To do that, my eth0 has a preset IP address (192.168.1.2) so the PC software can easily find it. The ARM Linux (3.17) application needs to listen on eth0 port A, and eth1 Port B (if configured), and once connected, will respond, but never initiate any activity (not even ping).

There is no connection between local PC and remote PC. They are not supposed to be bridged, or networked.

Question 1:

If eth1 is configured with same IP as eth0, will my application still able to listen on both NIC ports, and correctly respond? I will have two independent threads (maybe same function, but different parameters) to listen on the two NIC ports.

This is why I ask whether I can specify the NIC when connect, and respond, because now you can see they could have same IP address. Ideally, the OS knows where is the connect request is from, so it should know which way to reply to, even if the two NIC have same IP as long as they have different Ethernet address. But, does C++11 or Berkeley model allow me to specify eth0 or eth1 when I listen and reply?

Now, the local PC and remote PC could have same IP address as well (but different from the ARM Linux). But imagine I have two ARM Linux computers, then this configuration is completely ok. But unfortunately I only have one embedded system and one OS with eth0 and eth1.

Question 2:

If answer to question 1 is no, then can they have same subnet mask? Also, can the local PC and remote PC have same IP address?

Assumption

Setting routing table, is a solution, if works. I wanted to know whether it is feasible and also whether it is recommended not to do it.

Also, this is Linux. Similar questions were asked long time ago for Windows, and Windows XP says (no) and I am using Linux 3.17 and I have same IP address so things are different from similar questions.

At the system level, you can configure a bridge on the mediating box. This can have the same IP address on both sides of the bridge and can be locked down using iptables to only respond to particular TCP/UDP ports.

You can't have systems on both sides of the bridge with the same IP address (ie the local pc and remote pc can't have the same IP address). You can use ebtables to limit the access on either side of the bridge to the IP address of the bridge itself, which means that the local pc can only talk to the mediating box and the remote pc can only talk to the mediating box.

This is based on never expecting the local and remote pcs to talk to each other.

It's mostly a sys-adminny solution, though, there's not really an API that you could use as a developer to accomplish the same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM