Christian Schou
  • Forside
  • Blog
    • Programmering
      • C#
      • PowerShell
      • Python
      • SQL
    • WordPress
      • Guides
    • Cloud
    • Boligautomatisering
      • Home Assistant
        • Node-Red
    • Career
  • Services
  • Ordbog
  • About
No Result
View All Result
Christian Schou
  • Forside
  • Blog
    • Programmering
      • C#
      • PowerShell
      • Python
      • SQL
    • WordPress
      • Guides
    • Cloud
    • Boligautomatisering
      • Home Assistant
        • Node-Red
    • Career
  • Services
  • Ordbog
  • About
No Result
View All Result
Christian Schou
No Result
View All Result
Home Operating Systems
ping ip and port

How to ping IP and port from Windows or Linux

by Christian
18. februar 2022
in Operating Systems
0

One of the things I do the most when troubleshooting deployments of services exposing data to the internet is pinging the IP and port where the service is supposed to be alive. In this tutorial, I will show you how to ping IP and port on Linux and Windows.

I think most system administrators know the commands for this, but if you like me normally don’t work like an IT admin (at least not anymore) I tend to forget the commands. Due to that, I have written this article as a reference for myself but also everyone else, who is in need of pinging services they expect at a location.

Often it’s enough to just ping an IP to validate that you got “life” on the server. However if you like me often got many services running on one server (often when using Docker), I need to ping the specific port number on the server. One of the Kubernetes clusters I manage is running more than 100 services and here I use it a lot.

In this article/reference post, I will show you how to ping IP and port on your Windows or Linux machine using different commands in the terminal (CLI)

Indholdsfortegnelse
  1. Ping IP and port using Telnet
    • Install Telnet on Linux
    • Install Telnet on Windows
    • Ping IP and port with Telnet example
  2. Ping IP and port using Nmap
    • Install Nmap on Linux
    • Install Nmap on Windows
    • Ping IP and port using Nmap
  3. Ping IP and port using PowerShell
  4. Summary

Ping IP and port using Telnet

This is my favorite when working on both Windows and Linux. I also think that it’s the easiest one to use and it’s called Telnet. You can with a simple command using Telnet ping IP and port on the remote server you would like to check.

If you want to, you can also use a domain instead of the IP. A domain is often easier for humans to remember instead of numbers to multiple different servers locally or externally.

Below are the commands to ping IP and port on a server using Telnet:

$ telnet <server_ip_address> <server_port_number>

$ telnet <server_domain_name> <server_port_number>

As I mentioned above, you can use Telnet on both Windows and Linux computers/servers which makes it a great choice for most sys-ops.

On most computers, telnet is not installed by default. If you get the annoying error “telnet: command not found”, you have to install Telnet on the machine using the commands below:

Install Telnet on Linux

If you are working on a Linux Server or Desktop, you can use the below command to install Telnet on that machine:

$ sudo apt install telnet

Install Telnet on Windows

By default, Telnet is not an enabled Windows Feature. If you run Telnet on your computer in a Command Prompt, you will get the following error: “Telnet is not recognized as an operable program or batch file.”. So – to install Telnet on Windows, you have to do the following:

  1. Click on Start.
  2. Select Control Panel.
  3. Choose Programs and Features.
  4. Click Turn Windows features on or off.
  5. Select the Telnet Client option.
  6. Click OK.
    A dialog box appears to confirm installation when it’s done. The telnet command should now be available in your Command Prompt. Remember to restart your CMD window.

Ping IP and port with Telnet example

Let’s check out how Telnet works. This website is running at IP: 172.67.161.26 – this is the public IP address of the website that the domain is mapped to.

By default, all requests are redirected to HTTPS (port 443) if a request is made at port 80. This means that the server accepts connections on port 80 too – let’s try and ping both ports:

$ telnet 172.67.161.26 80

Trying 172.67.161.26...
Connected to 172.67.161.26.
Escape character is '^]'.

$ telnet 172.67.161.26 443

Trying 172.67.161.26...
Connected to 172.67.161.26.
Escape character is '^]'.

That went well. We got connected and could see that the server is responding on both ports. This simply means that the service on the port is up and running.

