4. ๋„คํŠธ์›Œํฌ

TCP/IP์˜ ๊ฐ ๊ณ„์ธต


OSI 7๊ณ„์ธต๊ณผ TCP/IP์˜ ๊ณ„์ธต์˜ ์ฐจ์ด

Pasted image 20250305132743.png


Frame, Packet, Segment, Datagram

์†Œ์ผ“์€ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋„คํŠธ์›Œํฌ๋ฅผ ํ†ตํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ ๋ฐ›์œผ๋ ค๋ฉด ๋ฐ˜๋“œ์‹œ ์—ด์–ด์•ผ ํ•˜๋Š” ์ฐฝ๊ตฌ ๊ฐ™์€ ๊ฒƒ์ด๊ณ ,ย 
ํฌํŠธ๋Š” ํ”„๋กœ์„ธ์Šค ์‹๋ณ„์„ ์œ„ํ•ด ํ•˜๋‚˜์˜ ํ˜ธ์ŠคํŠธ์—์„œ ํ”„๋กœ์„ธ์Šค์— ํ• ๋‹นํ•˜๋Š” ๊ณ ์œ ๊ฐ’์ด๊ณ ,ย 
ํŒจํ‚ท์€ ๋„คํŠธ์›Œํฌ ์ƒ์˜ ๋ฐ์ดํ„ฐ ์กฐ๊ฐ์„ ๋งํ•˜๋Š” ๊ฒƒ์ด๋‹ค.


TCP์™€ UDP์˜ ์ฐจ์ด

๋”ฐ๋ผ์„œ, UDP๋Š” ์†๋„์ฆ๊ฐ€์™€ ์ง€์—ฐ ๊ฐ์†Œ๋ฅผ ์œ„ํ•ด์„œ ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ , TCP๋Š” ์‹ ๋ขฐ์„ฑ์ด ์ค‘์š”ํ•œ ๊ฒฝ์šฐ์— ์‚ฌ์šฉ๋œ๋‹ค.
์˜ˆ๋ฅผ๋“ค์–ด, UDP๋Š” ๋™์˜์ƒ ์ „์†ก๊ณผ ๊ฐ™์ด, ๋ช‡ ํ”„๋ ˆ์ž„ ์ •๋„ ์†์‹ค๋˜์–ด๋„ ๊ดœ์ฐฎ์€ ๋ฐ์ดํ„ฐ ์ „์†ก์— ์‚ฌ์šฉ๋˜๊ณ , TCP๋Š” ๋ช‡๋ช‡์˜ ์ •๋ณด๋„ ์†์‹ค๋˜์–ด์„œ๋Š” ์•ˆ๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ด์šฉ๋œ๋‹ค.


TCP์™€ UDP์˜ ํ—ค๋” ๋น„๊ต


TCP์˜ 3-way-handshake์™€ 4-way-handshake๋ฅผ ๋น„๊ต

โ€ข 3-way Handshake (์—ฐ๊ฒฐ ์„ค์ •):
Pasted image 20250305140219.png
TCP์˜ ์—ฐ๊ฒฐ์„ ์ดˆ๊ธฐํ™” ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
์–‘์ชฝ ๋ชจ๋‘ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•  ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋‹ค๋Š” ๊ฒƒ์„ ๋ณด์žฅํ•˜๊ณ , ์‹ค์ œ๋กœ ๋ฐ์ดํ„ฐ ์ „๋‹ฌ์ด ์‹œ์ž‘ํ•˜๊ธฐ์ „์— ํ•œ์ชฝ์ด ๋‹ค๋ฅธ ์ชฝ์ด ์ค€๋น„๋˜์—ˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.

1. ํด๋ผ์ด์–ธํŠธ๊ฐ€ SYN ์ „์†ก
2. ์„œ๋ฒ„๊ฐ€ SYN+ACK ์ „์†ก
3. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ACK ์ „์†กํ•˜์—ฌ ์—ฐ๊ฒฐ ์„ฑ๋ฆฝ

