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)
13304정성태3/31/20234388VS.NET IDE: 181. Visual Studio - C/C++ 프로젝트에 application manifest 적용하는 방법
13303정성태3/30/20233731Windows: 241. 환경 변수 %PATH%에 DLL을 찾는 규칙
13302정성태3/30/20234358Windows: 240. RDP 환경에서 바뀌는 %TEMP% 디렉터리 경로
13301정성태3/29/20234453Windows: 239. C/C++ - Windows 10 Version 1607부터 지원하는 /DEPENDENTLOADFLAG 옵션파일 다운로드1
13300정성태3/28/20234097Windows: 238. Win32 - Modal UI 창에 올바른 Owner(HWND)를 설정해야 하는 이유
13299정성태3/27/20233870Windows: 237. Win32 - 모든 메시지 루프를 탈출하는 WM_QUIT 메시지
13298정성태3/27/20233827Windows: 236. Win32 - MessageBeep 소리가 안 들린다면?
13297정성태3/26/20234487Windows: 235. Win32 - Code Modal과 UI Modal
13296정성태3/25/20233825Windows: 234. IsDialogMessage와 협업하는 WM_GETDLGCODE Win32 메시지 [1]파일 다운로드1
13295정성태3/24/20234115Windows: 233. Win32 - modeless 대화창을 modal처럼 동작하게 만드는 방법파일 다운로드1
13294정성태3/22/20234282.NET Framework: 2105. LargeAddressAware 옵션이 적용된 닷넷 32비트 프로세스의 가용 메모리 - 두 번째
13293정성태3/22/20234346오류 유형: 853. dumpbin - warning LNK4048: Invalid format file; ignored
13292정성태3/21/20234461Windows: 232. C/C++ - 일반 창에도 사용 가능한 IsDialogMessage파일 다운로드1
13291정성태3/20/20234832.NET Framework: 2104. C# Windows Forms - WndProc 재정의와 IMessageFilter 사용 시의 차이점
13290정성태3/19/20234328.NET Framework: 2103. C# - 윈도우에서 기본 제공하는 FindText 대화창 사용법파일 다운로드1
13289정성태3/18/20233515Windows: 231. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 자식 윈도우를 생성하는 방법파일 다운로드1
13288정성태3/17/20233629Windows: 230. Win32 - 대화창의 DLU 단위를 pixel로 변경하는 방법파일 다운로드1
13287정성태3/16/20233790Windows: 229. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 윈도우를 직접 띄우는 방법파일 다운로드1
13286정성태3/15/20234235Windows: 228. Win32 - 리소스에 포함된 대화창 Template의 2진 코드 해석 방법
13285정성태3/14/20233823Windows: 227. Win32 C/C++ - Dialog Procedure를 재정의하는 방법파일 다운로드1
13284정성태3/13/20234046Windows: 226. Win32 C/C++ - Dialog에서 값을 반환하는 방법파일 다운로드1
13283정성태3/12/20233583오류 유형: 852. 파이썬 - TypeError: coercing to Unicode: need string or buffer, NoneType found
13282정성태3/12/20233914Linux: 58. WSL - nohup 옵션이 필요한 경우
13281정성태3/12/20233841Windows: 225. 윈도우 바탕화면의 아이콘들이 넓게 퍼지는 경우 [2]
13280정성태3/9/20234591개발 환경 구성: 670. WSL 2에서 호스팅 중인 TCP 서버를 외부에서 접근하는 방법
13279정성태3/9/20234117오류 유형: 851. 파이썬 ModuleNotFoundError: No module named '_cffi_backend'
1  2  3  4  5  6  7  8  9  10  11  12  [13]  14  15  ...