Skip to content

Commit 352b5d7

Browse files
updates to all
1 parent 5cc6413 commit 352b5d7

13 files changed

+1837
-652
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
/DSC/*
1515
hyperv.ps1
1616
configs.example.ps1
17-
*dtolab*
17+
*lab*
18+
*test*
1819

.images/network.png

71.6 KB
Loading

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change log for AzureSite2SiteVPNLab
22

3+
## 1.5.1 - April 22, 2024
4+
5+
- Changed the variable names for clarity
6+
- Fixed hub and spoke subnet creation
7+
- Fixed Azure login during context check
8+
- Added optionC script
9+
310
## 1.5.0 - May 21, 2022
411

512
- Added support for Azure Gov; updates location to use Virginia for site A and Arizona for site B

README.md

Lines changed: 92 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,50 @@
11
# Hybrid Lab Setup using Hyper-V and Azure Site-2-Site VPN
22

3+
A hybrid lab setup combines on-premises infrastructure with cloud resources to create a flexible and scalable environment for testing, development, to **mimic** production workloads. Azure Site-to-Site VPN extends your on-premises network to Azure, enabling secure and seamless communication between your on-premises environment and Azure resources.
34

4-
![Concept](/.images/concept.png)
5-
## Prereqs
5+
**In this setup:**
66

7-
- 1 or 2 Azure subscriptions (VSE or Trial will work)
8-
- Windows OS that will support Hyper-V (UEFI or TPM not needed)
9-
- Router with S2S IPSEC VPN capabilities __OR__ VyOS Router
10-
- This lab uses a virtual router called VyOS. The ISO can be found [**here**](https://s3.amazonaws.com/s3-us.VyOS.io/VyOS-1.1.8-amd64.iso). The script will auto download it
11-
- Home router is issuing IP (DHCP)
12-
- SSH utility with SCP and SSH-Keygen. These are installed with Git for Windows. You can get it [**here**](https://git-scm.com/downloads)
13-
- Azure PowerShell Modules installed (specifically **Az.Accounts, Az.Resources ,Az.Network, Az.Storage, Az.Compute**)
14-
- Partial knowledge with PowerShell
7+
1. Hyper-V: These script will install and configure Hyper-V on your "on-premises host" or workstation to create and manage virtual machines. These VMs can mimic various server roles, applications, or network configurations that you want to test or deploy.
8+
2. Azure Site-to-Site VPN: These script will configure a Site-to-Site VPN connection between your on-premises network and Azure Virtual Network. This VPN connection ensures that your on-premises resources can securely communicate with Azure resources over the Internet as if they are part of the same network.
159

16-
## Scripts
10+
**Benefits of this setup include:**
1711

18-
- **configs.ps1**. <-- This script is used to answer script values; linked to all scripts
19-
- _Advanced:_ You shouldn't have to change to much in the hashtables; recommend only changing the variable at top of script.
20-
- All scripts use this as an answer file for each setup. The answers are loaded in hashtable format and all of the required values are generated dynamically or will be prompted during execution
21-
- There are few things you should change on the top section:
22-
23-
```powershell
24-
$LabPrefix = 'contoso' #identifier for names in lab
12+
- **Scalability**: Easily add or remove virtual machines in Hyper-V or Azure based on your needs without significant hardware investments.
13+
- **Flexibility**: Test different scenarios or configurations in a sandboxed environment without affecting your production infrastructure.
14+
- **Security**: Securely connect your on-premises network to Azure using Site-to-Site VPN, ensuring data encryption and compliance with organizational security policies.
2515

26-
$domain = 'lab.contoso.com' #just a name for now (no DC install....yet)
16+
Overall, a hybrid lab setup using Hyper-V and Azure Site-to-Site VPN provides a powerful and flexible solution for testers looking to simulate a true on-premises and cloud resources effectively.
2717

28-
$Email = '' #used only in autoshutdown (for now)
18+
The script will setup whats in red:
19+
![Network](/.images/network.png)
2920

30-
#this is used to configure default username and password on Azure VM's
31-
$VMAdminUser = 'xAdmin'
32-
$VMAdminPassword = '<password>'
3321

34-
#NOTE: Make sure ALL subnets do not overlap!
35-
$OnPremSubnetCIDR = '10.120.0.0/16' #Always use /16
36-
$OnPremSubnetCount = 2
37-
38-
$RegionSiteAId = 'SiteA'
39-
$AzureSiteAHubCIDR = '10.23.0.0/16' #Always use /16
40-
$AzureSiteASpokeCIDR = '10.22.0.0/16' #Always use /16
41-
42-
$RegionSiteBId = 'SiteB'
43-
$AzureSiteBHubCIDR = '10.33.0.0/16' #Always use /16
44-
$AzureSiteBSpokeCIDR = '10.32.0.0/16' #Always use /16
45-
46-
$DHCPLocation = '<IP, server, or router>' #defaults to DHCP server not on router; assumes DHCP is on a server
47-
#if <router> is specified, DHCP server will be enabled but a full DHCP scope will be built for each subnets automatically (eg. 10.22.1.1-10.22.1.255)
48-
49-
$DNSServer = '<IP, IP addresses (comma delimitated), router>' #if not specified; defaults to fourth IP in spoke subnet scope (eg. 10.22.1.4). This would be Azure's first available IP for VM
50-
# if <router> is specified; google IP 8.8.8.8 will be used since no DNS server exist on router
22+
You can then use this network setup to build your environment. Here is an example:
23+
![Concept](/.images/concept.png)
5124

52-
$HyperVVMLocation = '<default>' #Leave as <default> for auto detect
53-
$HyperVHDxLocation = '<default>' #Leave as <default> for auto detect
25+
## Supported Environments
5426

55-
$VyOSIsoPath = '<default>' #Add path (eg. 'E:\ISOs\VyOS-1.1.8-amd64.iso') or use <latest> to get the latest VyOS ISO (this is still in BETA)
56-
#If path left blank or default, it will attempt to download the supported versions (1.1.8)
27+
- Azure Commercial
28+
- Azure Government High
5729

58-
$UseBGP = $false # not required for VPN, but can help. Costs more.
59-
#https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-bgp-overview
30+
## Prereqs
6031

61-
#used in step 5
62-
$AzureVnetToVnetPeering = @{
63-
SiteASubscriptionID = '<SubscriptionAID>'
64-
SiteATenantID= '<TenantAID>'
65-
SiteBSubscriptionID = '<SubscriptionBID>'
66-
SiteBTenantID = '<TenantBID>'
67-
}
32+
- 1 or 2 Azure subscriptions (VSE or Trial will work)
33+
- Windows OS that will support Hyper-V
34+
- Internet connectivity
35+
- Home router to issue IP to virtual router (vYOS)
36+
- SSH utility with SCP and SSH-Keygen. These are installed with _Git for Windows_. You can get it [**here**](https://git-scm.com/downloads)
37+
- Azure PowerShell Modules installed (specifically **Az.Accounts, Az.Resources ,Az.Network, Az.Storage, Az.Compute**)
38+
- Partial knowledge with PowerShell and Azure modules
6839

69-
#Uses Git, SSH and SCP to build VyOS router
70-
# 99% automated; but 90% successful
71-
$RouterAutomationMode = $True
40+
## Scripts
7241

73-
```
42+
- **configs.ps1**. <-- This script is used to answer script values; linked to all scripts
43+
- Make sure you edit the variables in the top section under the _General Configurations_
44+
- _Advanced:_ Recommend you don't make changed in this section
45+
- All scripts use this as an answer file for each setup. The answers are loaded in hashtable format and all of the required values are generated dynamically or will be prompted during execution
46+
47+
## Helper Functions
7448

7549
- **library.ps1** <-- Custom functions used for common automation
7650
- **network.ps1** <-- Custom functions used to generating network subnets
@@ -100,33 +74,52 @@ This script does a few things:
10074
- Setups the VyOS basic configuration (manual steps required)
10175
- Established SSH to VyOS and attempts auto configurations for LAN network
10276
- You will be prompted to make configurations to the router. Also once SSH is established the script will generate RSA key to auto logon.
103-
This is a temporary process because VyOS does not save authorized_keys. if login is successful, it will auto configure the VyOS router for you otherwise you will be presented with a copy/paste configurations.
77+
> This is a temporary process because VyOS does not save authorized_keys. if login is successful, it will auto configure the VyOS router for you otherwise you will be presented with a copy/paste configurations.
78+
- If ssh does not work, you can manually run the scripts within the VM. Scripts are exported to log folder for each step
79+
80+
- Change the value to something like this:
10481

105-
Change the value to something like this:
10682
```powershell
107-
$VyOSIsoPath = 'D:\ISOs\VyOS-1.1.8-amd64.iso'
83+
$VyOSIsoPath = 'D:\ISOs\VyOS-1.1.8-amd64.iso'
10884
```
10985

11086
## Azure VPN Lab
11187
There are few options when building the Site2Site VPN lab:
11288

113-
_Option A_: **Step 3A. Build Azure Basic S2S.ps1** <-- Sets up a very basic azure S2S VPN , no hub and spoke configurations.
89+
### Option A: Simple Network
11490

115-
_Option B_: **Step 3B-1. Build Azure Advanced S2S - Region 1.ps1** <--Sets up a more complex Azure S2S VPN with hub and spoke design. Also run scripts:
91+
- **Step 3A. Build Azure Basic S2S.ps1** <-- Sets up a very basic azure S2S VPN , no hub and spoke configurations.
11692

117-
1. **Step 3B-2. Build Azure Advanced S2S - Region 2.ps1** <-- Optional if you want to setup a second site
118-
2. **Step 3B-3. Connect Azure Advanced S2S Regions.ps1** <-- Only Required if a second site is setup
93+
### Option B: Hub and Spoke
11994

120-
_Option C_: **Step 3C. Attach Azure S2S to Existing Network.ps1** <-- Connect to an existing Azure network. You must run it like this:
95+
- **Step 3B-1. Build Azure Advanced S2S - TenantA.ps1** <--Sets up a more complex Azure S2S VPN with hub and spoke design. Also run scripts:
12196

122-
<span style="background-color:Yellow;">**NOTE: If connected to Azure, hit tab for the virtualNetwork and Resourcegroup values to iterate through existing Azure resources. </span>
97+
1. **Step 3B-2. Build Azure Advanced S2S - TenantB.ps1** <-- Optional if you want to setup a second site
98+
2. **Step 3B-3. Connect Azure Advanced S2S Tenants.ps1** <-- Only Required if a second site is setup
99+
100+
### Option C: Existing network
101+
102+
- **Step 3C. Attach Azure S2S to Existing Network.ps1** <-- Connect to an existing Azure network. You must run it like this:
103+
104+
<span style="background-color:Orange;">**NOTE: If connected to Azure, hit tab for the virtualNetwork and Resourcegroup values to iterate through existing Azure resources. </span>
123105
```powershell
124106
& '.\Step 3C. Attach Azure S2S to Existing Network.ps1' -Prefix MECMCBLAB -ResourceGroup mecmcb-lab-rg -vNet mecmcblab-vnet -DnsIp 10.0.0.4 -RemovePublicIps -EnableVMAutoShutdown -AttachNsg -Force
125107
```
126108

127109
<span style="background-color:Red;">**IMPORTANT**: All scripts list above can be ran multiple times! If ran a second time, it will check all configurations and attempt to repair and issues. this can be useful when public IP has changed on home network</span>
128110

129-
If all went well, the VyOS router will connect each Azure site.
111+
### Validate connection
112+
113+
If all went well, the VyOS router will connect each Azure site. You can check it two ways:
114+
115+
1. Run command on router:
116+
117+
```cmd
118+
show vpn ipsec sa
119+
```
120+
121+
2. Go to Azure Portal --> Local Network Gateways --> Click on gateway --> Connections
122+
130123
### Azure VM
131124

132125
The last thing to do is setup a VM in your Azure lab without Public IP and connect to it from you hyper-V vm. This is a good test to see if your VPN is connected
@@ -136,16 +129,16 @@ To setup a VM, run the script corresponding to the type of Azure VPN you set up
136129

137130
_Option 1_: **Step 4A-1. Build Azure VM.ps1**
138131

139-
_Option 2_: **Step 4B-1. Build Azure VM - Region 1.ps1**
132+
_Option 2_: **Step 4B-1. Build Azure VM - TenantA.ps1**
140133

141134
_Option 3_ Run scripts:
142135

143-
1. **Step 4B-1. Build Azure VM - Region 1.ps1**
144-
2. **Step 4B-2. Build Azure VM - Region 2.ps1**
136+
1. **Step 4B-1. Build Azure VM - TenantA.ps1**
137+
2. **Step 4B-2. Build Azure VM - TenantB.ps1**
145138

146-
_BETA_: **Step 4A-2. Build Hyper-V VM.ps1** <-- Sets up a VM in Hyper-V (not unattended)
139+
_BETA_: **Step 4C. Build Hyper-V VM.ps1** <-- Sets up a VM in Hyper-V (not unattended)
147140

148-
<span style="background-color:Yellow;">**IMPORTANT**: All scripts list above can be ran multiple times! If ran a second time, The script with create another VM incrementing the name automatically or you can specify an name like so:</span>
141+
<span style="background-color:Orange;">**IMPORTANT**: All scripts list above can be ran multiple times! If ran a second time, The script with create another VM incrementing the name automatically or you can specify an name like so:</span>
149142
```powershell
150143
& '.\Step 4A. Build Azure VM.ps1' -VMName 'contoso-dc1'
151144
```
@@ -155,14 +148,19 @@ _BETA_: **Step 4A-2. Build Hyper-V VM.ps1** <-- Sets up a VM in Hyper-V (not una
155148
## Known Issues
156149

157150
- Some devices have reduce network quality with hyper-v's external switch connecting to WiFi adapter. Recommend using physical adapter if possible
158-
- Some ISP's (especially hotels) don't allow public IP to pulled from web crawlers such as http://ipinfo.io/json; this could be an issue with setting up Site-2-Site-VPN
151+
- Some ISP's (especially hotels) don't allow public IP to pulled from web crawlers such as http://ipinfo.io/json; this can be an issue with when the script is setting up Site-2-Site-VPN
159152
- Some ISP's may not allow VPN traffic; no know work around for this
160-
- These scripts have not been tested with Azure Gov or other Azure community clouds
161153
- After Site 2 Site VPN is created; step that check for connectivity may show _unknown) or _not connected_; this may be due to Azure's graph api call not updating immediately. Recommend manual check
162154
- Go to Azure Portal --> Local Network Gateways --> Click on new gateway --> Connections
163-
- VyOS router will remove it trusted ssh host list on each reboot. This is by design and will require login for each script implementation; looking for alternate method to resolve this
155+
- VyOS router will remove it trusted ssh host list on each reboot. This is by design and will require login for each script implementation; looking for alternate method to resolve this.
164156
- There are known issues with the PowerShell ISE interface during VyOS configurations; Recommend running with Powershell console or VScode.
165157

158+
## Not Supported
159+
160+
- These scripts have not been tested on Azure clouds other than what is stated in supported section
161+
- Target multiple subscriptions per tenant (such as [Mission LZ](https://github.com/Azure/missionlz))
162+
- Vnet peering between Azure and Azure Gov is NOT supported
163+
166164
## References
167165

168166
- [Create a VPN Gateway and add a Site-to-Site connection using PowerShell](https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-create-site-to-site-rm-powershell)
@@ -175,3 +173,22 @@ _BETA_: **Step 4A-2. Build Hyper-V VM.ps1** <-- Sets up a VM in Hyper-V (not una
175173
- [Configuring Azure Site-to-Site connectivity using VyOS Behind a NAT – Part 3](http://www.lewisroberts.com/2015/07/17/configuring-azure-site-to-site-connectivity-using-VyOS-behind-a-nat-part-3/)
176174
- [BUILD A HYBRID CLOUD LAB INTO MICROSOFT AZURE WITH VyOS](https://bretty.me.uk/build-a-hybrid-cloud-lab-into-microsoft-azure-with-VyOS/)
177175
- [VyOS Site-to-Site](https://VyOS.readthedocs.io/en/latest/vpn/site2site_ipsec.html)
176+
177+
# DISCLAIMER
178+
This Sample Code is provided for the purpose of illustration only and is not
179+
intended to be used in a production environment. THIS SAMPLE CODE AND ANY
180+
RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
181+
EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
182+
MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We grant You a
183+
nonexclusive, royalty-free right to use and modify the Sample Code and to
184+
reproduce and distribute the object code form of the Sample Code, provided
185+
that You agree: (i) to not use Our name, logo, or trademarks to market Your
186+
software product in which the Sample Code is embedded; (ii) to include a valid
187+
copyright notice on Your software product in which the Sample Code is embedded;
188+
and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and
189+
against any claims or lawsuits, including attorneys’ fees, that arise or result
190+
from the use or distribution of the Sample Code.
191+
192+
This posting is provided "AS IS" with no warranties, and confers no rights. Use
193+
of included script samples are subject to the terms specified
194+
at https://www.microsoft.com/en-us/legal/copyright.

Step 3A. Build Azure Simple S2S.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Else{
7070
#endregion
7171

7272
#region start transcript
73-
$LogfileName = "$RegionName-AzureSimpleS2S-$(Get-Date -Format 'yyyy-MM-dd_Thh-mm-ss-tt').log"
73+
$LogfileName = "$SiteName-AzureSimpleS2S-$(Get-Date -Format 'yyyy-MM-dd_Thh-mm-ss-tt').log"
7474
Try{Start-transcript "$PSScriptRoot\Logs\$LogfileName" -ErrorAction Stop}catch{Start-Transcript "$PSScriptRoot\$LogfileName"}
7575
#endregion
7676

@@ -396,7 +396,7 @@ set vpn ipsec site-to-site peer $($azpip.IpAddress) authentication mode 'pre-sha
396396
set vpn ipsec site-to-site peer $($azpip.IpAddress) authentication pre-shared-secret '$($Global:SharedPSK)'
397397
set vpn ipsec site-to-site peer $($azpip.IpAddress) connection-type 'initiate'
398398
set vpn ipsec site-to-site peer $($azpip.IpAddress) default-esp-group 'azure'
399-
set vpn ipsec site-to-site peer $($azpip.IpAddress) description '$($AzureSimpleConfig.TunnelDescription) ($($AzureAdvConfigSiteA.LocationName))'
399+
set vpn ipsec site-to-site peer $($azpip.IpAddress) description '$($AzureSimpleConfig.TunnelDescription) ($($AzureAdvConfigTenantA.LocationName))'
400400
set vpn ipsec site-to-site peer $($azpip.IpAddress) ike-group 'azure-ike'
401401
set vpn ipsec site-to-site peer $($azpip.IpAddress) ikev2-reauth 'inherit'
402402
set vpn ipsec site-to-site peer $($azpip.IpAddress) local-address '$($VyOSExternalIP)'

0 commit comments

Comments
 (0)