-> 2-way๋กœ๋„ ์ถฉ๋ถ„ํ•ด๋ณด์ด๋Š”๋ฐ 3-way๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ : ์–‘๋ฐฉํ–ฅ์„ฑ ์—ฐ๊ฒฐ์ด๊ธฐ ๋•Œ๋ฌธ

โ€ข 4-way Handshake (์—ฐ๊ฒฐ ์ข…๋ฃŒ)
Pasted image 20250305140528.png
์„ธ์…˜์„ ์ข…๋ฃŒํ•˜๊ธฐ ์œ„ํ•ด ์ˆ˜ํ–‰๋˜๋Š” ์ ˆ์ฐจ์ด๋‹ค.

1. FIN ์ „์†ก (ํ•œ ์ชฝ ์ข…๋ฃŒ ์˜์‚ฌ ํ‘œ์‹œ)
2. ์ƒ๋Œ€๋ฐฉ์ด ACK ์ „์†ก ํ›„, ๋ฐ์ดํ„ฐ ์ „์†ก ๋งˆ๋ฌด๋ฆฌ
3. ์ƒ๋Œ€๋ฐฉ์ด FIN ์ „์†ก
4. ์ฒ˜์Œ FIN ์ „์†กํ•œ ์ชฝ์ด ACK ์ „์†ก ๋ฐ TIME_WAIT ์ƒํƒœ๋กœ ์ž”์—ฌ ํŒจํ‚ท ๋Œ€๊ธฐ

๐Ÿ’กย CLOSE_WAITย ์™€ย TIME_WAITย ์ƒํƒœ๋ž€ ๋ฌด์—‡์ผ๊นŒ?
TIME_WAITย ์ƒํƒœ๋กœ ๋Œ€๊ธฐํ•˜๋Š” ์ด์œ ๋Š”, ์„ธ์…˜ ์ข…๋ฃŒํ›„, ํ˜น์‹œ๋‚˜ ๋„คํŠธ์›Œํฌ์— ์•„์ง ๋ผ์ด๋ธŒ ํŒจํ‚ท์ด ์กด์žฌํ• ์ˆ˜๋„ ์žˆ๊ธฐ๋•Œ๋ฌธ์ด๋‹ค.

๐Ÿ’ก ์šฉ์–ด


TCP์˜ ์—ฐ๊ฒฐ ์„ค์ • ๊ณผ์ •(3๋‹จ๊ณ„)์™€ ์—ฐ๊ฒฐ ์ข…๋ฃŒ(4๋‹จ๊ณ„)์—์„œ ๋‹จ๊ณ„ ์ฐจ์ด๊ฐ€ ๋‚˜๋Š” ์ด์œ 


FIN ํŒจํ‚ท๋ณด๋‹ค ๋Šฆ๊ฒŒ ๋„์ฐฉํ•˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•œ๋‹ค๋ฉด?


์ดˆ๊ธฐ Sequence Number์ธ ISN์„ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์ง€ ์•Š๊ณ  ๋‚œ์ˆ˜๋ฅผ ์ƒ์„ฑํ•ด์„œ ์„ค์ •ํ•˜๋Š” ์ด์œ 


HTTP์™€ HTTPS์˜ ์ฐจ์ด


HTTP ์š”์ฒญ/์‘๋‹ต ํ—ค๋”์˜ ๊ตฌ์กฐ


HTTP์™€ HTTPS ๋™์ž‘ ๊ณผ์ • ๋น„๊ต


CORS

Pasted image 20250305142405.png


HTTP GET๊ณผ POST ๋ฉ”์„œ๋“œ๋ฅผ ๋น„๊ต/์„ค๋ช…


์ฟ ํ‚ค์™€ ์„ธ์…˜


DNS

Pasted image 20250305143242.png


REST์™€ RESTful


Socket์ด๋ž€?

TCP

from socket import *

server_name = "example.com"
server_port = 1234

