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)
13430정성태10/30/20232666닷넷: 2153. C# - 사용자가 빌드한 ICU dll 파일을 사용하는 방법
13429정성태10/27/20232940닷넷: 2152. Win32 Interop - C/C++ DLL로부터 이중 포인터 버퍼를 C#으로 받는 예제파일 다운로드1
13428정성태10/25/20233014닷넷: 2151. C# 12 - ref readonly 매개변수
13427정성태10/18/20233199닷넷: 2150. C# 12 - 정적 문맥에서 인스턴스 멤버에 대한 nameof 접근 허용(Allow nameof to always access instance members from static context)
13426정성태10/13/20233359스크립트: 59. 파이썬 - 비동기 호출 함수(run_until_complete, run_in_executor, create_task, run_in_threadpool)
13425정성태10/11/20233169닷넷: 2149. C# - PLinq의 Partitioner<T>를 이용한 사용자 정의 분할파일 다운로드1
13423정성태10/6/20233147스크립트: 58. 파이썬 - async/await 기본 사용법
13422정성태10/5/20233284닷넷: 2148. C# - async 유무에 따른 awaitable 메서드의 병렬 및 예외 처리
13421정성태10/4/20233345닷넷: 2147. C# - 비동기 메서드의 async 예약어 유무에 따른 차이
13420정성태9/26/20235512스크립트: 57. 파이썬 - UnboundLocalError: cannot access local variable '...' where it is not associated with a value
13419정성태9/25/20233188스크립트: 56. 파이썬 - RuntimeError: dictionary changed size during iteration
13418정성태9/25/20233883닷넷: 2146. C# - ConcurrentDictionary 자료 구조의 동기화 방식
13417정성태9/19/20233421닷넷: 2145. C# - 제네릭의 형식 매개변수에 속한 (매개변수를 가진) 생성자를 호출하는 방법
13416정성태9/19/20233233오류 유형: 877. redis-py - MISCONF Redis is configured to save RDB snapshots, ...
13415정성태9/18/20233726닷넷: 2144. C# 12 - 컬렉션 식(Collection Expressions)
13414정성태9/16/20233483디버깅 기술: 193. Windbg - ThreadStatic 필드 값을 조사하는 방법
13413정성태9/14/20233680닷넷: 2143. C# - 시스템 Time Zone 변경 시 이벤트 알림을 받는 방법
13412정성태9/14/20236959닷넷: 2142. C# 12 - 인라인 배열(Inline Arrays) [1]
13411정성태9/12/20233458Windows: 252. 권한 상승 전/후 따로 관리되는 공유 네트워크 드라이브 정보
13410정성태9/11/20234976닷넷: 2141. C# 12 - Interceptor (컴파일 시에 메서드 호출 재작성) [1]
13409정성태9/8/20233834닷넷: 2140. C# - Win32 API를 이용한 모니터 전원 끄기
13408정성태9/5/20233800Windows: 251. 임의로 만든 EXE 파일을 포함한 ZIP 파일의 압축을 해제할 때 Windows Defender에 의해 삭제되는 경우
13407정성태9/4/20233556닷넷: 2139. C# - ParallelEnumerable을 이용한 IEnumerable에 대한 병렬 처리
13406정성태9/4/20233520VS.NET IDE: 186. Visual Studio Community 버전의 라이선스
13405정성태9/3/20233967닷넷: 2138. C# - async 메서드 호출 원칙
13404정성태8/29/20233477오류 유형: 876. Windows - 키보드의 등호(=, Equals sign) 키가 눌리지 않는 경우
1  2  3  4  5  6  7  [8]  9  10  11  12  13  14  15  ...