mirror of
				https://github.com/shokinn/.files.git
				synced 2025-11-03 20:18:10 +00:00 
			
		
		
		
	Add script to enable forwarding
on Windows network interfaces to get access to Hyper-V VMs
This commit is contained in:
		
							parent
							
								
									066af88bf1
								
							
						
					
					
						commit
						4438299f33
					
				
					 2 changed files with 53 additions and 3 deletions
				
			
		
							
								
								
									
										14
									
								
								config.yaml
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								config.yaml
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -18,9 +18,6 @@ actions:
 | 
			
		|||
    [[ ! -d ${{ZSH_CUSTOM:-${{HOME}}/.oh-my-zsh/custom}}/themes ]] && mkdir -p ${{ZSH_CUSTOM:-${{HOME}}/.oh-my-zsh/custom}}/themes || echo "do nothing" >/dev/null
 | 
			
		||||
    [[ ! -d ${{ZSH_CUSTOM:-${{HOME}}/.oh-my-zsh/custom}}/themes/powerlevel10k ]] && git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${{ZSH_CUSTOM:-${{HOME}}/.oh-my-zsh/custom}}/themes/powerlevel10k || echo "do nothing" >/dev/null
 | 
			
		||||
dotfiles:
 | 
			
		||||
  f_addhypervroute:
 | 
			
		||||
    dst: ~/.bin/addhypervroute
 | 
			
		||||
    src: bin/addhypervroute
 | 
			
		||||
  d_bspwm:
 | 
			
		||||
    dst: ~/.config/bspwm
 | 
			
		||||
    src: config/bspwm
 | 
			
		||||
| 
						 | 
				
			
			@ -111,6 +108,12 @@ dotfiles:
 | 
			
		|||
  f_kite:
 | 
			
		||||
    src: local/bin/kite
 | 
			
		||||
    dst: ~/.local/bin/kite
 | 
			
		||||
  f_addhypervroute:
 | 
			
		||||
    dst: ~/.bin/addhypervroute
 | 
			
		||||
    src: bin/addhypervroute
 | 
			
		||||
  f_enablewslhypervforwarding:
 | 
			
		||||
    dst: ~/.bin/enablewslhypervforwarding
 | 
			
		||||
    src: bin/enablewslhypervforwarding
 | 
			
		||||
profiles:
 | 
			
		||||
  AINCRAD:
 | 
			
		||||
    dotfiles:
 | 
			
		||||
| 
						 | 
				
			
			@ -133,6 +136,7 @@ profiles:
 | 
			
		|||
    - f_start_systemd_shell.sh
 | 
			
		||||
    - f_dotdrop.sh
 | 
			
		||||
    - f_addhypervroute
 | 
			
		||||
    - f_enablewslhypervforwarding
 | 
			
		||||
  AINCRAD-wsl:
 | 
			
		||||
    dotfiles:
 | 
			
		||||
    - d_fonts
 | 
			
		||||
| 
						 | 
				
			
			@ -154,6 +158,7 @@ profiles:
 | 
			
		|||
    - f_start_systemd_shell.sh
 | 
			
		||||
    - f_dotdrop.sh
 | 
			
		||||
    - f_addhypervroute
 | 
			
		||||
    - f_enablewslhypervforwarding
 | 
			
		||||
  yoetunheimr:
 | 
			
		||||
    dotfiles:
 | 
			
		||||
    - d_bspwm
 | 
			
		||||
| 
						 | 
				
			
			@ -182,6 +187,7 @@ profiles:
 | 
			
		|||
    - f_c3check
 | 
			
		||||
    - f_dotdrop.sh
 | 
			
		||||
    - f_addhypervroute
 | 
			
		||||
    - f_enablewslhypervforwarding
 | 
			
		||||
  YOETUNHEIMR-wsl:
 | 
			
		||||
    dotfiles:
 | 
			
		||||
    - d_fonts
 | 
			
		||||
| 
						 | 
				
			
			@ -203,6 +209,7 @@ profiles:
 | 
			
		|||
    - f_start_systemd_shell.sh
 | 
			
		||||
    - f_dotdrop.sh
 | 
			
		||||
    - f_addhypervroute
 | 
			
		||||
    - f_enablewslhypervforwarding
 | 
			
		||||
  ymir:
 | 
			
		||||
    dotfiles:
 | 
			
		||||
    - f_zshrc
 | 
			
		||||
| 
						 | 
				
			
			@ -221,6 +228,7 @@ profiles:
 | 
			
		|||
    - f_c3check
 | 
			
		||||
    - f_dotdrop.sh
 | 
			
		||||
    - f_addhypervroute
 | 
			
		||||
    - f_enablewslhypervforwarding
 | 
			
		||||
  workspace:
 | 
			
		||||
    dotfiles:
 | 
			
		||||
    - d_fonts
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										42
									
								
								dotfiles/bin/enablewslhypervforwarding
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										42
									
								
								dotfiles/bin/enablewslhypervforwarding
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,42 @@
 | 
			
		|||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# {{@@ header() @@}}
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
WINHOME="$(echo "$(cmd.exe /C "echo %USERPROFILE%")" | tr -d '\r')"
 | 
			
		||||
WINHOMEWSL="$(wslpath ${WINHOME})"
 | 
			
		||||
 | 
			
		||||
cat <<EOF > "${WINHOMEWSL}/enablewslhypervforwarding.ps1"
 | 
			
		||||
#at top of script
 | 
			
		||||
if (!
 | 
			
		||||
    #current role
 | 
			
		||||
    (New-Object Security.Principal.WindowsPrincipal(
 | 
			
		||||
        [Security.Principal.WindowsIdentity]::GetCurrent()
 | 
			
		||||
    #is admin?
 | 
			
		||||
    )).IsInRole(
 | 
			
		||||
        [Security.Principal.WindowsBuiltInRole]::Administrator
 | 
			
		||||
    )
 | 
			
		||||
) {
 | 
			
		||||
    #elevate script and exit current non-elevated runtime
 | 
			
		||||
    Start-Process \`
 | 
			
		||||
        -FilePath 'powershell' \`
 | 
			
		||||
        -ArgumentList (
 | 
			
		||||
            #flatten to single array
 | 
			
		||||
            '-File', \$MyInvocation.MyCommand.Source, \$args \`
 | 
			
		||||
            | %{ \$_ }
 | 
			
		||||
        ) \`
 | 
			
		||||
        -Verb RunAs
 | 
			
		||||
    exit
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Set-NetIPInterface -ifAlias "vEthernet (Default Switch)" -Forwarding Enabled
 | 
			
		||||
Set-NetIPInterface -ifAlias "vEthernet (WSL)" -Forwarding Enabled
 | 
			
		||||
 | 
			
		||||
EOF
 | 
			
		||||
 | 
			
		||||
powershell.exe "${WINHOME}\enablewslhypervforwarding.ps1"
 | 
			
		||||
powershell.exe "Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
rm ${WINHOMEWSL}/enablewslhypervforwarding.ps1
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue