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

(시리즈 글이 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




Hyper-V Internal 네트워크에 NAT을 이용한 인터넷 연결 제공

Hyper-V의 Internal network 유형은,

Hyper-V의 네트워크 유형 (1)
; https://www.sysnet.pe.kr/2/0/910#internal

VM끼리의 통신과, VM - Host 간의 통신은 제공하지만 인터넷으로의 연결은 안 됩니다. 이런 제약은 ICS(Internet Connection Sharing)를 Internal에 제공해 해결할 수 있지만,

Hyper-V의 네트워크 유형 (2)
; https://www.sysnet.pe.kr/2/0/915

개인적으로는, 그냥 VM에 External과 Internal을 동시에 제공하는 것을 선호합니다. (그래서 보통, External은 동적 IP로, Internal은 정적 IP로 설정해 둡니다.)




예전에 "Windows Virtual PC"를 사용하신 분은, Hyper-V에서는 제공하지 않는 "NAT" 유형의 네트워크를 기억하실 텐데요,

Windows Virtual PC 의 네트워크 유형 (1)
; https://www.sysnet.pe.kr/2/0/906#nat

아쉽게도 이런 유형을 Hyper-V에서는 제공하지 않습니다. 그런데, "명시적"으로만 제공하지 않았을 뿐 원한다면 사용자가 직접 구성하는 것이 가능한데요,

Set up a NAT network
; https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/setup-nat-network

Hyper-V NAT w/ Linux VM
; https://medium.com/@mdavis332/hyper-v-nat-w-linux-vm-1d245be6ded1

예를 들어, 기존에 "HyperVInternal"이라는 Internal 유형의 네트워크가 있을 때,

internet_with_internal_and_nat_0.png

호스트와 VM의 네트워크 설정이 각각 다음과 같다고 가정해 보겠습니다.

//////////////////// 호스트 측
C:\temp> ipconfig

...[생략]...

Ethernet adapter vEthernet (HyperVInternal):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::e1cb:997b:a4a6:d7aa%61
   Autoconfiguration IPv4 Address. . : 169.254.215.170
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

//////////////////// VM 측
C:\temp> ipconfig

...[생략]...

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : kornet
   Link-local IPv6 Address . . . . . : fe80::c564:42e0:8fb3:3d66%8
   Autoconfiguration IPv4 Address. . : 169.254.61.102
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

그럼, 이 네트워크 영역을 NAT에 포함시킬 수 있습니다.

PS C:\temp> New-NetNat -Name "NATNetwork" -InternalIPInterfaceAddressPrefix 169.254.0.0/16

Name                             : NATNetwork
ExternalIPInterfaceAddressPrefix :
InternalIPInterfaceAddressPrefix : 169.254.0.0/16
IcmpQueryTimeout                 : 30
TcpEstablishedConnectionTimeout  : 1800
TcpTransientConnectionTimeout    : 120
TcpFilteringBehavior             : AddressDependentFiltering
UdpFilteringBehavior             : AddressDependentFiltering
UdpIdleSessionTimeout            : 120
UdpInboundRefresh                : False
Store                            : Local
Active                           : True

그런 다음, VM 측의 Default Gateway를 다음과 같이 호스트 측의 "vEthernet (HyperVInternal)" IP로 설정합니다.

internet_with_internal_and_nat_2.png

(위의 그림에서는, 고정 IP 할당 없이 default gateway를 설정하느라 "Advanced..." 기능을 통해 복잡하게 했지만, 고정 IP를 할당한다면 그냥 인터넷 속성 창에서 IP와 함께 Default gateway를 직접 지정해도 됩니다.)

이렇게 NAT으로 연결해 주면, 이제 VM의 Internal 네트워크는 호스트 측의 NAT 기능을 이용해 인터넷 영역으로 정상적으로 통신이 가능합니다. 게다가 일단 한 번 이렇게 설정해 두면, 이후의 VM들은 Default Gateway를 설정하는 것만으로 간단하게 Internal 유형으로 Internet 연결이 가능합니다.




참고로, "Set up a NAT network" 글에서 다루는 PowerShell 명령어를 이번 기회에 익혀 보겠습니다. ^^

우선, Hyper-V의 가상 스위치를 관리 콘솔을 이용하지 않고도 다음과 같이 생성할 수 있습니다.

PS C:\Windows\System32> New-VMSwitch -SwitchName "HyperVInternal" -SwitchType Internal

그런 다음, 호스트 측의 (ipconfig을 이용해 알 수 있지만) vEthernet에 할당된 IP를 알아낼 수도 있고,

PS C:\Windows\System32> Get-NetIPAddress -InterfaceAlias "vEthernet (HyperVInternal)"

IPAddress         : fe80::e1cb:997b:a4a6:d7aa%61
InterfaceIndex    : 61
InterfaceAlias    : vEthernet (HyperVInternal)
AddressFamily     : IPv6
Type              : Unicast
PrefixLength      : 64
PrefixOrigin      : WellKnown
SuffixOrigin      : Link
AddressState      : Preferred
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

IPAddress         : 169.254.215.170
InterfaceIndex    : 61
InterfaceAlias    : vEthernet (HyperVInternal)
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 16
PrefixOrigin      : WellKnown
SuffixOrigin      : Link
AddressState      : Preferred
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

혹은 강제로 설정할 수도 있습니다.

PS C:\Windows\System32> New-NetIPAddress -IPAddress 192.168.100.1 -PrefixLength 24 -InterfaceAlias "vEthernet (HyperVInternal)"

IPAddress         : 192.168.100.1
InterfaceIndex    : 65
InterfaceAlias    : vEthernet (NatTest)
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Tentative
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

IPAddress         : 192.168.100.1
InterfaceIndex    : 65
InterfaceAlias    : vEthernet (NatTest)
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Invalid
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : PersistentStore

/*
또는, netsh을 이용해

netsh interface ip set address name="vEthernet (HyperVInternal)" static 192.168.100.1 255.255.255.0
*/

만약, 위와 같이 가상 스위치에 연결된 호스트 측의 어댑터 IP를 "192.168.100.1"로 지정한 Internal 네트워크에 대해 NAT 서비스를 제공하고 싶다면 New-NetNat 명령어를 다음과 같은 옵션으로 실행해야 합니다.

PS C:\Windows\System32> New-NetNat -Name "NATNetwork" -InternalIPInterfaceAddressPrefix 192.168.100.0/24

Name                             : NATNetwork
ExternalIPInterfaceAddressPrefix :
InternalIPInterfaceAddressPrefix : 192.168.100.0/24
IcmpQueryTimeout                 : 30
TcpEstablishedConnectionTimeout  : 1800
TcpTransientConnectionTimeout    : 120
TcpFilteringBehavior             : AddressDependentFiltering
UdpFilteringBehavior             : AddressDependentFiltering
UdpIdleSessionTimeout            : 120
UdpInboundRefresh                : False
Store                            : Local
Active                           : True

하지만 해당 LAN 어댑터가 DHCP 기능을 제공하는 것은 아니므로, VM은 여전히 "169.254.x.x" 등의 IP로 기본 설정되며 따라서 위와 같이 IP를 바꾼 경우에는 VM 측의 IP도 "192.168.100.x" 대역으로 직접 설정해야 합니다.

internet_with_internal_and_nat_1.png




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







[최초 등록일: ]
[최종 수정일: 3/9/2024]

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

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  70  71  72  73  [74]  75  ...
NoWriterDateCnt.TitleFile(s)
11797정성태12/19/201810582개발 환경 구성: 425. vcpkg - CMake Error: Problem with archive_write_header(): Can't create '' 빌드 오류
11796정성태12/19/201810230개발 환경 구성: 424. vcpkg - "File does not have expected hash" 오류를 무시하는 방법
11795정성태12/19/201812662Windows: 154. PowerShell - Zone 별로 DNS 레코드 유형 정보 조회 [1]
11794정성태12/16/201810010오류 유형: 508. Get-AzureWebsite : Request to a downlevel service failed.
11793정성태12/16/201811656개발 환경 구성: 423. NuGet 패키지 제작 - Native와 Managed DLL을 분리하는 방법 [1]
11792정성태12/11/201812408Graphics: 34. .NET으로 구현하는 OpenGL (11) - Per-Pixel Lighting파일 다운로드1
11791정성태12/11/201812420VS.NET IDE: 130. C/C++ 프로젝트의 시작 프로그램으로 .NET Core EXE를 지정하는 경우 닷넷 디버깅이 안 되는 문제 [1]
11790정성태12/11/201810737오류 유형: 507. Could not save daemon configuration to C:\ProgramData\Docker\config\daemon.json: Access to the path 'C:\ProgramData\Docker\config' is denied.
11789정성태12/10/201820642Windows: 153. C# - USB 장치의 연결 및 해제 알림을 위한 WM_DEVICECHANGE 메시지 처리 [2]파일 다운로드2
11788정성태12/4/201810555오류 유형: 506. SqlClient - Value was either too large or too small for an Int32.Couldn't store <2151292191> in ... Column
11787정성태11/29/201814532Graphics: 33. .NET으로 구현하는 OpenGL (9), (10) - OBJ File Format, Loading 3D Models파일 다운로드1
11786정성태11/29/201811175오류 유형: 505. OpenGL.NET 예제 실행 시 "Managed Debugging Assistant 'CallbackOnCollectedDelegate'" 예외 발생
11785정성태11/21/201813600디버깅 기술: 120. windbg 분석 사례 - ODP.NET 사용 시 Finalizer에서 System.AccessViolationException 예외 발생으로 인한 비정상 종료
11784정성태11/18/201813294Graphics: 32. .NET으로 구현하는 OpenGL (7), (8) - Matrices and Uniform Variables, Model, View & Projection Matrices파일 다운로드1
11783정성태11/18/201811384오류 유형: 504. 윈도우 환경에서 docker가 설치된 컴퓨터 간의 ping IP 주소 풀이 오류
11782정성태11/18/201811153Windows: 152. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선순위 조정 기능 - 두 번째 이야기
11781정성태11/17/201813367개발 환경 구성: 422. SFML.NET 라이브러리 설정 방법 [1]파일 다운로드1
11780정성태11/17/201814843오류 유형: 503. vcpkg install bzip2 빌드 에러 - "Error: Building package bzip2:x86-windows failed with: BUILD_FAILED"
11779정성태11/17/201815227개발 환경 구성: 421. vcpkg 업데이트 [1]
11778정성태11/14/201813016.NET Framework: 803. UWP 앱에서 한 컴퓨터(localhost, 127.0.0.1) 내에서의 소켓 연결
11777정성태11/13/201812037오류 유형: 502. Your project does not reference "..." framework. Add a reference to "..." in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
11776정성태11/13/201811287.NET Framework: 802. Windows에 로그인한 계정이 마이크로소프트의 계정인지, 로컬 계정인지 알아내는 방법
11775정성태11/13/201813832Graphics: 31. .NET으로 구현하는 OpenGL (6) - Texturing파일 다운로드1
11774정성태11/8/201811687Graphics: 30. .NET으로 구현하는 OpenGL (4), (5) - Shader파일 다운로드1
11773정성태11/7/201811451Graphics: 29. .NET으로 구현하는 OpenGL (3) - Index Buffer파일 다운로드1
11772정성태11/6/201813735Graphics: 28. .NET으로 구현하는 OpenGL (2) - VAO, VBO파일 다운로드1
... 61  62  63  64  65  66  67  68  69  70  71  72  73  [74]  75  ...