TCP Sessions – Impact of IP Changes on Networking

hijacknetcatnetworkingnixtcpip

What happens to a TCP session when the IP of a client changes?

I did a simple test of having netcat listen on a port, and connecting to that port from a client machine. I then changed the IP of the client while that nc session was open and sent some data, no data was received by server after changing the IP.

  1. I know they are different layers,
    but does TCP use IPs for part of how
    it distinguishes sessions?
  2. Does my example not work because of
    how the application handles it, or
    is this not working because of
    something happening at
    TCP/IP/Ethernet layers?
  3. Does this depend on the OS implementation? ( I am most interested in Linux at the moment)

Best Answer

My understanding is that a TCP socket consists of the IP+port number, so changing the IP breaks that connection. nc has no way of knowing the IP changed, so it continues sending data to the original IP until the session times out.

See RFC 793 (Transmission Control Protocol), specifically section 2.7:

2.7. Connection Establishment and Clearing

To identify the separate data streams that a TCP may handle, the TCP provides a port identifier. Since port identifiers are selected independently by each TCP they might not be unique. To provide for unique addresses within each TCP, we concatenate an internet address identifying the TCP with a port identifier to create a socket which will be unique throughout all networks connected together.

I suggest using Wireshark or another packet sniffer to watch the traffic for yourself and see it in action.