Showing posts with label route. Show all posts
Showing posts with label route. Show all posts

Monday, March 2, 2015

Powershell: SkipAsSource Flag

Finally ran into an issue where the removal of the primary ip address after Server 2003 caused an issue. Since if you have a multihomed nic the routing table will be set to use the closest IP address to the gateway as the source interface. Here is a fix from  James Kehr to run on your server to set an ip address to be the "Primary" ie Source. I did edit his script by putting a menu and removing the need to put a interface alias. This should only work with 2012 and above with powershell 3.0 and above. For other OS check the heyscriptingguy link.

http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/24/use-powershell-to-change-ip-behavior-with-skipassource.aspx
KB969029

Thank you James Kehr
# set some constants
clear
Import-Module NetTCPIP

Get-NetIPAddress | Where {$_.PrefixOrigin -eq "Manual"} | select IPaddress,InterfaceAlias,SkipasSource | format-table

$primaryIP = Read-Host "Which ip address should be set as primary?"
$Alias = Get-NetIPAddress $primaryIP -EA stop | select -expand InterfaceAlias

Write-Host "Setting $Alias primary IP to $primaryIP"

# get all the IP addresses on the interface, filtered by IPv4 and excluding

# the $primaryIP

[array]$IPs = Get-NetIPAddress -InterfaceAlias $Alias | Where-Object {$_.AddressFamily -eq "IPv4" -and $_.IPAddress -ne $primaryIP}

 

# set primary IP SkipAsSource to false

Set-NetIPAddress -IPAddress $primaryIP -InterfaceAlias $Alias -SkipAsSource $false

 

# set other IP addresses with SkipAsSource equal to true

Set-NetIPAddress -IPAddress $IPs.IPAddress -InterfaceAlias $Alias -SkipAsSource $true
Write-Host "Please review the output False under SkipasSource means the ip can be a source"
Get-NetIPAddress | Where {$_.PrefixOrigin -eq "Manual"} | select IPaddress,InterfaceAlias,SkipasSource | format-table

Monday, January 23, 2012

Howto: Two different subnets same physical LAN how to get them to talk without a gateway

Have you ever ran into a problem where you had two windows boxes that were on different sub nets on the same physical LAN and you needed to establish temporarily communication?

Say you have these two computers with the following ip addresses.

Computer 1
172.16.1.2 

Computer 2
192.168.100.1



So what we are going to do is tell each computer that in order to get to the other computer they have to go out their local interface.

Open a command prompt and run each of the following commands on the respective computer.

Computer 1
route add 192.168.100.1 MASK 255.255.255.255 172.16.1.2

Computer 2
route add  172.16.1.2  MASK 255.255.255.255 192.168.100.1


This now should allow for communication to occur.

I wrote a batch file to help with adding the route command


@echo off
echo -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Echo Created By Tony Unger
Echo **********************************************************************
echo Note:

echo Setup Routing Table
Echo Enter IP address you wish to connect to
REM IP address that was entered
set /p IPAddress=

REM Find Local IP Address - Works for Win7 if you have more then 1 adapter this may not work

REM Windows 7
FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG ^| FIND "IPv4"') DO FOR %%B IN (%%A) DO SET LOCIPADDR=%%B


route add %IPAddress% MASK 255.255.255.255 %LOCIPADDR% /p






Powershell: Microsoft Graph to add new roles to application registration

PowerShell Script Bulk add new roles to application registration in azure. Update $roles with ,Us...