client_socket = socket(AF_INET, SOCKET_STREAM)  # ์†Œ์ผ“ ์ƒ์„ฑ
client_socket.connect((server_name, server_port)) # ์„œ๋ฒ„์— ์—ฐ๊ฒฐ ์š”์ฒญ
from socket import *

server_port = 1234

server_socket = socket(AF_INET, SOCKET_STREAM)  # ์†Œ์ผ“ ์ƒ์„ฑ
server_socket.bind(('', server_port)) # ์†Œ์ผ“์— ์ฃผ์†Œ ๋ฐ”์ธ๋”ฉ
server_socket.listen(1) # ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ ๋Œ€๊ธฐ

(client_socket, client_address) = server_socket.accept()  # ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ ์ˆ˜๋ฝ

UDP

from socket import *

server_name = "example.com"
server_port = 1234

client_socket = socket(AF_INET, SOCK_DGRAM) # ์†Œ์ผ“ ์ƒ์„ฑ
from socket import *

server_port = 1234
server_socket = socket(AF_NET, SOCK_DGRAM)  # ์†Œ์ผ“ ์ƒ์„ฑ
server_socket.bind(('', server_port)) # ์†Œ์ผ“์— ์ฃผ์†Œ ๋ฐ”์ธ๋”ฉ

Socket.io์™€ WebSocket์˜ ์ฐจ์ด


IPv4์™€ IPv6 ์ฐจ์ด


MAC Address๋ž€

๐Ÿ’ก MAC ์ฃผ์†Œ์™€ IP ์ฃผ์†Œ์˜ ์ฐจ์ด
MAC ์ฃผ์†Œ์™€ IP ์ฃผ์†Œ ๋ชจ๋‘ ํ†ต์‹ ๊ธฐ๊ธฐ์˜ ์‹๋ณ„์ž๋ผ๋Š” ๊ฒƒ์€ ๋™์ผํ•˜๋‹ค. ๋‹ค๋งŒ MAC ์ฃผ์†Œ๋Š” ์ œ์กฐ์—…์ฒด๊ฐ€ ํ†ต์‹ ๊ธฐ๊ธฐ์— ๋ถ€์—ฌํ•˜๋Š” ์‹๋ณ„์ž์ด๋ฉฐ ๊ฐ™์€ ์‹๋ณ„์ž๋ฅผ ๊ฐ™๋Š” ํ†ต์‹ ๊ธฐ๊ธฐ๋Š” ์—†๋‹ค. IP ์ฃผ์†Œ๋Š” Network Layer์—์„œ ํ†ต์‹ ์„ ํ•˜๊ธฐ ์œ„ํ•œ ์ฃผ์†Œ๋กœ ๋ณดํ†ต ํ†ต์‹ ์‚ฌ์—์„œ ๋ถ€์—ฌํ•˜๋ฉฐ ๋ฐ”๋€” ์ˆ˜ ์žˆ๋‹ค.


๋ผ์šฐํ„ฐ, ์Šค์œ„์น˜, ํ—ˆ๋ธŒ ์ฐจ์ด

Pasted image 20250305145325.png


SMTP


๋„คํŠธ์›Œํฌ topology

Pasted image 20250305145546.png


subnet mask โ†’ ์ด๊ฑด ์ข€ ์ดํ•ด๊ฐ€ ์•ˆ๊ฐ€๋Š”๋””..

IP ์ฃผ์†Œ์™€ ์„œ๋ธŒ๋„คํŒ… (subnetting)

IPv4 ์˜ ๊ฒฝ์šฐย 232์˜ ์ˆซ์ž๋กœ ์ฃผ์†Œ๋ฅผ ํ‘œํ˜„ํ•˜๊ณ , ์ด๋ฅผ ๊ตญ๊ฐ€, ํšŒ์‚ฌ ๋“ฑ ์ž˜๊ฒŒ ๋‚˜๋ˆ  ์–ด๋Š ์˜์—ญ์„ ์“ฐ๊ฒŒํ•  ๊ฒƒ์ธ์ง€ ๊ฒฐ์ •ํ•œ๋‹ค.

