Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)
(시리즈 글이 12개 있습니다.)
개발 환경 구성: 83. Hyper-V의 네트워크 유형 (1)
; https://www.sysnet.pe.kr/2/0/910

개발 환경 구성: 84. Hyper-V의 네트워크 유형 (2)
; https://www.sysnet.pe.kr/2/0/915

개발 환경 구성: 87. Hyper-V의 네트워크 유형 (3)
; https://www.sysnet.pe.kr/2/0/918

Windows: 59. Hyper-V Internal 네트워크 VM의 인터넷 접속
; https://www.sysnet.pe.kr/2/0/1335

개발 환경 구성: 330. Hyper-V VM의 Internal Network를 Private 유형으로 만드는 방법
; https://www.sysnet.pe.kr/2/0/11299

Windows: 174. WSL 2의 네트워크 통신 방법
; https://www.sysnet.pe.kr/2/0/12347

개발 환경 구성: 517. Hyper-V Internal 네트워크에 NAT을 이용한 인터넷 연결 제공
; https://www.sysnet.pe.kr/2/0/12352

개발 환경 구성: 522. WSL2 인스턴스와 호스트 측의 Hyper-V에 운영 중인 VM과 네트워크 연결을 하는 방법
; https://www.sysnet.pe.kr/2/0/12494

개발 환경 구성: 656. Internal Network 유형의 스위치로 공유한 Hyper-V의 VM과 호스트가 통신이 안 되는 경우
; https://www.sysnet.pe.kr/2/0/13199

개발 환경 구성: 660. WSL 2 내부로부터 호스트 측의 네트워크로 UDP 데이터가 1개의 패킷으로만 제한되는 문제
; https://www.sysnet.pe.kr/2/0/13230

개발 환경 구성: 665. WSL 2의 네트워크 통신 방법 - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/13256

개발 환경 구성: 670. WSL 2에서 호스팅 중인 TCP 서버를 외부에서 접근하는 방법
; https://www.sysnet.pe.kr/2/0/13280




WSL2 인스턴스와 호스트 측의 Hyper-V에 운영 중인 VM과 네트워크 연결을 하는 방법

기존 WSL 1 방식에서는 localhost 네트워크를 호스트와 공유해 사용했으므로 호스트 측에서 VM을 접근 가능했다면 WSL 1 인스턴스에서도 동일하게 접근이 됩니다. 하지만 해당 인스턴스를 WSL 2로 바꾸게 되면 네트워크 공간이 Hyper-V에 특별하게 생성된 (internal network 유형인) "WSL" 스위치로 별도 분리되기 때문에,

WSL 2의 네트워크 통신 방법
; https://www.sysnet.pe.kr/2/0/12347

이후 WSL 2 인스턴스와 호스트에 설치한 다른 VM 간의 통신이 안 됩니다. 예를 들어 볼까요? 자신의 컴퓨터에 설치된 wsl 인스턴스 상황이 아래와 같을 때,

C:\Windows\System32> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu-20.04           Running         2
  Ubuntu                 Running         1
  docker-desktop-data    Stopped         2

"Ubuntu-20.04" 인스턴스는 WSL 2 버전이므로 현재 호스트에 설치한 VM(예를 들어, IP가 192.168.100.50)에 대해 ping을 하면 이렇게 막히지만,

$ ping 192.168.100.50 -c 1
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, 100% packet loss, time 0ms

WSL 1에 해당하는 Ubuntu에서는 다음과 같이 정상적으로 ping이 잘 됩니다.

$ ping 192.168.100.50 -c 1
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




그런데 재미있는 건, 지난 글에 소개한 호스트 측의 포트 포워딩으로도 WSL 2 -> VM으로의 통신 설정을 할 수 없다는 점입니다. 예를 들어 아래와 같이 192.168.100.50 VM에 대해 호스트 측에 포트 포워딩 설정을 했지만,

C:\temp> netsh interface portproxy add v4tov4 listenport=18010 listenaddress=0.0.0.0 connectport=8010 connectaddress=192.168.100.50

C:\temp> netsh interface portproxy show v4tov4

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
*/

