Tag: Ping

Ping Azure VM Public IP address

How to enable Ping (ICMP echo) on an Azure VM

This is just a very quick blog post because I got the question from a couple of people. In this blog post want to show you how you can enable ping (ICMP) on a public IP address of an Azure virtual machine (VM). First, just let me say that assigning a public IP address to a virtual machine can be a security risk. So if you do that, make sure you know what you are doing. If you need admin access to virtual machines only for a specific time, there are services like Azure Just-in-Time VM Access (JIT) and Azure Bastion you should have a look at. Now back to the topic, Azure by default denies and blocks all public inbound traffic to an Azure virtual machine, and also includes ICMP traffic. This is a good thing since it improves security by reducing the attack surface.

Azure Network Security Group Port Rules Deny All Inbound Traffic to Azure VM

Azure Network Security Group Port Rules Deny All Inbound Traffic to Azure VM

This also applies to pings or ICMP echo requests sent to Azure VMs.

Ping Azure VM failed

Ping Azure VM failed

However, if you need to access your application from a public IP address, you will need to allow the specific ports and protocols. The same applies to the ICMP (Internet Control Message Protocol) protocol. The ICMP protocol is typically used for diagnostic and is often used to troubleshoot networking issues. One of the diagnostic tools using ICMP is ping, which we all know and love.

What do I need to do to be able to ping my Azure virtual machines (VMs)

Overall we need to do two main steps:

Configure Network Security Group (NSG) to allow ICMP traffic

So here is how you enable or allow ping (ICMP) to an Azure VM. Click on add a new inbound port rule for the Azure network security group (NSG).

Enable Ping ICMP in a NSG on an Azure VM

Enable Ping ICMP in an NSG on an Azure VM

Change the protocol to ICMP. As you can see, you can also limit the sources which can make use of that rule, as well as change the name and description. You can also use the following Azure PowerShell commands to add the inbound security rule to your NSG.

Get-AzNetworkSecurityGroup -Name "AzureVM-WIN01-nsg" | Add-AzNetworkSecurityRuleConfig -Name ICMP-Ping -Description "Allow Ping" -Access Allow -Protocol ICMP -Direction Inbound -Priority 100 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange * | Set-AzNetworkSecurityGroup
Configure Network Security Group PowerShell

Configure Network Security Group PowerShell

Set up the operating system to answer to Ping/ICMP echo request

If you haven’t already configured the operating system that way, you will need to allow ICMP traffic, so the operating system response to a ping. On Windows Server, this is disabled by default, and you need to configure the Windows Firewall. You can run the following command to allow ICMP traffic in the Windows Server operating system. In the Windows Firewall with Advanced Security, you can enable the Echo Request – ICMPv4-In or Echo Request ICMPv6-In rules, depending on if you need IPv4 or IPv6.

Windows Firewall Enable Ping

Windows Firewall Enable Ping

You can also run the following command to do that:

# For IPv4
netsh advfirewall firewall add rule name="ICMP Allow incoming V4 echo request" protocol="icmpv4:8,any" dir=in action=allow
 
#For IPv6
netsh advfirewall firewall add rule name="ICMP Allow incoming V6 echo request" protocol="icmpv6:8,any" dir=in action=allow

After doing both steps, you should be able to ping your Azure Virtual Machine (VM) using a public IP address.

Ping Azure VM Public IP address

Ping Azure VM Public IP address

I hope this helps you be able to ping your Azure VMs. If you have any questions, please let me know in the comments.



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.



Test-NetConnection PowerShell Portscan

SuperPing – PowerShell Test-NetConnection

With Windows 8.1 and Windows Server 2012 R2 Microsoft released PowerShell v4 with new PowerShell modules and new PowerShell cmdlets. One of them is the new Test-NetConnection cmdlet which does basically replaces some simple network tools like Ping, Traceroute, Portscanner and more.

First if you just run Test-NetConnection this will check a Microsoft edge server and will tell you if your internet is working or not.

PowerShell Test-NetConnection

You can also ping other servers

Test-NetConnection Ping

If we have a closer look at this cmdlet we can see that we can do much more.

get-help get-testnetconnection

What we can do is something like a port scan. In this example I check if the RDP port is open on my webserver. Which is hopefully not ;-)

Test-NetConnection thomasmaurer.ch -CommonTCPPort RDP

Test-NetConnection PowerShell Portscan

You can also check for not so common ports by using the -Port parameter and entering the port number.
Another thing you could do would be a simple traceroute.

Test-NetConnection thomasmaurer.ch -TraceRoute

Test-NetConnection PowerShell Traceroute

If you want to do a ping -t you could use the following command

while ($true) {Test-NetConnection -InformationLevel Quiet}

Ping -t with PowerShell

I hope this helps you a little :)

Find more networking PowerShell cmdlets in my PowerShell Networking cheatsheet.



PowerShell: Ping IP range

Powershell

Some you need to know which IP in a specific range is already in use. With Windows PowerShell there is a simple way to ping a IP range.

You can use the .Net class System.Net.Networkinformation.Ping to do this.

 
$ping = New-Object System.Net.Networkinformation.Ping
1..254 | % { $ping.send(“192.168.100.$_) | select address, status }

You can also have a look at the new Test-Connection or Test-NetConnection PowerShell cmdlets.