IPv4와 IPv6는 인터넷 프로토콜(IP)의 두 가지 버전으로 네트워크에서 장치들이 데이터를 주고받을 수 있도록 하는 규칙을 정의한 프로토콜.
헤더의 크기는 20~60바이트 정도로 구성 요소는 다음과 같다.
기본적으로 보안 기능이 따로 없으며 보안을 위해 별도로 IPsec(인터넷 프로토콜 보안)을 구성해야 한다.
브로드캐스트를 지원하여 네트워크의 모든 장치에 데이터를 전송할 수 있다.
기존에 가장 널리 사용되며 모든 장치와 네트워크가 지원.
헤더의 크기는 고정적으로 40바이트이며 구성요소는 다음과 같다.
IPsec이 프로토콜에 내장되어 있어 기본적으로 보안을 제공한다. 데이터의 무결성과 인증, 암호화를 쉽게 구현할 수 있다.
브로드캐스트를 사용하지 않으며 대신 멀티캐스트와 애니캐스트를 사용.
: 멀티캐스트 - 특정 그룹에 데이터 전송
: 애니캐스트 - 가장 가까운 장치에 데이터 전송
IPv4와 호환되지 않기 때문에 전환 과정에서 이중 스택(Dual Stack) 또는 터널링(Tunneling) 같은 기술을 사용해 두 프로토콜을 공존시키고 있다.
Java와 Spring 백엔드 개발자 입장에서 IPv4와 IPv6 관련 개념을 실습해보는 것은 네트워크와 관련된 실무적인 감각을 익히는 데 매우 유용합니다. 실습을 통해 이해할 수 있는 주제와 방법을 아래에 정리했습니다.
운영 체제에서 네트워크 설정 확인
ipconfig 또는 ifconfig 명령어를 사용하여 IPv4와 IPv6 주소 확인.Java로 네트워크 인터페이스 확인
import java.net.*;
public class NetworkInterfaces {
public static void main(String[] args) throws SocketException {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
System.out.println("Interface: " + networkInterface.getName());
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
System.out.println(" Address: " + address.getHostAddress());
}
}
}
}
네트워크 설정 변경
Java 클라이언트-서버 통신
import java.io.*;
import java.net.*;
public class SimpleServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(8080);
System.out.println("Server started on port 8080");
while (true) {
Socket client = serverSocket.accept();
System.out.println("Client connected: " + client.getInetAddress());
client.close();
}
}
}
import java.io.*;
import java.net.*;
public class SimpleClient {
public static void main(String[] args) throws IOException {
String serverAddress = "192.168.1.100"; // 고정 IP 또는 동적 IP 확인
Socket socket = new Socket(serverAddress, 8080);
System.out.println("Connected to server at: " + serverAddress);
socket.close();
}
}
서버 실행
public class IPv6Server {
public static void main(String[] args) throws IOException {
InetAddress ipv6Address = InetAddress.getByName("::1"); // Loopback IPv6 주소
ServerSocket serverSocket = new ServerSocket(8080, 50, ipv6Address);
System.out.println("IPv6 Server started on port 8080");
while (true) {
Socket client = serverSocket.accept();
System.out.println("Client connected: " + client.getInetAddress());
client.close();
}
}
}
클라이언트 실행
public class IPv6Client {
public static void main(String[] args) throws IOException {
String serverAddress = "::1"; // Loopback IPv6 주소
Socket socket = new Socket(serverAddress, 8080);
System.out.println("Connected to IPv6 server at: " + serverAddress);
socket.close();
}
}
멀티캐스트 예제
import java.net.*;
public class MulticastExample {
public static void main(String[] args) throws IOException {
InetAddress group = InetAddress.getByName("224.0.0.1"); // IPv4 멀티캐스트 주소
MulticastSocket socket = new MulticastSocket(4446);
socket.joinGroup(group);
System.out.println("Joined multicast group: " + group);
byte[] buffer = new byte[256];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet);
System.out.println("Received message: " + new String(packet.getData()));
socket.leaveGroup(group);
socket.close();
}
}
HTTP 요청 전송
import java.net.*;
import java.io.*;
public class HttpRequestExample {
public static void main(String[] args) throws IOException {
URL url = new URL("http://[::1]:8080"); // IPv6 URL 형식
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("Response: " + response);
}
}
Spring Boot 애플리케이션에 적용:
application.properties).server.address=:: # IPv6 활성화
server.port=8080서버 환경 테스트:
위 실습은 네트워크 프로토콜의 기본 개념을 Java와 Spring을 통해 실질적으로 이해할 수 있는 기회를 제공합니다. 특히 IPv4와 IPv6의 차이점을 이해하고, 클라이언트-서버 환경에서 프로토콜을 구현하며 실무적인 네트워크 감각을 기를 수 있습니다.