티스토리 뷰

Java

[Java] Java에서 IPv4로 출력하기

Jane Kwon 2023. 6. 7. 12:00
반응형

 

인프라 팀에서 우리 서버가 IPv4가 아닌 IPv6로 잡힌다고 한다.

 

서버에 접속해서 netstat -nltp 때려보니

톰캣으로 띄워놓은 8080 포트가 우리에게 익숙한 IPv4가 아닌 IPv6로 인식하고 있다.

$ netstat -nltp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 127.0.0.1:18003             0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -
tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN      7091/java
tcp        0      0 :::9000                     :::*                        LISTEN      1940/java
tcp        0      0 :::8009                     :::*                        LISTEN      7091/java
tcp        0      0 :::28461                    :::*                        LISTEN      7091/java
tcp        0      0 :::3309                     :::*                        LISTEN      -
tcp        0      0 :::9840                     :::*                        LISTEN      7091/java
tcp        0      0 :::8080                     :::*                        LISTEN      7091/java
tcp        0      0 :::80                       :::*                        LISTEN      -
tcp        0      0 :::9841                     :::*                        LISTEN      7091/java
tcp        0      0 :::22                       :::*                        LISTEN      -
tcp        0      0 :::443                      :::*                        LISTEN      -

 

톰캣 설정 파일을 열어 아래 설정을 추가해주니

JAVA_OPTS="-Djava.net.preferIPv4Stack=true"

 

이제야 IPv4로 출력한다.

$ netstat -nltp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 127.0.0.1:8005              0.0.0.0:*                   LISTEN      32184/java
tcp        0      0 0.0.0.0:21415               0.0.0.0:*                   LISTEN      32184/java
tcp        0      0 0.0.0.0:8009                0.0.0.0:*                   LISTEN      32184/java
tcp        0      0 0.0.0.0:9840                0.0.0.0:*                   LISTEN      32184/java
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      32184/java
tcp        0      0 0.0.0.0:9841                0.0.0.0:*                   LISTEN      32184/java
tcp        0      0 127.0.0.1:18003             0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -
tcp        0      0 :::9000                     :::*                        LISTEN      1940/java
tcp        0      0 :::3309                     :::*                        LISTEN      -
tcp        0      0 :::80                       :::*                        LISTEN      -
tcp        0      0 :::22                       :::*                        LISTEN      -
tcp        0      0 :::443                      :::*                        LISTEN      -

 

(참고 : https://m.blog.naver.com/hanajava/221731411069)

 

 

 

 

 

반응형
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함