If you would like to escape out of the Telnet utility when connected, you can use “CTRL + ]” or the “q” command.

Ping IP and port using Nmap

Another well-used tool is Nmap. In Nmap, you can ping a port by using the “-p” option including the IP or domain you would like to scan.

$ nmap -p <server_port_number> <server_ip_address>

$ nmap -p <server_port_number> <internet_domain_name>

A heads up – be aware of legal issues!

“When used properly, Nmap helps protect your network from invaders. But when used improperly, Nmap can (in rare cases) get you sued, fired, expelled, jailed, or banned by your ISP.” – Nmap website.

If you get an error telling you that Nmap is not available on your computer/server, you would have to install it.

Install Nmap on Linux

To install Nmap on your Linux machine, you can use the below command:

$ sudo apt install nmap

Install Nmap on Windows

Not as simple as Linux, but it’s still easy using the official installer from Nmap’s website. Go to this page: Download Nmap and look under the Windows Binaries for the latest available installer file.

Once the installer has completed installing, you are now ready to use Nmap on your Windows computer.

Ping IP and port using Nmap

Let’s try to ping a website at IP “172.67.161.26” on the global internet at the default HTTPS port – 443. If you test this yourself, then don’t use that IP. Cloudflare is protecting the website and will block your access and in the worst-case ban your IP from their global network. Only do this at IPs you own or services that won’t do any damage to others.

