성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] 그냥 RSS Reader 기능과 약간의 UI 편의성 때문에 사용...
[이종효] 오래된 소프트웨어는 보안 위협이 되기도 합니다. 혹시 어떤 기능...
[정성태] @Keystroke IEEE의 문서를 소개해 주시다니... +_...
[손민수 (Keystroke)] 괜히 듀얼채널 구성할 때 한번에 같은 제품 사라고 하는 것이 아...
[정성태] 전각(Full-width)/반각(Half-width) 기능을 토...
[정성태] Vector에 대한 내용은 없습니다. Vector가 닷넷 BCL...
[orion] 글 읽고 찾아보니 디자인 타임에는 InitializeCompon...
[orion] 연휴 전에 재현 프로젝트 올리자 생각해 놓고 여의치 않아서 못 ...
[정성태] 아래의 글에 정리했으니 참고하세요. C# - Typed D...
[정성태] 간단한 재현 프로젝트라도 있을까요? 저런 식으로 설명만 해...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>WSL 2 인스턴스와 호스트 측의 Hyper-V에 운영 중인 VM과 네트워크 연결을 하는 방법</h1> <p> 아래의 글에 새롭게 정리했으니 참고하세요.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > WSL 2 인스턴스와 호스트 측의 Hyper-V에 운영 중인 VM과 네트워크 연결을 하는 방법 - 두 번째 이야기 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/13658'>https://www.sysnet.pe.kr/2/0/13658</a> </pre> <br /> <hr style='width: 50%' /><br /> <br /> 기존 WSL 1 방식에서는 localhost 네트워크를 호스트와 공유해 사용했으므로 호스트 측에서 VM을 접근 가능했다면 WSL 1 인스턴스에서도 동일하게 접근이 됩니다. 하지만 해당 인스턴스를 WSL 2로 바꾸게 되면 네트워크 공간이 Hyper-V에 특별하게 생성된 (internal network 유형인) "WSL" 스위치로 별도 분리되기 때문에,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > WSL 2의 네트워크 통신 방법 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12347'>https://www.sysnet.pe.kr/2/0/12347</a> </pre> <br /> 이후 WSL 2 인스턴스와 호스트에 설치한 다른 VM 간의 통신이 안 됩니다. 예를 들어 볼까요? 자신의 컴퓨터에 설치된 wsl 인스턴스 상황이 아래와 같을 때,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\Windows\System32> <span style='color: blue; font-weight: bold'>wsl -l -v</span> NAME STATE VERSION * <span style='color: blue; font-weight: bold'>Ubuntu-20.04</span> Running <span style='color: blue; font-weight: bold'>2</span> <span style='color: blue; font-weight: bold'>Ubuntu</span> Running <span style='color: blue; font-weight: bold'>1</span> docker-desktop-data Stopped 2 </pre> <br /> "Ubuntu-20.04" 인스턴스는 WSL 2 버전이므로 현재 호스트에 설치한 VM(예를 들어, IP가 192.168.100.50)에 대해 ping을 하면 이렇게 막히지만,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>ping 192.168.100.50 -c 1</span> PING 192.168.100.50 (192.168.100.50) 56(84) bytes of data. --- 192.168.100.50 ping statistics --- 1 packets transmitted, 0 received, <span style='color: blue; font-weight: bold'>100% packet loss</span>, time 0ms </pre> <br /> WSL 1에 해당하는 Ubuntu에서는 다음과 같이 정상적으로 ping이 잘 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>ping 192.168.100.50 -c 1</span> PING 192.168.100.50 (192.168.100.50) 56(84) bytes of data. 64 bytes from 192.168.100.50: icmp_seq=1 ttl=128 time=0.604 ms --- 192.168.100.50 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.604/0.604/0.604/0.000 ms </pre> <br /> <hr style='width: 50%' /><br /> <br /> 그런데 재미있는 건, <a target='tab' href='https://www.sysnet.pe.kr/2/0/12347#port_forward'>지난 글에 소개한 호스트 측의 포트 포워딩</a>으로도 WSL 2 -> VM으로의 통신 설정을 할 수 없다는 점입니다. 예를 들어 아래와 같이 192.168.100.50 VM에 대해 호스트 측에 포트 포워딩 설정을 했지만,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp> <span style='color: blue; font-weight: bold'>netsh interface portproxy add v4tov4 listenport=18010 listenaddress=0.0.0.0 connectport=8010</span> connectaddress=192.168.100.50 C:\temp> <span style='color: blue; font-weight: bold'>netsh interface portproxy show v4tov4</span> Listen on ipv4: Connect to ipv4: Address Port Address Port --------------- ---------- --------------- ---------- 0.0.0.0 18010 192.168.100.50 8010 /* 삭제 방법) netsh interface portproxy delete v4tov4 listenport=18010 listenaddress=0.0.0.0 */ </pre> <br /> WSL 2 인스턴스에서 curl을 이용해 서비스 접속을 시도해도 time-out만 발생합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // WSL 2 인스턴스가 속한 "WSL" 네트워크의 호스트 측 주소가 172.20.100.1이라고 가정했을 때 $ <span style='color: blue; font-weight: bold'>curl -I http://172.20.100.1:18010/test.txt</span> curl: (28) Failed to connect to 172.20.100.1 port 18010: Connection timed out </pre> <br /> <hr style='width: 50%' /><br /> <br /> 포기해야 하나 싶었는데... 다음의 글을 발견했습니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > After converting to WSL2 no longer able to route traffic to other VSwitches on the same host. #4288 ; <a target='tab' href='https://github.com/microsoft/WSL/issues/4288'>https://github.com/microsoft/WSL/issues/4288</a> </pre> <br /> 답글에 보면, Hyper-V의 네트워크 스위치에 서로 포워딩이 가능하게 만들어 주면 된다는 것입니다. 그리고, 기본적으로는 이러한 포워딩이 전부 비활성 상태지만,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > PS C:\Windows\System32> <span style='color: blue; font-weight: bold'>Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table</span> ifIndex InterfaceAlias AddressFamily ConnectionState Forwarding ------- -------------- ------------- --------------- ---------- 12 Local Area Connection IPv6 Disconnected Disabled 12 Local Area Connection IPv4 Disconnected Disabled <span style='color: blue; font-weight: bold'>18 vEthernet (HyperVInternal) IPv6 Connected Disabled 18 vEthernet (HyperVInternal) IPv4 Connected Disabled</span> 40 vEthernet (Default Switch) IPv6 Connected Disabled 40 vEthernet (Default Switch) IPv4 Connected Disabled <span style='color: blue; font-weight: bold'>56 vEthernet (WSL) IPv6 Connected Disabled 56 vEthernet (WSL) IPv4 Connected Disabled</span> </pre> <br /> WSL 2가 속한 "vEthernet (WSL)"과 통신을 원하는 VM이 속한 스위치(위의 예제에서는 "vEthernet (HyperVInternal)")에 대해 Forwarding을 활성화시켰더니,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > PS C:\Windows\System32> <span style='color: blue; font-weight: bold'>Set-NetIPInterface -ifindex 18 -Forwarding Enabled</span> PS C:\Windows\System32> <span style='color: blue; font-weight: bold'>Set-NetIPInterface -ifindex 56 -Forwarding Enabled</span> PS C:\Windows\System32> <span style='color: blue; font-weight: bold'>Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table</span> ifIndex InterfaceAlias AddressFamily ConnectionState Forwarding ------- -------------- ------------- --------------- ---------- 12 Local Area Connection IPv6 Disconnected Disabled 12 Local Area Connection IPv4 Disconnected Disabled 18 vEthernet (HyperVInternal) IPv6 Connected Enabled 18 vEthernet (HyperVInternal) IPv4 Connected <span style='color: blue; font-weight: bold'>Enabled</span> 40 vEthernet (Default Switch) IPv6 Connected Disabled 40 vEthernet (Default Switch) IPv4 Connected Disabled 56 vEthernet (WSL) IPv6 Connected Enabled 56 vEthernet (WSL) IPv4 Connected <span style='color: blue; font-weight: bold'>Enabled</span> </pre> <br /> ping 메시지가 약간 달라지긴 했지만,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>ping 192.168.100.50 -c 1</span> PING 192.168.100.50 (192.168.100.50) 56(84) bytes of data. From 172.20.100.1: icmp_seq=1 Redirect Network(New nexthop: 192.168.100.50) --- 192.168.100.50 ping statistics --- 1 packets transmitted, 0 received, <span style='color: blue; font-weight: bold'>100% packet loss</span>, time 0ms </pre> <br /> 그래도 결과적으로는 실패를 하고 있습니다.<br /> <br /> 음... ^^; 그러다 "<a target='tab' href='https://github.com/microsoft/WSL/issues/4288'>After converting to WSL2 no longer able to route traffic to other VSwitches on the same host. #4288</a>" 글을 다시 한번 읽어봤는데요, 왠지 "Default Switch"가 언급되는 것이 좀 걸립니다. 혹시나 싶어, 제가 실습한 환경의 VM도 테스트를 위해 (제가 만들어 두었던) "vEthernet (HyperVInternal)"에서 (Hyper-V 설치 시 기본 생성된) "vEthernet (Default Switch)"로 옮긴 후 다시 Forwarding 설정을 했더니... ^^ 잘 됩니다.<br /> <br /> 뭔가 일반적인 VM Switch와 Hyper-V가 만든 "Default Switch" 간에 차이가 있다는 건데, 일단 오늘은 여기까지만 하고 ^^ 나중에 기회 되면 다시 Default Switch 이외의 환경에서 테스트를 해봐야겠습니다.<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
5665
(왼쪽의 숫자를 입력해야 합니다.)