CS/컴퓨터네트워크

[Ch4] IPv4, Network Address Translation(NAT)

호프 2023. 12. 3. 02:17

Datagram format & Fragmentation

IPv4 Datagram Format

  • IP Header: 20바이트

 

IPv4 Fragmentation

IPv4 Fragmentation at router

  • large IP datagram divided(fragmented) at routers (UDP datagram -> at host)
    • one datagram -> several datagrams
  • reassembled only at final destination "host" (not router) before they reach the transport layer (Layer 4) using IP header
    • IP header bits used to identify, order related fragments
  • If one or more of fragments doesn't arrive, discard the incomplete datagram
    • TCP segment loss 발생 -> TCP will recover from this loss
  • network links have MTU(max transmission unit): max amount of data that a link-level frame can carry
    • different link types along the path, different MTUs
  • src host에서도 IP fragmentation이 일어날 수 있다.
  • IPv4 라우터는 IP fragmentation은 해도 reassembly는 하지 않는다.
  • 하나의 메시지가 여러 pkt으로 쪼개서 전송될 때 Layer 3 header는 메세지의 가장 앞부분에 해당하는 pkt에만 포함된다. (X)

 

IPv4 Addressing

Interface

  • connection btw host/router and physical link
  • router typically have multiple interfaces
  • host typically has one or two interfaces (e.g. wired Ethernet, wireless 802.11)

IPv4 address

  • 32-bit identifier for host, router interface
  • IP addresses associated with each intereface
  • 223.1.1.1 = 11011111 00000001 00000001 00000001

Private IPv4 주소들을 동시에 여러 ISP에서 사용할 수 있다.

Subnet

Subnet

  • device interfaces with same subnet part of IP address can physically reach each other without intervening router
  • if subnet mask = 24: subnet part = leftmost 24-bit, host part = rightmost 8-bit

두 호스트의 IPv4 주소의 subnet part가 같다면, 두 호스트는 같은 네트워크에 있으며 라우터 없이도 통신이 가능하다.

 

 

Classful Addressing

  • Class A: /8, Class B: /16, Class C: /24
  • Class C provides too small hosts, Class B provides too many hosts
    • Rapid deletion of the class B address space & poor utilization of the assigned address space
    • 👉 CIDR

 

CIDR

CIDR: Classless InterDomain Routing

  • subnet portion of address of arbitrary length
  • public IP address (routable)
  • a.b.c.d/x : x = number of leftmost bits in subnet portion of address
    • x: subnet mask, network prefix, prefix
    • number of host IP address available = 2*(32-x) - 2

128.119.40.128/26 Subnet에 포함되는 IP address의 범위는?

👉 128.119.40.128 (11011111.0000001.00010001.10000000) to 128.119.40.191 (11011111.0000001.00010001.10111111)

 

DHCP

DHCP: Dynamic Host Configuration Protocol

  • Layer 5 protocol
  • allow host to dynamically get temporary IP address from server when it joins network.
  • DHCP는 서버와 클라이언트 모두 well-known-port 사용
  • DHCP를 사용하는 호스트는 여러 번의 인터넷 접속을 할 때마다 다른 IP 주소를 설정한다.

DHCP client-server scenario

 

 

DHCP server

  • can renew its lease on address in use
  • allow reuse of addresses
  • DHCP can return more than just allocated IP address on subnet
    • network mask
    • IP address of first-hop router (default gateway) for client
    • name and IP address of DNS server
  • 인터넷 연결시간이 짧은 다수의 사용자들에게 IP 주소를 할당하는 경우 DHCP가 적당 -> 적은 갯수의 IP 주소를 이용해서 더 많은 사용자들에게 인터넷 연결을 지원하는 효과
  • 처음 인터넷에 접속하는 기기에 네트워크를 설정할 때 기기의 NIC 카드에 할당할 IP 주소, gateway router의 IP 주소, DNS 서버의 IP 주소 정보를 알아야 한다.

Route Aggregation

How does network get subnet aprt of IP address?

  • gets allocated portion of its provider ISP's address space

Route Aggregation

  • hierarchical addressing
  • router will deliver IP pkts whose destination IP address belongs to the subnet
  • IP 경로의 효율성을 높이기 위해 여러 경로를 더 큰 하나의 경로로 합치는 기술, 더 넓은 범위의 IP 주소를 단일 경로로 표현함으로써 라우팅 테이블의 크기를 줄이고, 라우팅 정보를 간소화하여 네트워크의 효율성을 향상시킴

 

Longest prefix matching

Destination-based forwarding

  • 각 라우터는 패킷의 목적지 IP 주소를 확인하고 forwarding table (FIB)을 통해 forwarding 결정
  • 이 방식은 라우터의 FIB가 커질 수 있고, 특히 인터넷과 같이 대규모의 네트워크에서는 FIB의 크기가 문제가 될 수 있음

Longest prefix matching

  • when looking for forwarding table entry for given destination address, use longest address prefix that matches destination address
  • route aggregation 가능
  • 전통적인 per-routing 방식의 라우터들은 incoming pkt의 destination IP 주소만 보고 forwarding table(FIB)를 이용해서 forwarding 결정
  • router가 forwarding 할 때는 destination IP address의 subnet part만 본다.

Network Address Translation (NAT)

NAT

NAT: Network Addresss Translation == NAPT: Network Address Port Translation

  • translation btw private IP address (non-routable) <-> public IP address (routable)
  • all datagrams leaving local network have same single source NAT IP address, and different source port numbers
  • can change addresses of devices in local network without notifying outside world
  • can change ISP without changing addresses of devices in local network
  • devices inside local network not explicitly addressable, visible by outside world -> security plus

 

Implementation of NAT

  1. outgoing datagram: NAT router must replace of everying outgoing datagram
    • (src IP addr, port #) -> (NAT IP addr, new port #)
  2. NAT router must remember every translation pair in NAT translation table
  3. remote clients/servers will respond using (NAT IP adr, new port #) as destination address
  4. incoming datagram: NAT router must replace every incoming datagram using NAT table
    • (NAT IP addr, new port #) -> (src IP addr, port #)

 

Controversial of NAT

  • address shortage should instead be solved by IPv6
  • routers should only process up to Laer 3 -> But NAT는 port #도 사용
  • NAT violates the principle of end-to-end connectivity
    • port numbers are used for addressing processes
    • it causes problems for servers running on the home network

 

NAT traversal techniques

Relaying

  • Relaying은 서드파티 서버 또는 중계 서버를 사용하여 통신을 중계하는 방식
  • 내부 디바이스(in private network)와 외부 디바이스 간의 직접 통신이 불가능한 경우, 중계 서버가 데이터를 수신하고 해당 데이터를 다시 목적지에 전달하는 방식

Connection reversal

  • 내부 디바이스(in private network)가 외부 디바이스와 직접 연결을 시도하고, 외부 디바이스가 해당 연결을 통해 다시 내부 디바이스에 연결하는 방식
  • client와 server 사이에 주고 받는 데이터가 중간 노드를 거치지 않아 통신 속도 측면에서 유리하다.