6

Just a curiosity, if I have a NIC that is associated with more than one IP addresses. Does port ties to an IP or NIC?

For example if I have a NIC that has two IPs, 1) 192.168.8.18 and 2) 10.1.11.240

If I open port 1234 on 192.168.8.18, can I also open port 1234 on 10.1.11.240 or that will be prohibited since the NIC already had port 1234.

Thanks

beyonddc
  • 163
  • 1
  • 4
  • 4
    The short answer is that yes you can do that, provided that you explicitly bind the socket you open to one of the two IPs rather than using the typical default which is to bind to all local IPs on the host. This SE question has a much more detailed answer which should help : http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t – Jeremy Gibbons Jun 06 '16 at 21:31

3 Answers3

7

When you open a port, bound to an IP address, it is called a socket. Then, if you have multiple IP addresses, on each of them, you can open ports, always if hardware permits.

Regarding your question, these 2 connections can be established simultaneously. You also can have one service running on 192.168.8.18 and another on 10.1.11.240, also using the same port.

192.168.8.18:1234
10.1.11.240:1234

If you read more info about OSI model, you can check that "port" relies on L4 (transport layer), and NICs exist between L2-L3.

Ron Maupin
  • 98,218
  • 26
  • 115
  • 191
Orlando Gaetano
  • 2,105
  • 11
  • 12
0

Ip sockets bind to a combination of IP version, IP address, port number and transport protocol (some operating systems may also allow sockets for non-IP protocols, I will not go into those there). Whether those IP addresses are associated with the same NIC or not is irrelevent.

So yes you can bind a seperate socket (either from the same or different applications) to the same port on different addresses on the same interface. This is very common on web servers.

Note1: if you bind a socket to 0.0.0.0 it will accept connections on ayn local IPv4 address and (while this socket exists) you will not be able to bind to the port on individual IPv4 IPs (at least not without extra socket options).

Note2: If you bind a socket to :: it will accept connections on any local IPv6 address. Depending on OS, configuration and socket options it may also accept connections on any local IPv4 address.

Peter Green
  • 12,935
  • 2
  • 20
  • 46
-1

A Network Interface Card ( NIC ) consists of a port ( Hardware port ) and are bind with unique MAC address ( which could be changed under special circumstances eg visualization ). Port is just a cabling device. A NIC card have a port embedded in it.Interface = NIC ( port + other component ).

We can assign multiple ip address on a interface. There is only one primary address and other address bind to that interface are secondary addresses.Secondary IP address could also be advertised in routing protocols or could be used as gateways.

Word "Port" is also used in software where it identify specific process or type of service.Software port number could be bind to any of reachable IP address.

  • Ports bind to transport protocols (TCP and UDP), not IP addresses. Ports are layer-4 addresses for TCP and UDP. Some transport protocols don't have addresses or ports. It really has nothing to do with the IP address. – Ron Maupin Jun 07 '16 at 01:58