Tag: IP Address

PowerShell Test-NetConnection Azure Arc API

Check if network connectivity for Azure Arc Connected Machine Agent is blocked

To onboard a server to Azure Arc, you will need to install the Azure Connected Machine Agent, which communicates outbound securely to Azure Arc over TCP port 443 with a couple of service tags and URLs. To check if the network connection for the Azure Arc Connected Machine Agent is blocked, I put together a couple of commands you can run on your machine. These commands allow you to see if the machine can connect to the specific URLs needed for the Azure Connected Machine agent.

You can find the up-to-date documentation for the Azure Connected Machine agent on Microsoft Docs.

If outbound connectivity is restricted by your firewall or proxy server, make sure the URLs listed below are not blocked. When you only allow the IP ranges or domain names required for the agent to communicate with the service. Your servers need to have access to the following URLs and Service Tags (list of IP addresses):

URLs:

  • management.azure.com (Azure Resource Manager)
  • login.windows.net (Azure Active Directory)
  • login.microsoftonline.com (Azure Active Directory)
  • dc.services.visualstudio.com (Application Insights)
  • *.guestconfiguration.azure.com (Guest Configuration)
  • *.his.arc.azure.com (Hybrid Identity Service)
  • www.office.com (Office 365)

Service Tags:

  • AzureActiveDirectory
  • AzureTrafficManager
  • AzureResourceManager
  • AzureArcInfrastructure

For a list of IP addresses for each service tag/region, see the JSON file – Azure IP Ranges and Service Tags – Public Cloud.

To check if network connectivity for the Azure Arc Connected Machine Agent is blocked you can use for example PowerShell. With the Test-NetConnection PowerShell cmdlet, you can see if you can reach the specific endpoint on port 443. In PowerShell 7 on Linux or macOS you can use the Test-Connection cmdlet in the same way. With this command you can check if DNS can resolve the URL and if the endpoint is reachable on the TCP port.

Test-NetConnection management.azure.com -Port 443

Make sure you check all the above listed URLs. For * you will need to add the region where your server needs to connect to. In my case this is the Azure West Europe region.

Test-NetConnection weu.his.arc.azure.com -Port 443
PowerShell Test-NetConnection Azure Arc API
PowerShell Test-NetConnection Azure Arc API

To find all the IP addresses which are needed for the Azure Arc Connected Machine agent, you can download the JSON file which includes the Azure Service Tags. You can either scroll through the file itself, or you can use my PowerShell script to quickly get all the IP ranges needed for Azure Arc.

$ServiceTags = Get-Content -path .\ServiceTags_Public_20210510.json -Raw | ConvertFrom-Json

foreach ($value in $ServiceTags.values)  {
    if ($value.properties.systemService -eq "AzureArcInfrastructure" -or "AzureActiveDirectory" -or "AzureTrafficManager" -or "AzureResourceManager"){
        Write-Output $value.name
        Write-Output $value.properties.addressPrefixes
    }
}

Microsoft publishes weekly updates containing each Azure Service and the IP ranges it uses. This information in the JSON file is the current point-in-time list of the IP ranges that correspond to each service tag. The IP addresses are subject to change. If IP address ranges are required for your firewall configuration, then the AzureCloud Service Tag should be used to allow access to all Azure services. Do not disable security monitoring or inspection of these URLs, allow them as you would other Internet traffic. For more information, review Service tags overview.

I hope this quick blog post helps you to troubleshoot any issue with network connectivity related to the Azure Arc Connected Machine agent and allows you to see if the local firewall blocks any traffic. If you need more troubleshooting information check out the following Microsoft Docs article and if you have any questions, feel free to leave a comment.



VM Network Adapter

PowerShell One-liner to list IP Addresses of Hyper-V Virtual Machines

Here a very quick PowerShell command to list all the Virtual Network Adapters, including IP Addresses of Virtual Machines running on a Hyper-V Host.

 
Get-VM -ComputerName "Hyperv01" | Get-VMNetworkAdapter

This will give you a list of all Virtual Machines running on Hyper-V Server called “HyperV01”



Get-NetIPConfiguration

Basic Networking PowerShell cmdlets cheatsheet to replace netsh, ipconfig, nslookup and more

Around 4 years ago I wrote a blog post about how to Replace netsh with Windows PowerShell which includes basic powershell networking cmdlets. After working with Microsoft Azure, Nano Server and Containers, PowerShell together with networking becomes more and more important. I created this little cheat sheet so it becomes easy for people to get started.

Basic Networking PowerShell cmdlets

Get-NetIPConfiguration

Get the IP Configuration (ipconfig with PowerShell)

Get-NetIPConfiguration

List all Network Adapters

Get-NetAdapter

Get a spesific network adapter by name

Get-NetAdapter -Name *Ethernet*

Get more information VLAN ID, Speed, Connection status

Get-NetAdapter | ft Name, Status, Linkspeed, VlanID

Get driver information

Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName

