반응형

[JAVA 실습 #4] IPv4 사용 설정

 

<< 환경 >>

Window 10 명령프롬프트 (cmd)

JDK 1.8

 

WAR 파일을 java로 실행하는 경우 IPv4 우선 사용 설정

-D옵션 추가

 
-Djava.net.preferIPv4Stack=true
 

 

java -jar 파일이름.war --server.port=9090 -Djava.net.preferIPv4Stack=true

 


참고

https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/net/doc-files/net-properties.html

Networking Properties

There are a few standard system properties used to alter the mechanisms and behavior of the various classes of the java.net package. Some are checked only once at startup of the VM, and therefore are best set using the -D option of the java command, while others have a more dynamic nature and can also be changed using the System.setProperty() API. The purpose of this document is to list and detail all of these properties.

If there is no special note, a property value is checked every time it is used.

IPv4 / IPv6

  • java.net.preferIPv4Stack (default: false)
    If IPv6 is available on the operating system the underlying native socket will be, by default, an IPv6 socket which lets applications connect to, and accept connections from, both IPv4 and IPv6 hosts. However, in the case an application would rather use IPv4 only sockets, then this property can be set to true. The implication is that it will not be possible for the application to communicate with IPv6 only hosts.

  • java.net.preferIPv6Addresses (default: false)
    When dealing with a host which has both IPv4 and IPv6 addresses, and if IPv6 is available on the operating system, the default behavior is to prefer using IPv4 addresses over IPv6 ones. This is to ensure backward compatibility, for example applications that depend on the representation of an IPv4 address (e.g. 192.168.1.1). This property can be set to true to change that preference and use IPv6 addresses over IPv4 ones where possible, or system to preserve the order of the addresses as returned by the operating system.

Both of these properties are checked only once, at startup.


 

반응형