ํ•œ์ •๋œ ์ž์›์ด๊ธฐ ๋•Œ๋ฌธ์— ํšจ์œจ์ ์œผ๋กœ ๋…ธ๋“œ์— ์ฃผ์†Œ๋ฅผ ํ• ๋‹นํ•˜๋Š”๊ฒŒ ์ค‘์š”ํ•˜๋‹ค. ์ด๋ฅผ ์œ„ํ•ด IP ๋ฅผ ์ชผ๊ฐœ๋Š”, ๋„คํŠธ์›Œํฌ ํŒŒํŠธ + ํ˜ธ์ŠคํŠธ ํŒŒํŠธ๋กœ ๊ตฌ์„ฑํ•˜๋Š” ์„œ๋ธŒ๋„คํŒ…์„ ํ™œ์šฉํ•œ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ IP ์ฃผ์†Œ์— ๋”ฐ๋ผ 5๊ฐœ์˜ ํด๋ž˜์Šค๋กœ ๊ตฌ๋ถ„๋œ๋‹ค. ๊ฐ ํด๋ž˜์Šค์— ๋”ฐ๋ผ ๋„คํŠธ์›Œํฌ ํŒŒํŠธ์™€ ํ˜ธ์ŠคํŠธ ํŒŒํŠธ๊ฐ€ ์ •ํ•ด์ง„๋‹ค.
Pasted image 20250305150409.png
์œ„์™€ ๊ฐ™์€ ํด๋ž˜์Šค ๊ตฌ์กฐ์™€ ๋”๋ถˆ์–ด ๋”์šฑ ํšจ์œจ์ ์ธ ์„œ๋ธŒ๋„คํŒ…์„ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์„œ๋ธŒ๋„ท ๋งˆ์Šคํฌ์ด๋‹ค.

์„œ๋ธŒ๋„ท ๋งˆ์Šคํฌ (subnet mask)

ํ• ๋‹น๋œ IP ์ฃผ์†Œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋„คํŠธ์›Œํฌ ํŒŒํŠธ์™€ ํ˜ธ์ŠคํŠธ ํŒŒํŠธ๊ฐ€ ์ •ํ•ด์ ธ์žˆ๋‹ค.

ํšจ์œจ์ ์ธ ์ฃผ์†Œ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•ด ๋‚ด๋ถ€์ ์œผ๋กœ ํ˜ธ์ŠคํŠธ ํŒŒํŠธ๋ฅผ ์ƒˆ๋กœ์šด ๋„คํŠธ์›Œํฌ ํŒŒํŠธ์™€ ํ˜ธ์ŠคํŠธ ํŒŒํŠธ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ๋‹ค. ์ด ๋•Œ ์„œ๋ธŒ๋„ท ๋งˆ์Šคํฌ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๋งŒ์•ฝ C ํด๋ž˜์Šค์ธ 192.12.16.1 IP, 255.255.255.0 ์„œ๋ธŒ๋„ท ๋งˆ์Šคํฌ(ํ˜ธ์ŠคํŠธ ํŒŒํŠธ)๊ฐ€ ํ• ๋‹น๋˜์—ˆ์„ ๋•Œ ๊ธฐ์กด์˜ ์„œ๋ธŒ๋„ท ๋งˆ์Šคํฌ์ธ ๋งˆ์ง€๋ง‰ 8 ๋น„ํŠธ๋ฅผ 1111 0000 ์œผ๋กœ ๋ฐ”๊พผ๋‹ค๋ฉด, 4 ๋น„ํŠธ๋งŒํผ์˜ ๋„คํŠธ์›Œํฌ ํŒŒํŠธ (๊ทธ๋ฃน), 4 ๋น„ํŠธ๋งŒํผ์˜ ํ˜ธ์ŠคํŠธ (๋ฉค๋ฒ„) ๋ฅผ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๋œ๋‹ค๋ฉด ๋™์ผ ๋„คํŠธ์›Œํฌ ๊ฐ„์—๋Š” ์ปค๋ฎค๋‹ˆ์ผ€์ด์…˜์ด ์ž์œ ๋กญ์ง€๋งŒ, ๋‹ค๋ฅธ ๋„คํŠธ์›Œํฌ ๊ฐ„์—๋Š” ๋ผ์šฐํ„ฐ๋ฅผ ๊ฑฐ์ณ์•ผ ์ปค๋ฎค๋‹ˆ์ผ€์ด์…˜์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.