Get adapter hardware information. This can be really usefull when you need to know the PCI slot of the NIC.

Get-NetAdapterHardwareInfo

Disable and Enable a Network Adapter

Disable-NetAdapter -Name "Wireless Network Connection"
Enable-NetAdapter -Name "Wireless Network Connection"

Rename a Network Adapter

Rename-NetAdapter -Name "Wireless Network Connection" -NewName "Wireless"

IP Configuration using PowerShell

PowerShell Networking Get-NetIPAddress

Get IP and DNS address information

Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress

Get IP address only

(Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress).IPv4Address

Get DNS Server Address information

Get-NetAdapter -Name "Local Area Connection" | Get-DnsClientServerAddress

Set IP Address

New-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 10.0.1.95 -PrefixLength "24" -DefaultGateway 10.0.1.1

or if you want to change a existing IP Address

Set-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 192.168.12.25 -PrefixLength "24"

Remove IP Address

Get-NetAdapter -Name "Wireless" | Remove-NetIPAddress

Set DNS Server

Set-DnsClientServerAddress -InterfaceAlias "Wireless" -ServerAddresses "10.10.20.1","10.10.20.2"

Set interface to DHCP

Set-NetIPInterface -InterfaceAlias "Wireless" -Dhcp Enabled

Clear DNS Cache with PowerShell

You can also manage your DNS cache with PowerShell.

List DNS Cache:

 
Get-DnsClientCache

Clear DNS Cache

 
Clear-DnsClientCache

Ping with PowerShell

PowerShell Networking Test-NetConnection Ping

How to Ping with PowerShell. For a simple ping command with PowerShell, you can use the Test-Connection cmdlet:

 
Test-Connection thomasmaurer.ch

There is an advanced way to test connection using PowerShell

Test-NetConnection -ComputerName www.thomasmaurer.ch

Get some more details from the Test-NetConnection

Test-NetConnection -ComputerName www.thomasmaurer.ch -InformationLevel Detailed

Ping multiple IP using PowerShell

1..99 | % { Test-NetConnection -ComputerName x.x.x.$_ } | FT -AutoSize

Tracert

PowerShell Tracert

Tracert with PowerShell

Test-NetConnection www.thomasmaurer.ch –TraceRoute

Portscan with PowerShell

PowerShell Portscan

Use PowerShell to check for open port

Test-NetConnection -ComputerName www.thomasmaurer.ch -Port 80
Test-NetConnection -ComputerName www.thomasmaurer.ch -CommonTCPPort HTTP

NSlookup in PowerShell

PowerShell Networking NSlookup

NSlookup using PowerShell:

Resolve-DnsName www.thomasmaurer.ch
Resolve-DnsName www.thomasmaurer.ch -Type MX -Server 8.8.8.8

Route in PowerShell

PowerShell Networking Route

How to replace Route command with PowerShell

Get-NetRoute -Protocol Local -DestinationPrefix 192.168*
Get-NetRoute -InterfaceAlias Wi-Fi
 
New-NetRoute –DestinationPrefix "10.0.0.0/24" –InterfaceAlias "Ethernet" –NextHop 192.168.192.1

NETSTAT in PowerShell

PowerShell Networking Netstat

How to replace NETSTAT with PowerShell

Get-NetTCPConnection
Get-NetTCPConnection –State Established

NIC Teaming PowerShell commands

Create a new NIC Teaming (Network Adapter Team)

New-NetLbfoTeam -Name NICTEAM01 -TeamMembers Ethernet, Ethernet2 -TeamingMode SwitchIndependent -TeamNicName NICTEAM01 -LoadBalancingAlgorithm Dynamic

SMB Related PowerShell commands

SMB PowerShell SMB Client Configuration

Get SMB Client Configuration

Get-SmbClientConfiguration

Get SMB Connections

Get-SmbConnection

Get SMB Mutlichannel Connections

Get-SmbMutlichannelConnection

Get SMB open files

Get-SmbOpenFile

Get SMB Direct (RDMA) adapters

Get-NetAdapterRdma

Hyper-V Networking cmdlets

Hyper-V PowerShell Get-VMNetwork Adapter

Get and set Network Adapter VMQ settings

Get-NetAdapterVmq
# Disable VMQ
Set-NetAdapterVmq -Enabled $false
# Enable VMQ
Set-NetAdapterVmq -Enabled $true

Get VM Network Adapter

Get-VMNetworkAdapter -VMName Server01

Get VM Network Adapter IP Addresses

(Get-VMNetworkAdapter -VMName NanoConHost01).IPAddresses

Get VM Network Adapter Mac Addresses

(Get-VMNetworkAdapter -VMName NanoConHost01).MacAddress

I hope you enjoyed it and the post was helpful, if you think something important is missing, please add it in the comments.



System Center 2012 R2 Virtual Machine Manager in IPAM

Connect IPAM with System Center 2012 R2 Virtual Machine Manager