C:\Users\christian>nmap -p 443 172.67.161.26
Starting Nmap 7.92 ( https://nmap.org ) at 2022-02-10 06:50 Romance Standard Time
Nmap scan report for 172.67.161.26
Host is up (0.028s latency).

Well, once again the port is returned as open on the server. This means that there is a service accepting data at port 443, which was just verified by Nmap.

Ping IP and port using PowerShell

Normally when I’m not on my own machines, which means I’m working on production servers not related to my own business/platform and it’s a Windows Server Environment, I always use PowerShell to ping IP and port.

A great thing about PowerShell is that you can use the methods in scripts running automated stuff in the background or during the setup of a service or multiple services. A great thing if deploying with PowerShell would be to check if the ports were active after deployment and return a status to the terminal.

In PowerShell, we got something called Test-NetConnection which is a command where you specify either an IP or a domain followed by the port you would like to ping.

PS C:\Users\christian> Test-NetConnection <server_ip_address> -p <server_port_number>

Below is an example of what this would look like on a local network:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
                                                                                                                                                                                                                                                                             PS C:\Users\christian> Test-NetConnection 192.168.1.1 -p 80                                                                                                                                                                                                                                                                                                                   ComputerName     : 192.168.1.1
RemoteAddress    : 192.168.1.1
RemotePort       : 80
InterfaceAlias   : Wi-Fi
SourceAddress    : 192.168.1.68
TcpTestSucceeded : True

In the test above you can see that the TCP call to my gateway at home succeeded at port 80. If you can’t get through to the service you will status False in TcpTestSucceeded.

Summary

In this quick article on how to ping IP and port using different tools on Windows or Linux machines, we learned how we can use the terminal to check if a given port is open and is accepting requests.

If you got any issues, questions, or suggestions, please let me know in the comments below. Happy pinging! 🙂

Tags: CLICMDIPLinuxNetworkNmapPingPowerShellTelnetTerminalWindows
Previous Post

How to add Toast Notifications in an ASP.NET Core Web App (.NET 6)

Next Post

What is Docker? Docker beginner guide

Christian

Christian

Hello 👋 My name is Christian and I am 26 years old. I'm an educated Software Developer with a primary focus on C#, .NET Core, Python, and PowerShell. Currently, I'm expanding my skills in Software Robots and Cloud Architecture. In some of my spare time, I share my knowledge about tech stuff on my blog.

Related Posts

No Content Available
Next Post
docker, what is docker, docker beginner guide

What is Docker? Docker beginner guide

Skriv et svar Annuller svar

Din e-mailadresse vil ikke blive publiceret. Krævede felter er markeret med *

Christian Schou

Christian Schou

Software Developer

Hello - my name is Christian and I am 26 years old. I'm an educated Software Developer with a primary focus on C#, .NET Core, Python, and PowerShell. Currently, I'm expanding my skills in Software Robots and Cloud Architecture. In some of my spare time, I share my knowledge about tech stuff on my blog.

Recent articles

personal website
Career

Top 6 things to add on your personal website to get hired for a tech job

by Christian
7. august 2022
0

Back in the days before the internet was a thing like it is today, we used to have business cards...

Read more
watchdog

The #1 guide to show real-time .NET 6 logs for Web Apps and APIs in a modern way using WatchDog for Free

13. august 2022
get hired for a tech job

5 tips to help you get hired for a tech job

31. juli 2022
restful web api

How to build a RESTful Web API using ASP.NET Core and Entity Framework Core (.NET 6)

25. juli 2022
dynamically register entities

How to Dynamically Register Entities in DbContext by Extending ModelBuilder?

23. juli 2022

Christian Schou

Software Developer

Hello - my name is Christian and I am 26 years old. I'm an educated Software Developer with a primary focus on C#, .NET Core, Python, and PowerShell. Currently, I'm expanding my skills in Software Robots and Cloud Architecture. In some of my spare time, I share my knowledge about tech stuff on my blog.

Recent articles

personal website

Top 6 things to add on your personal website to get hired for a tech job

7. august 2022
watchdog

The #1 guide to show real-time .NET 6 logs for Web Apps and APIs in a modern way using WatchDog for Free

13. august 2022
get hired for a tech job

5 tips to help you get hired for a tech job

31. juli 2022
  • da_DKDansk
    • en_USEnglish
    • de_DEDeutsch
    • hi_INहिन्दी
    • pt_BRPortuguês do Brasil
  • Contact
  • Privatlivspolitik
  • Vilkår og betingelser

© 2022 Christian Schou - All rights reserved.

No Result
View All Result
  • Forside
  • Blog
    • Programmering
      • C#
      • PowerShell
      • Python
      • SQL
    • WordPress
      • Guides
    • Cloud
    • Boligautomatisering
      • Home Assistant
    • Career
  • Services
  • Ordbog
  • About

© 2022 Christian Schou - All rights reserved.

Jeg bruger cookies på min hjemmeside for at give dig den mest relevante oplevelse ved at huske dine præferencer og gentage besøg. Ved at klikke på "Accepter“, du giver dit samtykke til brugen af ALLE cookies.
Sælg ikke mine personlige informationer.
Cookie indstillingerACCEPT
Privat & Cookies politik

Overblik over privatliv

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Altid aktiveret
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
CookieVarighedBeskrivelse
__gads1 year 24 daysThe __gads cookie, set by Google, is stored under DoubleClick domain and tracks the number of times users see an advert, measures the success of the campaign and calculates its revenue. This cookie can only be read from the domain they are set on and will not track any data while browsing through other sites.
_ga2 yearsThe _ga cookie, installed by Google Analytics, calculates visitor, session and campaign data and also keeps track of site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognize unique visitors.
_ga_0J2F6JVWSD2 yearsThis cookie is installed by Google Analytics.
_gat_gtag_UA_84232734_11 minuteSet by Google to distinguish users.
_gid1 dayInstalled by Google Analytics, _gid cookie stores information on how visitors use a website, while also creating an analytics report of the website's performance. Some of the data that are collected include the number of visitors, their source, and the pages they visit anonymously.
YouTube2 yearsYouTube sets this cookie via embedded youtube-videos and registers anonymous statistical data. I embed YouTube videos in my articles/tutorials - you won't get the full experience of the articles if this is deactivated.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
CookieVarighedBeskrivelse
IDE1 year 24 daysGoogle DoubleClick IDE cookies are used to store information about how the user uses the website to present them with relevant ads and according to the user profile.
test_cookie15 minutesThe test_cookie is set by doubleclick.net and is used to determine if the user's browser supports cookies.
VISITOR_INFO1_LIVE5 months 27 daysA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.
YSCsessionYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.
yt-remote-connected-devicesneverYouTube sets this cookie to store the video preferences of the user using embedded YouTube video.
yt-remote-device-idneverYouTube sets this cookie to store the video preferences of the user using embedded YouTube video.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
GEM & ACCEPTÈR
Powered by CookieYes Logo