WSL 2 인스턴스에서 curl을 이용해 서비스 접속을 시도해도 time-out만 발생합니다.

// WSL 2 인스턴스가 속한 "WSL" 네트워크의 호스트 측 주소가 172.20.100.1이라고 가정했을 때

$ curl -I http://172.20.100.1:18010/test.txt
curl: (28) Failed to connect to 172.20.100.1 port 18010: Connection timed out




포기해야 하나 싶었는데... 다음의 글을 발견했습니다. ^^

After converting to WSL2 no longer able to route traffic to other VSwitches on the same host. #4288
; https://github.com/microsoft/WSL/issues/4288

답글에 보면, Hyper-V의 네트워크 스위치에 서로 포워딩이 가능하게 만들어 주면 된다는 것입니다. 그리고, 기본적으로는 이러한 포워딩이 전부 비활성 상태지만,

PS C:\Windows\System32> Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table
>>

ifIndex InterfaceAlias              AddressFamily ConnectionState Forwarding
------- --------------              ------------- --------------- ----------
     12 Local Area Connection                IPv6    Disconnected   Disabled
     12 Local Area Connection                IPv4    Disconnected   Disabled
     18 vEthernet (HyperVInternal)           IPv6       Connected   Disabled
     18 vEthernet (HyperVInternal)           IPv4       Connected   Disabled
     40 vEthernet (Default Switch)           IPv6       Connected   Disabled
     40 vEthernet (Default Switch)           IPv4       Connected   Disabled
     56 vEthernet (WSL)                      IPv6       Connected   Disabled
     56 vEthernet (WSL)                      IPv4       Connected   Disabled

WSL 2가 속한 "vEthernet (WSL)"과 통신을 원하는 VM이 속한 스위치(위의 예제에서는 "vEthernet (HyperVInternal)")에 대해 Forwarding을 활성화시켰더니,

PS C:\Windows\System32> Set-NetIPInterface -ifindex 18 -Forwarding Enabled
PS C:\Windows\System32> Set-NetIPInterface -ifindex 56 -Forwarding Enabled
PS C:\Windows\System32> Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table

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    Enabled
     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    Enabled

ping 메시지가 약간 달라지긴 했지만,

$ ping 192.168.100.50 -c 1
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, 100% packet loss, time 0ms

그래도 결과적으로는 실패를 하고 있습니다.

음... ^^; 그러다 "After converting to WSL2 no longer able to route traffic to other VSwitches on the same host. #4288" 글을 다시 한번 읽어봤는데요, 왠지 "Default Switch"가 언급되는 것이 좀 걸립니다. 혹시나 싶어, 제가 실습한 환경의 VM도 테스트를 위해 (제가 만들어 두었던) "vEthernet (HyperVInternal)"에서 (Hyper-V 설치 시 기본 생성된) "vEthernet (Default Switch)"로 옮긴 후 다시 Forwarding 설정을 했더니... ^^ 잘 됩니다.

뭔가 일반적인 VM Switch와 Hyper-V가 만든 "Default Switch" 간에 차이가 있다는 건데, 일단 오늘은 여기까지만 하고 ^^ 나중에 기회 되면 다시 Default Switch 이외의 환경에서 테스트를 해봐야겠습니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 1/19/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2021-01-22 07시57분
Using Tailscale on Windows to network more easily with WSL2 and Visual Studio Code
; https://www.hanselman.com/blog/using-tailscale-on-windows-to-network-more-easily-with-wsl2-and-visual-studio-code

WSL 2.0부터는 아래의 글에서 소개하는 것처럼,

Windows Subsystem for Linux September 2023 update
; https://devblogs.microsoft.com/commandline/windows-subsystem-for-linux-september-2023-update/

networkingMode를 mirrored로 주면 port forward 할 필요가 없어졌습니다.

* IPv6 support
* Connect to Windows servers from within Linux using the localhost address 127.0.0.1
* Connect to WSL directly from your local area network (LAN)
* Improved networking compatibility for VPNs
* Multicast support
정성태
2021-03-26 10시51분
[iron] 좋은내용 감사드립니다.
[guest]

