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]

... 46  47  48  49  50  51  52  53  54  55  56  57  58  [59]  60  ...
NoWriterDateCnt.TitleFile(s)
12172정성태3/7/202016297개발 환경 구성: 474. docker - container에서 root 권한 명령어 실행(sudo)
12171정성태3/6/202011370VS.NET IDE: 143. Visual Studio - ASP.NET Core Web Application의 "Enable Docker Support" 옵션으로 달라지는 점 [1]
12170정성태3/6/20209904오류 유형: 599. "Docker Desktop is switching..." 메시지와 DockerDesktopVM CPU 소비 현상
12169정성태3/5/202011924개발 환경 구성: 473. Windows nanoserver에 대한 docker pull의 태그 사용 [1]
12168정성태3/5/202012637개발 환경 구성: 472. 윈도우 환경에서의 dockerd.exe("Docker Engine" 서비스)가 Linux의 것과 다른 점
12167정성태3/5/202011871개발 환경 구성: 471. C# - 닷넷 응용 프로그램에서 DB2 Express-C 데이터베이스 사용 (3) - ibmcom/db2express-c 컨테이너 사용
12166정성태3/4/202011481개발 환경 구성: 470. Windows Server 컨테이너 - DockerMsftProvider 모듈을 이용한 docker 설치
12165정성태3/2/202011110.NET Framework: 900. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 네 번째 이야기(Monitor.Enter 후킹)파일 다운로드1
12164정성태2/29/202011981오류 유형: 598. Surface Pro 6 - Windows Hello Face Software Device가 인식이 안 되는 문제
12163정성태2/27/202010446.NET Framework: 899. 익명 함수를 가리키는 delegate 필드에 대한 직렬화 문제
12162정성태2/26/202013277디버깅 기술: 166. C#에서 만든 COM 객체를 C/C++로 P/Invoke Interop 시 메모리 누수(Memory Leak) 발생 [6]파일 다운로드2
12161정성태2/26/20209884오류 유형: 597. manifest - The value "x64" of attribute "processorArchitecture" in element "assemblyIdentity" is invalid.
12160정성태2/26/202010607개발 환경 구성: 469. Reg-free COM 개체 사용을 위한 manifest 파일 생성 도구 - COMRegFreeManifest
12159정성태2/26/20208701오류 유형: 596. Visual Studio - The project needs to include ATL support
12158정성태2/25/202010616디버깅 기술: 165. C# - Marshal.GetIUnknownForObject/GetIDispatchForObject 사용 시 메모리 누수(Memory Leak) 발생파일 다운로드1
12157정성태2/25/202010595디버깅 기술: 164. C# - Marshal.GetNativeVariantForObject 사용 시 메모리 누수(Memory Leak) 발생 및 해결 방법파일 다운로드1
12156정성태2/25/20209876오류 유형: 595. LINK : warning LNK4098: defaultlib 'nafxcw.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
12155정성태2/25/20209115오류 유형: 594. Warning NU1701 - This package may not be fully compatible with your project
12154정성태2/25/20208906오류 유형: 593. warning LNK4070: /OUT:... directive in .EXP differs from output filename
12153정성태2/23/202011686.NET Framework: 898. Trampoline을 이용한 후킹의 한계파일 다운로드1
12152정성태2/23/202011414.NET Framework: 897. 실행 시에 메서드 가로채기 - CLR Injection: Runtime Method Replacer 개선 - 세 번째 이야기(Trampoline 후킹)파일 다운로드1
12151정성태2/22/202011866.NET Framework: 896. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 - 두 번째 이야기 (원본 함수 호출)파일 다운로드1
12150정성태2/21/202011748.NET Framework: 895. C# - Win32 API를 Trampoline 기법을 이용해 C# 메서드로 가로채는 방법 [1]파일 다운로드1
12149정성태2/20/202011519.NET Framework: 894. eBEST C# XingAPI 래퍼 - 연속 조회 처리 방법 [1]
12148정성태2/19/202012801디버깅 기술: 163. x64 환경에서 구현하는 다양한 Trampoline 기법 [1]
12147정성태2/19/202011435디버깅 기술: 162. x86/x64의 기계어 코드 최대 길이
... 46  47  48  49  50  51  52  53  54  55  56  57  58  [59]  60  ...