Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.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




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

비밀번호

댓글 작성자
 




... 121  122  123  124  125  126  127  128  129  130  [131]  132  133  134  135  ...
NoWriterDateCnt.TitleFile(s)
1780정성태10/15/201424139오류 유형: 249. The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID
1779정성태10/15/201419654오류 유형: 248. Active Directory에서 OU가 지워지지 않는 경우
1778정성태10/10/201418088오류 유형: 247. The Netlogon service could not create server share C:\Windows\SYSVOL\sysvol\[도메인명]\SCRIPTS.
1777정성태10/10/201421202오류 유형: 246. The processing of Group Policy failed. Windows attempted to read the file \\[도메인]\sysvol\[도메인]\Policies\{...GUID...}\gpt.ini
1776정성태10/10/201418203오류 유형: 245. 이벤트 로그 - Name resolution for the name _ldap._tcp.dc._msdcs.[도메인명]. timed out after none of the configured DNS servers responded.
1775정성태10/9/201419329오류 유형: 244. Visual Studio 디버깅 (2) - Unable to break execution. This process is not currently executing the type of code that you selected to debug.
1774정성태10/9/201426561개발 환경 구성: 246. IIS 작업자 프로세스의 20분 자동 재생(Recycle)을 끄는 방법
1773정성태10/8/201429743.NET Framework: 471. 웹 브라우저로 다운로드가 되는 파일을 왜 C# 코드로 하면 안되는 걸까요? [1]
1772정성태10/3/201418499.NET Framework: 470. C# 3.0의 기본 인자(default parameter)가 .NET 1.1/2.0에서도 실행될까? [3]
1771정성태10/2/201428023개발 환경 구성: 245. 실행된 프로세스(EXE)의 명령행 인자를 확인하고 싶다면 - Sysmon [4]
1770정성태10/2/201421645개발 환경 구성: 244. 매크로 정의를 이용해 파일 하나로 C++과 C#에서 공유하는 방법 [1]파일 다운로드1
1769정성태10/1/201424054개발 환경 구성: 243. Scala 개발 환경 구성(JVM, 닷넷) [1]
1768정성태10/1/201419440개발 환경 구성: 242. 배치 파일에서 Thread.Sleep 효과를 주는 방법 [5]
1767정성태10/1/201424597VS.NET IDE: 94. Visual Studio 2012/2013에서의 매크로 구현 - Visual Commander [2]
1766정성태10/1/201422415개발 환경 구성: 241. 책 "프로그래밍 클로저: Lisp"을 읽고 나서. [1]
1765정성태9/30/201425982.NET Framework: 469. Unity3d에서 transform을 변수에 할당해 사용하는 특별한 이유가 있을까요?
1764정성태9/30/201422234오류 유형: 243. 파일 삭제가 안 되는 경우 - The action can't be comleted because the file is open in System
1763정성태9/30/201423841.NET Framework: 468. PDB 파일을 연동해 소스 코드 라인 정보를 알아내는 방법파일 다운로드1
1762정성태9/30/201424520.NET Framework: 467. 닷넷에서 EIP/RIP 레지스터 값을 구하는 방법 [1]파일 다운로드1
1761정성태9/29/201421528.NET Framework: 466. 윈도우 운영체제의 보안 그룹 이름 및 설명 문자열을 바꾸는 방법파일 다운로드1
1760정성태9/28/201419794.NET Framework: 465. ICorProfilerInfo::GetILToNativeMapping 메서드가 0x80131358을 반환하는 경우
1759정성태9/27/201430961개발 환경 구성: 240. Visual C++ / x64 환경에서 inline-assembly를 매크로 어셈블리로 대체하는 방법파일 다운로드1
1758정성태9/23/201437791개발 환경 구성: 239. 원격 데스크톱 접속(RDP)을 기존의 콘솔 모드처럼 사용하는 방법 [1]
1757정성태9/23/201418373오류 유형: 242. Lync로 모임 참여 시 소리만 들리지 않는 경우 - 두 번째 이야기
1756정성태9/23/201427365기타: 48. NVidia 제품의 과다한 디스크 사용 [2]
1755정성태9/22/201434167오류 유형: 241. Unity Web Player를 설치해도 여전히 설치하라는 화면이 나오는 경우 [4]
... 121  122  123  124  125  126  127  128  129  130  [131]  132  133  134  135  ...