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)
11847정성태3/17/201915206Linux: 7. 리눅스 C/C++ - 공유 라이브러리 동적 로딩 후 export 함수 사용 방법파일 다운로드1
11846정성태3/15/201913577Linux: 6. getenv, setenv가 언어/운영체제마다 호환이 안 되는 문제
11845정성태3/15/201914296Linux: 5. Linux 응용 프로그램의 (C++) so 의존성 줄이기(ReleaseMinDependency) [3]
11844정성태3/14/201915124개발 환경 구성: 434. Visual Studio 2019 - 리눅스 프로젝트를 이용한 공유/실행(so/out) 프로그램 개발 환경 설정 [1]파일 다운로드1
11843정성태3/14/201910860기타: 75. MSDN 웹 사이트를 기본으로 영문 페이지로 열고 싶다면?
11842정성태3/13/201910269개발 환경 구성: 433. 마이크로소프트의 CoreCLR 프로파일러 예제를 Visual Studio CMake로 빌드하는 방법 [1]파일 다운로드1
11841정성태3/13/201910237VS.NET IDE: 132. Visual Studio 2019 - CMake의 컴파일러를 기본 g++에서 clang++로 변경
11840정성태3/13/201911340오류 유형: 526. 윈도우 10 Ubuntu App 환경에서는 USB 외장 하드 접근 불가
11839정성태3/12/201914109디버깅 기술: 124. .NET Core 웹 앱을 호스팅하는 Azure App Services의 프로세스 메모리 덤프 및 windbg 분석 개요 [3]
11838정성태3/7/201916860.NET Framework: 811. (번역글) .NET Internals Cookbook Part 1 - Exceptions, filters and corrupted processes [1]파일 다운로드1
11837정성태3/6/201926613기타: 74. 도서: 시작하세요! C# 7.3 프로그래밍 [10]
11836정성태3/5/201914416오류 유형: 525. Visual Studio 2019 Preview 4/RC - C# 8.0 Missing compiler required member 'System.Range..ctor' [1]
11835정성태3/5/201914189.NET Framework: 810. C# 8.0의 Index/Range 연산자를 .NET Framework에서 사용하는 방법 및 비동기 스트림의 컴파일 방법 [3]파일 다운로드1
11834정성태3/4/201913075개발 환경 구성: 432. Visual Studio 없이 최신 C# (8.0) 컴파일러를 사용하는 방법
11833정성태3/4/201913838개발 환경 구성: 431. Visual Studio 2019 - CMake를 이용한 공유/실행(so/out) 리눅스 프로젝트 설정파일 다운로드1
11832정성태3/4/201910871오류 유형: 524. Visual Studio CMake - rsync: connection unexpectedly closed
11831정성태3/4/201910458오류 유형: 523. Visual Studio 2019 - 새 창으로 뜬 윈도우를 닫을 때 비정상 종료
11830정성태2/26/201910244오류 유형: 522. 이벤트 로그 - Error opening event log file State. Log will not be processed. Return code from OpenEventLog is 87.
11829정성태2/26/201912145개발 환경 구성: 430. 마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법 - 리눅스 환경 [1]
11828정성태2/26/201918554개발 환경 구성: 429. Component Services 관리자의 RuntimeBroker 설정이 2개 있는 경우 [8]
11827정성태2/26/201912462오류 유형: 521. Visual Studio - Could not start the 'rsync' command on the remote host, please install it using your system package manager.
11826정성태2/26/201912344오류 유형: 520. 우분투에 .NET Core SDK 설치 시 패키지 의존성 오류
11825정성태2/25/201917209개발 환경 구성: 428. Visual Studio 2019 - CMake를 이용한 리눅스 빌드 환경 설정 [1]
11824정성태2/25/201912018오류 유형: 519. The SNMP Service encountered an error while accessing the registry key SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration. [1]
11823정성태2/21/201913506오류 유형: 518. IIS 관리 콘솔이 뜨지 않는 문제
11822정성태2/20/201911638오류 유형: 517. docker에 설치한 MongoDB 서버로 연결이 안 되는 경우
... 61  62  63  64  65  66  67  68  69  70  71  [72]  73  74  75  ...