Skip to content

Instantly share code, notes, and snippets.

@tech-zombie
Last active January 29, 2019 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tech-zombie/66d9e8f4297bd0a5a5b9387ca41a2d6b to your computer and use it in GitHub Desktop.
Save tech-zombie/66d9e8f4297bd0a5a5b9387ca41a2d6b to your computer and use it in GitHub Desktop.
Sets DNS server based on octet in AWS
<##>
param (
[int]$WhichOctet,
[int]$Zone1_OctetValue,
[int]$Zone2_OctetValue,
$DNSZone1_server,
$DNSZone2_server
)
function Get-AWSIP
{ Invoke-WebRequest http://169.254.169.254/latest/meta-data/local-ipv4 }
function Get-Interface($IPaddr)
{ Get-NetIPAddress | Where IPAddress -EQ $IPaddr }
function Set-DnsClientServer($Zone1_OctetValue,$Zone2_OctetValue,$DNSZone1_server,$DNSZone2_server,$Interface_index,$octet_value)
{
if ($octet_value -eq $Zone1_OctetValue)
{ #Set-DnsClientServerAddress -InterfaceIndex $interface_index -ServerAddresses ($DNSZone1_server,$DNSZone2_server)
"Zone 1"
}
elseif ($octet_value -eq $Zone2_OctetValue)
{
#Set-DnsClientServerAddress -InterfaceIndex $interface_index -ServerAddresses ($DNSZone2_server,$DNSZone1_server)
"Zone 2"
}
else {"ERROR:- No Match"}
}
$ip = Get-AWSIP
$interface = get-interface($ip.content)
$octet_value = $ip.content.split(".")[$WhichOctet -1]
write-host "IP:" $ip.content "-- octet:" $octet_value "-- interface:" $interface.InterfaceIndex
Set-DnsClientServer -Zone1_OctetValue $Zone1_OctetValue `
-Zone2_OctetValue $Zone2_OctetValue `
-DNSZone1_server $DNSZone1_server `
-DNSZone2_server $DNSZone2_server `
-Interface_index $interface.InterfaceIndex `
-octet_value $octet_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment