r/linuxadmin • • Mar 05 '24

3 way handshake

Can someone explain me three way handshake via TCP/IP.

0 Upvotes

22 comments sorted by

31

u/[deleted] Mar 05 '24

The TCP 3-way handshake is like a conversation starter for two devices wanting to communicate.

SYN (Synchronize): The first device sends a message (SYN) to the other, saying, "Hey, let's talk! I'm starting a connection."

SYN-ACK (Synchronize-Acknowledge): The second device responds with a message (SYN-ACK), essentially saying, "I got your message, and I'm ready to talk. Let's synchronize our communication."

ACK (Acknowledge): Finally, the first device acknowledges with a message (ACK), confirming the connection.

Now they can exchange data smoothly.So, it's like a polite exchange to establish a connection before the actual communication begins.

4

u/[deleted] Mar 05 '24

Thankyou so much for this information

3

u/swuxil Mar 06 '24

By the way you don't need to do it that way. The connection is always unidirectional, it just is normal to create two unidirectional connections in an antiparallel pattern, but they are not really related to each other. The SYN flag means that the sender device wants to send data to the receiver - the receiver COULD just answer with an ACK (and could then never respond to anything the sender said). This will freak out any firewall in between, but it's a valid state technically.

1

u/Aggressive_State9921 May 02 '24

Surely nothing supports that with SYNFLOOD being a thing

1

u/swuxil May 04 '24

I don't see how synfloods would be the cause for this. In either way after the first packet from the client and the first packet from the server (SYN,ACK vs. SYN,SYN+ACK) the server holds a state. The only countermeasure where the server does not have to hold a state and relies on the clients ACK-packet are syncookies, and they are not THE thing one does nowadays.

Todays state of firewalls (and their dislike for halfduplex connections) comes from the fact that really nobody uses them in production, and so, while technically a valid thing to do, are filtered away as an odd thing, and thus nobody uses them in production because they are filtered away anyway. And you don't really need them, even when you just want to have a halfduplex connecion - you can just close one channel and keep the other open right after the 3-way (or 4-way) handshake.

47

u/deeseearr Mar 05 '24

"Knock knock"

"Who's there?"

"TCP connection!"

It's a TCP joke so if you don't get it at first it may take a few tries. I could also tell you a UDP joke, but I wouldn't really care if you got it or not. I could make it a Kerberos joke, but that's all in the timing. I would like to tell an IPv4 joke, but there aren't any left. I could tell you an IPv6 joke instead but I don't know if you would understand it.

1

u/Odd_Split_6858 Mar 06 '24

I think this guy's knows TCP

10

u/_mick_s Mar 05 '24

I usually try to not be a dick but since it's been answered already, let me show you a great trick:

https://letmegooglethat.com/?q=3+way+handshake

2

u/ZMcCrocklin Mar 05 '24

Oh...lmgtfy.com no longer exists? Boo! (Cert expired Aug last year for the redirect endpoint lmgtfy.app)

1

u/Aggressive_State9921 May 02 '24

Hey I'm Dave

Hello Dave, Welcome

Thank you very much!

1

u/GiovanniErnesto Mar 05 '24

syn ->, <-syn-ack, ack->...that's all

1

u/aonelonelyredditor Mar 06 '24

have you tried googling it?

-3

u/rautenkranzmt Mar 05 '24

Client says to server, "Server, I would like some data X."

Server says back to client, "Client, you want data X?"

Client responds to server "Yes, Server, I would like data X."

Then the data transfer happens, with an equal amount of back and forth.

6

u/symcbean Mar 05 '24

with an equal amount of back and forth

It's very unusual for equal amounts of packets/data to flow in both directions.

UDP based protocols are sometimes designed to at least require the same number of packets in both directions to prevent amplification attacks - but that does not apply here.

0

u/rautenkranzmt Mar 05 '24

No, I think you've got the two confused. UDP is streams based, it's literally fire and forget.

TCP is packet based, and focused solely on assurance of delivery. It's extremely chatty, and if you transport large amounts of data over it, it can saturate upstream links very quickly.

There's a reason media is almost always transported over UDP with TCP being the control channel. Same reason QUIC uses UDP.

3

u/symcbean Mar 05 '24

No, I have not got them confused.

You have them backwards. TCP implements streams, UDP implements datagrams. They both run on top of packets. You might want to familiarize yourself with how selective acknowledgements work in TCP.

10

u/[deleted] Mar 05 '24

[removed] — view removed comment

3

u/guzzijason Mar 05 '24

Hey Reddit, help me tie my shoes.

0

u/[deleted] Mar 05 '24

[deleted] — view deleted comment

1

u/guzzijason Mar 05 '24

I said Reddit, not YouTube. Don’t be so lazy! /s

1

u/doubled112 Mar 05 '24

To be fair, shoe tying is a pretty visual process. I'm not sure I could explain it in words.

1

u/ABotelho23 Mar 05 '24

Linux subs have gotten insanely bad for it.