Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

(시리즈 글이 14개 있습니다.)
개발 환경 구성: 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. WSL 2 인스턴스와 호스트 측의 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

개발 환경 구성: 712. Windows - WSL 2의 네트워크 통신 방법 - 세 번째 이야기 (같은 IP를 공유하는 WSL 2 인스턴스)
; https://www.sysnet.pe.kr/2/0/13647

개발 환경 구성: 714. WSL 2 인스턴스와 호스트 측의 Hyper-V에 운영 중인 VM과 네트워크 연결을 하는 방법 - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/13658




WSL 2 인스턴스와 호스트 측의 Hyper-V에 운영 중인 VM과 네트워크 연결을 하는 방법 - 두 번째 이야기

지난번에 테스트한 글을,

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

아래의 글을 읽은 김에 한 번 더 해봤습니다. ^^

Allowing Windows Subsystem for Linux to communicate with Hyper-V VMs
; https://automatingops.com/allowing-windows-subsystem-for-linux-to-communicate-with-hyper-v-vms




Hyper-V를 호스팅하는 경우 WSL과 "Default Switch" 간의 네트워크는 분리돼 있습니다.

// Windows 호스팅 서버 (Hyper-V)에서 ipconfig 실행 결과

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::c52e:bcaf:7ccb:3114%36
   IPv4 Address. . . . . . . . . . . : 172.23.240.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (WSL (Hyper-V firewall)):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::ace:43c2:3a85:56b5%62
   IPv4 Address. . . . . . . . . . . : 172.18.208.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

// WSL 2 Ubuntu 20.04 인스턴스에서 ifconfig 실행 결과

eth0: flags=4163  mtu 1500
        inet 172.18.214.61  netmask 255.255.240.0  broadcast 172.18.223.255
        ...[생략]...

// Hyper-V VM에 설치된 윈도우 VM에서 ipconfig 실행 결과 (Default Switch에 연결된 경우)

Ethernet adapter 이더넷 3:

   Connection-specific DNS Suffix  . : mshome.net
   Link-local IPv6 Address . . . . . : fe80::c2d7:20ff:31bf:6e94%4
   IPv4 Address. . . . . . . . . . . : 172.23.240.28
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . : 172.23.240.1

따라서 호스트 측에서는 WSL 2와 VM 모두에 ping이 잘 동작합니다.

ping 172.18.214.61  // Host -> WSL 2: OK
ping 172.23.240.28  // Host -> VM: OK

반면, WSL 2와 VM 간의 ping은 모두 동작하지 않는데요, 이유는 기본적으로 중계를 하지 않기 때문입니다.

PS C:\temp> Get-NetIPInterface | where { $_.InterfaceAlias -eq 'vEthernet (WSL (Hyper-V firewall))' } | Select-Object ifIndex,InterfaceAlias,ConnectionState,Forwarding

ifIndex InterfaceAlias                     ConnectionState Forwarding
------- --------------                     --------------- ----------
     62 vEthernet (WSL (Hyper-V firewall))       Connected   Disabled // IPv6
     62 vEthernet (WSL (Hyper-V firewall))       Connected   Disabled // IPv4


PS C:\temp> Get-NetIPInterface | where { $_.InterfaceAlias -eq 'vEthernet (Default Switch)' } | Select-Object ifIndex,InterfaceAlias,ConnectionState,Forwarding

ifIndex InterfaceAlias             ConnectionState Forwarding
------- --------------             --------------- ----------
     36 vEthernet (Default Switch)       Connected   Disabled // IPv6
     36 vEthernet (Default Switch)       Connected   Disabled // IPv4

저렇게 Forwarding 설정이 꺼져 있는데요, 따라서 그걸 켜주면,

Get-NetIPInterface | where { $_.InterfaceAlias -eq 'vEthernet (WSL (Hyper-V firewall))' } | Set-NetIPInterface -Forwarding Enabled -Verbose

Get-NetIPInterface | where { $_.InterfaceAlias -eq 'vEthernet (Default Switch)' } | Set-NetIPInterface -Forwarding Enabled -Verbose

이후 서로 간에 ping이 잘 동작합니다.

ping 172.23.240.28  // WSL 2 -> VM: OK
ping 172.18.214.61  // VM -> WSL 2: OK

재미있는 건, 이러한 양방향 Forwarding은 "Default Switch"에 대해서만 가능하고, "Internal Network" 유형에 대해서는 약간 다른 동작을 합니다.

[VM 측이 Internal Network 유형인 경우]
VM -> WSL 2: Failed (Forwarding 설정 여부와 무관)
WSL 2 -> VM: OK (Forwarding 설정 여부와 무관)

지난 글을 쓸 때까지만 해도 WSL 2에서 (Internal Network에 속한) VM으로 불가능했던 것으로 아는데, 아마도 WSL 2 패치 과정에서 현재는 지원하게 된 것으로 보입니다. 반면 그 반대로 VM에서 WSL 2 인스턴스로는 ping이 되지 않습니다. 대신 ping을 제외하고는 일반적인 TCP/UDP 통신이라면 호스팅을 경유한 포트 포워딩으로 해결할 수 있을 텐데요, 단지 ping의 경우 ICMP 프로토콜이므로 포트가 없어 테스트할 수 없습니다.