์–ด๋–ค ๊ธฐ์—…์„ ์ƒ๊ฐํ•ด๋ณด์ž. ์„œ๋ธŒ๋„ท ๋งˆ์Šคํฌ๋กœ ์ถ”๊ฐ€์ ์ธ ์„œ๋ธŒ๋„คํŒ…์„ ์•ˆํ•œ๋‹ค๋ฉด ์ธ์‚ฌํŒ€, ์žฌ๋ฌดํŒ€ ๋“ฑ๋“ฑ ์—ฌ๋Ÿฌ ํŒ€๋“ค์ด ๋ชจ๋‘ ๊ฐ™์€ ๋„คํŠธ์›Œํฌ ํŒŒํŠธ๋ฅผ ์ง€๋‹ˆ๋ฏ€๋กœ ์„œ๋กœ์—๊ฒŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿด ๋•Œ ์„œ๋ธŒ๋„ท ๋งˆ์Šคํฌ๋ฅผ ํ™œ์šฉํ•œ ์„œ๋ธŒ๋„คํŒ…์œผ๋กœ ํšจ์œจ์ ์œผ๋กœ IP ๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.


DHCP


Pasted image 20250305151045.png


์ด๋”๋„ท์ด๋ž€?

CSMA/CD vs CSMA/CA

  • CSMA/CD (Collision Detection)
    • ์ฃผ๋กœ ์œ ์„  ๋„คํŠธ์›Œํฌ(Ethernet)์—์„œ ์‚ฌ์šฉ
    • ์ฑ„๋„์„ ๊ฐ์‹œํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•˜๋ฉด ์ฆ‰์‹œ ์ค‘๋‹จํ•˜๊ณ  ๋Œ€์‘ ๊ฐ€๋Šฅ
    • ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•˜๋ฉด ๋„คํŠธ์›Œํฌ ์ž์›์„ ๋‚ญ๋น„ํ•˜๊ฒŒ ๋˜์ง€๋งŒ, ์œ ์„  ํ™˜๊ฒฝ์—์„œ๋Š” ์‹ ํ˜ธ ๊ฐ์ง€๊ฐ€ ๋น„๊ต์  ์ •ํ™•ํ•˜์—ฌ ํšจ์œจ์ ์œผ๋กœ ๋™์ž‘
  • CSMA/CA (Collision Avoidance)
    • ๋ฌด์„  ๋„คํŠธ์›Œํฌ(Wi-Fi)์—์„œ ์‚ฌ์šฉ
    • ๋ฌด์„  ํ™˜๊ฒฝ์—์„œ๋Š” ์ถฉ๋Œ ๊ฐ์ง€๊ฐ€ ์–ด๋ ค์›€
    • RTS/CTS(Request to Send / Clear to Send) ํ•ธ๋“œ์…ฐ์ดํฌ ๋“ฑ์˜ ์ ˆ์ฐจ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹ค์ œ ์ „์†ก ์ „์— ์ถฉ๋Œ ๊ฐ€๋Šฅ์„ฑ์„ ์ตœ์†Œํ™”
    • ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์ฆ๊ฐ€ํ•˜์ง€๋งŒ, ๋ฌด์„  ํŠน์„ฑ์— ๋งž๊ฒŒ ์„ค๊ณ„

Client์™€ Server ์ฐจ์ด


Delay, Timing(jitter), Throughput์˜ ์ฐจ์ด