In System Center 2012 SP1 Virtual Machine Manager you already had an option to feed information into your IPAM (IP Address Management which was introduced with Windows Server 2012).  In the R2 release of Windows Server 2012 R2 and System Center 2012 R2, Microsoft did enhance the connection between IPAM and Virtual Machine Manager (SCVMM). This was a really important step, because first of all not a lot of people have a real IP Address Management solution like IPAM, most of them are still using some crazy Excelsheets to mange IP Addresses. But if you are thinking about your Private Cloud or you are a Cloud Service Provider this just doesn’t work. IP Addresses these days change rapidly and especially when you do IaaS (Infrastructure as a Service) and you don’t have access inside the VM, because you don’t control it, you need some automated system. IPAM in Windows Server 2012 and Windows Server 2012 R2 is just perfect for that. It integrates in Active Directory, DNS, DHCP and more. With System Center 2012 R2, Virtual Machine Manager gets a perfect connection to IPAM. And if you have worked with Virtual Machine Manager 2012, 2012 SP1 you know that SCVMM knows about all your networks and even your customer networks. VMM is definitely the central management for your cloud environment which offers an end-to-end solution.

To connect and integrate IPAM into SCVMM 2012 R2, open the Virtual Machine Manager console and navigate Fabric and add a new Network Service.

Assign a name to the network service.

Virtual Machine Manager add Network Service

Choose Microsoft Windows Server IP Address Management

Choose Microsoft Windows Server IP Address Management

Enter credentials for the connection between Virtual Machine Manager and IPAM and enter the connection string which is basically the FQDN of the IPAM infrastructure.

Specify network service connection string

You can also validate the network service configuration provider, which will test the connection to the IPAM server.

Validate the network service configuration provider

After you have connected IPAM, the network definitions, VM Networks, Logical Networks, IP Pools and so on will show up in IPAM.

System Center 2012 R2 Virtual Machine Manager in IPAM

I hope more people will see the value of IPAM and the integration in System Center 2012 R2 Virtual Machine Manager.



Replace netsh with Windows PowerShell – Basic network cmdlets

Some days ago I made a blog post about how you can replace diskpart.exe with the new cmdlets in Windows PowerShell v3. Now my next goal was to replace netsh with PowerShell.

Microsoft offers a lot of new cmdlets for networking tasks lets see what we have here. We got a lot of new PowerShell modules which are related to networking.

get-module

Now the two modules which sound really interesting are

NetAdapter
NetTCPIP

lets check which cmdlets are included

Get-Command -Module NetAdapter

net-adpater module

 Get-Command -Module NetTCPIP

Now lets start with NetAdpater.

List all Network Adapters

 Get-NetAdapter

get-netadapter

Just list Wireless Network Adapters

 Get-NetAdapter -Name *Wireless* 

get-netadapter wireless

Get more information VLAN ID, Speed, Connection status

 Get-NetAdapter | ft Name, Status, Linkspeed, VlanID 

get-netadapter information

Get driver information

 Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName 

get-netadapter driver

Get adapter hardware information. This can be really usefull when you need to know the PCI slot of the NIC.

 Get-NetAdapterHardwareInfo 

get-netadapterhardwareinfo

Disable and Enable a Network Adapter

 Disable-NetAdapter -Name "Wireless Network Connection"
Enable-NetAdapter -Name "Wireless Network Connection" 

disable enable network adapter

Rename a Network Adapter

 Rename-NetAdapter -Name "Wireless Network Connection" -NewName "Wireless" 

rename network adapter

Now with the NetTCPIP PowerShell module we can work with IP settings

Get IP and DNS address information

 Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress 

get-ipaddress

Get IP address only

 (Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress).IPv4Address 

get-ipaddress only

Get DNS Server Address information

 Get-NetAdapter -Name "Local Area Connection" | Get-DnsClientServerAddress 

get-dnsserver

Set IP Address

 New-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 10.0.1.95 -PrefixLength "24" -DefaultGateway 10.0.1.1 

or if you want to change a existing IP Address

 Set-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 192.168.12.25 -PrefixLength "24"

Remove IP Address

 Get-NetAdapter -Name "Wireless" | Remove-NetIPAddress 

Set DNS Server

 Set-DnsClientServerAddress -InterfaceAlias "Wireless" -ServerAddresses "10.10.20.1","10.10.20.2"

Set interface to DHCP

 Set-NetIPInterface -InterfaceAlias "Wireless" -Dhcp Enabled

Now with this basic knowledge we can replace some of the basic netsh commands and ipconfig

netsh

ipconfig
netsh interface set interface "Local Area Connection" newname="Management"
netsh interface ipv4 set address "Management" static 192.168.10.101 255.255.255.0 192.168.10.1

Windows PowerShell

Get-NetAdapter
Rename-NetAdapter -Name "Local Area Connection" -NewName "Management"
New-NetIPAddress -InterfaceAlias "Management" -IPv4Address 192.168.10.101 -PrefixLength "24" -DefaultGateway 192.168.10.1