한 가지 더 첨언하자면, 원래 ping을 위한 echo 요청은,

Windows 7/2008에서 ping을 위한 echo 요청 열기
; https://www.sysnet.pe.kr/2/0/780

Windows Defender Firewall with Advanced Security에서 "File and Printer Sharing" 범주의 ICMPv4-In, ICMPv6-In 규칙으로 제어합니다.

File and Printer Sharing (Echo Request - ICMPv4-In)
File and Printer Sharing (Echo Request - ICMPv6-In)

하지만, WSL 2 인스턴스에서 ("Default Switch"로 연결된) Hyper-V VM으로 ping을 하는 경우에는 저 규칙으로 열리지 않고 대신 "Virtual Machine Monitoring" 범주의 항목으로 열어야 합니다.

Virtual Machine Monitoring (Echo Request - ICMPv4-In)
Virtual Machine Monitoring (Echo Request - ICMPv6-In)

여기서 더 재미있는 것은, ("Default Switch"가 아닌) "Internal Network" 유형에 속한 VM인 경우에는 다시 "File and Printer Sharing" 범주의 ICMPv4-In, ICMPv6-In 규칙으로 열어야 WSL 2 인스턴스에서 ping이 됩니다. 마치, 윈도우 호스트 측에서 VM으로 ping을 하는 것과 유사하다고 볼 수 있습니다.




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







[최초 등록일: ]
[최종 수정일: 7/1/2024]

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

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  83  [84]  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11836정성태3/5/201923184오류 유형: 525. Visual Studio 2019 Preview 4/RC - C# 8.0 Missing compiler required member 'System.Range..ctor' [1]
11835정성태3/5/201921708.NET Framework: 810. C# 8.0의 Index/Range 연산자를 .NET Framework에서 사용하는 방법 및 비동기 스트림의 컴파일 방법 [3]파일 다운로드1
11834정성태3/4/201920550개발 환경 구성: 432. Visual Studio 없이 최신 C# (8.0) 컴파일러를 사용하는 방법
11833정성태3/4/201921051개발 환경 구성: 431. Visual Studio 2019 - CMake를 이용한 공유/실행(so/out) 리눅스 프로젝트 설정파일 다운로드1
11832정성태3/4/201916990오류 유형: 524. Visual Studio CMake - rsync: connection unexpectedly closed
11831정성태3/4/201916807오류 유형: 523. Visual Studio 2019 - 새 창으로 뜬 윈도우를 닫을 때 비정상 종료
11830정성태2/26/201916499오류 유형: 522. 이벤트 로그 - Error opening event log file State. Log will not be processed. Return code from OpenEventLog is 87.
11829정성태2/26/201918253개발 환경 구성: 430. 마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법 - 리눅스 환경 [1]
11828정성태2/26/201926126개발 환경 구성: 429. Component Services 관리자의 RuntimeBroker 설정이 2개 있는 경우 [8]
11827정성태2/26/201919049오류 유형: 521. Visual Studio - Could not start the 'rsync' command on the remote host, please install it using your system package manager.
11826정성태2/26/201919244오류 유형: 520. 우분투에 .NET Core SDK 설치 시 패키지 의존성 오류
11825정성태2/25/201924450개발 환경 구성: 428. Visual Studio 2019 - CMake를 이용한 리눅스 빌드 환경 설정 [1]
11824정성태2/25/201918891오류 유형: 519. The SNMP Service encountered an error while accessing the registry key SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration. [1]
11823정성태2/21/201920616오류 유형: 518. IIS 관리 콘솔이 뜨지 않는 문제
11822정성태2/20/201918908오류 유형: 517. docker에 설치한 MongoDB 서버로 연결이 안 되는 경우
11821정성태2/20/201919673오류 유형: 516. Visual Studio 2019 - This extension uses deprecated APIs and is at risk of not functioning in a future VS update. [1]
11820정성태2/20/201922741오류 유형: 515. 윈도우 10 1809 업데이트 후 "User Profiles Service" 1534 경고 발생
11819정성태2/20/201922025Windows: 158. 컴퓨터와 사용자의 SID(security identifier) 확인 방법
11818정성태2/20/201920066VS.NET IDE: 131. Visual Studio 2019 Preview의 닷넷 프로젝트 빌드가 20초 이상 걸리는 경우 [2]
11817정성태2/17/201916445오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201919851Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201918097오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
11814정성태2/12/201916963오류 유형: 512. VM(가상 머신)의 NT 서비스들이 자동 시작되지 않는 문제
11813정성태2/12/201918312.NET Framework: 809. C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
11812정성태2/11/201915609오류 유형: 511. Windows Server 2003 VM 부팅 후 로그인 시점에 0xC0000005 BSOD 발생
11811정성태2/11/201920793오류 유형: 510. 서버 운영체제에 NVIDIA GeForce Experience 실행 시 wlanapi.dll 누락 문제
... 76  77  78  79  80  81  82  83  [84]  85  86  87  88  89  90  ...