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)
13534정성태1/21/20242241닷넷: 2207. C# - SQL Server DB를 bacpac으로 Export/Import파일 다운로드1
13533정성태1/18/20242453닷넷: 2206. C# - TCP KeepAlive의 서버 측 구현파일 다운로드1
13532정성태1/17/20242346닷넷: 2205. C# - SuperSimpleTcp 사용 시 주의할 점파일 다운로드1
13531정성태1/16/20242239닷넷: 2204. C# - TCP KeepAlive에 새로 추가된 Retry 옵션파일 다운로드1
13530정성태1/15/20242194닷넷: 2203. C# - Python과의 AES 암호화 연동파일 다운로드1
13529정성태1/15/20242053닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법
13528정성태1/14/20242181Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20242123오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242205닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20242158오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20242220오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20242029오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
13522정성태1/11/20242192닷넷: 2200. C# - HttpClient.PostAsJsonAsync 호출 시 "Transfer-Encoding: chunked" 대신 "Content-Length" 헤더 처리
13521정성태1/11/20242257닷넷: 2199. C# - 한국투자증권 KIS Developers OpenAPI의 WebSocket Ping, Pong 처리
13520정성태1/10/20242001오류 유형: 888. C# - Unable to resolve service for type 'Microsoft.Extensions.ObjectPool.ObjectPool`....'
13519정성태1/10/20242093닷넷: 2198. C# - Reflection을 이용한 ClientWebSocket의 Ping 호출파일 다운로드1
13518정성태1/9/20242356닷넷: 2197. C# - ClientWebSocket의 Ping, Pong 처리
13517정성태1/8/20242198스크립트: 63. Python - 공개 패키지를 이용한 위성 이미지 생성 (pystac_client, odc.stac)
13516정성태1/7/20242305닷넷: 2196. IIS - AppPool의 "Disable Overlapped Recycle" 옵션의 부작용
13515정성태1/6/20242582닷넷: 2195. async 메서드 내에서 C# 7의 discard 구문 활용 사례 [1]
13514정성태1/5/20242255개발 환경 구성: 702. IIS - AppPool의 "Disable Overlapped Recycle" 옵션
13513정성태1/5/20242176닷넷: 2194. C# - WebActivatorEx / System.Web의 PreApplicationStartMethod 특성
13512정성태1/4/20242143개발 환경 구성: 701. IIS - w3wp.exe 프로세스의 ASP.NET 런타임을 항상 Warmup 모드로 유지하는 preload Enabled 설정
13511정성태1/4/20242163닷넷: 2193. C# - ASP.NET Web Application + OpenAPI(Swashbuckle) 스펙 제공
13510정성태1/3/20242099닷넷: 2192. C# - 특정 실행 파일이 있는지 확인하는 방법 (Linux)
13509정성태1/3/20242123오류 유형: 887. .NET Core 2 이하의 프로젝트에서 System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0.
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...