1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13479정성태12/11/20232318개발 환경 구성: 691. WSL 2 (Ubuntu) + nginx 환경 설정
13477정성태12/8/20232508닷넷: 2182. C# - .NET 7부터 추가된 Int128, UInt128 [1]파일 다운로드1
13476정성태12/8/20232249닷넷: 2181. C# - .NET 8 JsonStringEnumConverter의 AOT를 위한 개선파일 다운로드1
13475정성태12/7/20232302닷넷: 2180. .NET 8 - 함수 포인터에 대한 Reflection 정보 조회파일 다운로드1
13474정성태12/6/20232164개발 환경 구성: 690. 닷넷 코어/5+ 버전의 ilasm/ildasm 실행 파일 구하는 방법 - 두 번째 이야기
13473정성태12/5/20232363닷넷: 2179. C# - 값 형식(Blittable)을 메모리 복사를 이용해 바이트 배열로 직렬화/역직렬화파일 다운로드1
13472정성태12/4/20232186C/C++: 164. Visual C++ - InterlockedCompareExchange128 사용 방법
13471정성태12/4/20232246Copilot - To enable GitHub Copilot, authorize this extension using GitHub's device flow
13470정성태12/2/20232542닷넷: 2178. C# - .NET 8부터 COM Interop에 대한 자동 소스 코드 생성 도입파일 다운로드1
13469정성태12/1/20232255닷넷: 2177. C# - (Interop DLL 없이) CoClass를 이용한 COM 개체 생성 방법파일 다운로드1
13468정성태12/1/20232214닷넷: 2176. C# - .NET Core/5+부터 달라진 RCW(Runtime Callable Wrapper) 대응 방식파일 다운로드1
13467정성태11/30/20232244오류 유형: 882. C# - Unhandled exception. System.Runtime.InteropServices.COMException (0x800080A5)파일 다운로드1
13466정성태11/29/20232439닷넷: 2175. C# - DllImport 메서드의 AOT 지원을 위한 LibraryImport 옵션
13465정성태11/28/20232186개발 환경 구성: 689. MSBuild - CopyToOutputDirectory가 "dotnet publish" 시에는 적용되지 않는 문제파일 다운로드1
13464정성태11/28/20232309닷넷: 2174. C# - .NET 7부터 UnmanagedCallersOnly 함수 export 기능을 AOT 빌드에 통합파일 다운로드1
13463정성태11/27/20232221오류 유형: 881. Visual Studio - NU1605: Warning As Error: Detected package downgrade
13462정성태11/27/20232273오류 유형: 880. Visual Studio - error CS0246: The type or namespace name '...' could not be found
13461정성태11/26/20232306닷넷: 2173. .NET Core 3/5+ 기반의 COM Server를 registry 등록 없이 사용하는 방법파일 다운로드1
13460정성태11/26/20232260닷넷: 2172. .NET 6+ 기반의 COM Server 내에 Type Library를 내장하는 방법파일 다운로드1
13459정성태11/26/20232236닷넷: 2171. .NET Core 3/5+ 기반의 COM Server를 기존의 regasm처럼 등록하는 방법파일 다운로드1
13458정성태11/26/20232247닷넷: 2170. .NET Core/5+ 기반의 COM Server를 tlb 파일을 생성하는 방법(tlbexp)
13457정성태11/25/20232183VS.NET IDE: 187. Visual Studio - 16.9 버전부터 추가된 "Display inline type hints" 옵션
13456정성태11/25/20232479닷넷: 2169. C# - OpenAI를 사용해 PDF 데이터를 대상으로 OpenAI 챗봇 작성 [1]파일 다운로드1
13455정성태11/25/20232384닷넷: 2168. C# - Azure.AI.OpenAI 패키지로 OpenAI 사용파일 다운로드1
13454정성태11/23/20232727닷넷: 2167. C# - Qdrant Vector DB를 이용한 Embedding 벡터 값 보관/조회 (Azure OpenAI) [1]파일 다운로드1
13453정성태11/23/20232239오류 유형: 879. docker desktop 설치 시 "Invalid JSON string. (Exception from HRESULT: 0x83750007)"
1  2  3  4  5  [6]  7  8  9  10  11  12  13  14  15  ...