Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Use Netcat to Test TCP and UDP Connections on a Linux Server

Practical netcat commands for TCP and UDP connectivity tests on Linux, including listeners, zero-I/O checks, exit statuses, implementation differences, and troubleshooting.
Length9 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use nc (netcat) to test a TCP port with nc -v -z -w 5 SERVER_IP PORT, or send a UDP datagram with printf 'hello over udpn' | nc -u -v -w 5 SERVER_IP PORT. A TCP result confirms socket-level acceptance; UDP needs a listener, response, or packet capture to prove delivery. First identify which netcat implementation your Linux server provides, because listener and option syntax differs between OpenBSD nc, Ncat, BusyBox nc, and other builds.

What netcat tests—and what it cannot prove

Netcat is a command-line utility that opens TCP or UDP connections, sends and receives bytes, listens on local ports, and can check whether a daemon is accepting connections. It works with IPv4 and IPv6 and requires no special hardware. On Linux it may be installed as OpenBSD nc, Ncat from the Nmap Project, BusyBox nc, or another implementation.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A successful TCP probe means that the destination address was reachable and a process accepted a TCP socket. It does not prove that the application protocol is healthy, that authentication works, that TLS is configured correctly, or that the service can complete a real request. A zero-I/O probe is deliberately limited to socket acceptance.

UDP is different: it has no TCP-style handshake. A sender can return to the shell even when a firewall dropped the datagram, no process is listening, or the application received it but does not answer. To establish UDP delivery, observe the packet at a listener, obtain an application response, or capture traffic on the relevant interfaces.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Identify your netcat implementation first

Do not copy listener commands blindly between machines. Option names, timeout behavior, and the syntax for binding a listening port vary by implementation.

  1. Run nc -h and read the displayed option list.
  2. Run nc -V when the build supports a version option.
  3. Read the local manual with man nc.

The examples in this guide use the OpenBSD-style syntax documented by Ubuntu. Ncat equivalents are shown where the behavior is known to differ. If your local help shows another listener form, use that form rather than forcing the examples to fit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Test a TCP port from a client

Make a bounded, visible connection attempt

nc -v -w 5 SERVER_IP PORT

Replace SERVER_IP with an address or resolvable hostname and PORT with the service port. The -v flag prints connection status. The -w 5 flag limits the connection or idle wait to five seconds, preventing an unattended command from hanging indefinitely.

When the command connects, you may see a success message and then an apparently idle terminal. That is normal for a service that keeps the socket open while waiting for protocol data. Press Ctrl+C after confirming the connection, or send the protocol’s expected request instead of typing arbitrary text.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Check only whether a daemon accepts TCP sockets

nc -v -z -w 5 SERVER_IP PORT

-z selects zero-I/O mode: netcat checks for a listening daemon without sending application data. This is the quickest way to answer “is this TCP port accepting connections?” Use an application-aware request when you need to know whether the service itself is functioning.

For example, if the destination is an HTTP service and you are authorized to query it, send a minimal HTTP/1.0 request:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
printf 'GET / HTTP/1.0rnHost: SERVER_NAMErnrn' | nc -v -w 5 SERVER_IP 80

The returned status line and headers test more than a bare socket probe, but they still do not validate every application feature, credential path, or production transaction.

Build an end-to-end TCP test with a listener

Start the listener

On the server or test host, run:

nc -l 5000

This listens on TCP port 5000 using the OpenBSD-style command shown above. Keep the terminal open while testing. Some implementations require an additional port option or place the port before other arguments; check nc -h if this command errors.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Connect from another host and send known text

printf 'hello over tcpn' | nc -v -w 5 SERVER_IP 5000

Replace SERVER_IP with the listener’s address. The listener should display hello over tcp. This verifies the path from the client to the listening process and confirms that bytes can traverse the established TCP connection.

Keep a Ncat listener open for multiple connections

Ncat, the Nmap Project implementation, supports:

ncat -l -k 5000

-k (also documented as --keep-open) keeps the listener available after a client disconnects, allowing repeated tests. The exact option set still depends on the installed Ncat version, so consult ncat --help or its manual on the host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a remote client cannot connect

  • Confirm the listener is running and bound to the intended interface. A process bound only to 127.0.0.1 or ::1 cannot accept a connection arriving on a remote interface.
  • Check the host firewall and any cloud security-group or network-policy rule for TCP 5000.
  • Verify routing and DNS resolution; test the actual address returned to the client.
  • Ensure another service is not already occupying the port.

Test UDP connectivity with netcat

Listen for UDP datagrams

nc -u -l 5000

-u selects UDP and -l creates a listener. OpenBSD nc documents that a UDP listener socket can receive datagrams from multiple hosts. Keep this terminal visible so you can confirm whether the payload arrives.

Send a datagram from another host

printf 'hello over udpn' | nc -u -v -w 5 SERVER_IP 5000

If the listener prints the line, you have direct evidence that the datagram reached the listening socket. The sender returning to its shell alone is not evidence of delivery: UDP provides no connection handshake or built-in acknowledgment.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

When the UDP listener shows nothing

Check the destination address, interface binding, host firewall, cloud security group, and routing. A service may be bound to a different address, may not be running, or may intentionally remain silent after receiving a packet. Compare packet captures on the client and server when you need to distinguish a transmit failure from filtering or an application-level decision not to respond.

Check several TCP ports at once

nc -vz -w 2 SERVER_IP 20-25

This checks ports 20 through 25 in zero-I/O mode, with a two-second wait bound for each attempt. The range syntax and zero-I/O behavior are documented by the Ubuntu OpenBSD nc manual. Treat the output as reachability information, not as a vulnerability scan and not as proof that any discovered service speaks its expected protocol.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a narrower range or an explicit list when you know the service ports you own. Broad probing can trigger intrusion-detection alerts and may violate a network’s acceptable-use policy.

Read results and exit status correctly

Common TCP outcomes

Observed result Likely meaning Next check
Connection succeeds The host and port accepted a TCP socket. Send an application-aware request if protocol health matters.
Connection refused The host was reachable, but no process accepted that TCP port, or an active device rejected it. Check the service state, listening address, and local firewall.
Timeout Filtering, routing trouble, a stopped service, or an address/interface mismatch is possible. Verify routes and policy, then compare captures at both ends.
Connection reset A peer or intermediary closed an established or attempted connection. Inspect service logs and protocol expectations.

Use the process exit code in scripts

Ncat documents exit status 0 for a successful connection, 1 for a network error such as “Connection refused” or “Connection reset,” and 2 for another error such as an invalid option or missing file.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
if nc -z -w 5 SERVER_IP PORT; then
    echo "TCP port is accepting connections"
else
    status=$?
    echo "netcat failed with status $status"
fi

Do not assume every nc variant uses exactly the same exit-code contract. If a monitoring script depends on a particular status, test that implementation and document the dependency.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Inspect the server when a probe fails

Confirm that something is listening

ss -lntup

The -l option shows listening sockets, -n keeps addresses and ports numeric, -t includes TCP, -u includes UDP, and -p shows the owning process when permitted. Compare the displayed local address and port with the address the client is targeting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Work through the network path

  • Resolve the hostname on the client and confirm it points to the intended server.
  • Check the server’s local firewall rules and any upstream firewall, router ACL, or cloud security-group policy.
  • Confirm that the service is configured to bind the required IPv4 or IPv6 interface, not only loopback.
  • Check that the client route reaches the server network and that return traffic is permitted.
  • Repeat the test with packet captures at the client and server when the symptoms do not identify the failing segment.

Interpret UDP evidence conservatively

A packet visible leaving the client proves transmission from that host, not receipt by the application. A packet visible at the server’s interface proves arrival at that interface, not that a process consumed it. Seeing the payload in the netcat listener, receiving a documented application reply, or correlating both directions in a capture provides stronger evidence.

OpenBSD nc and Ncat: which implementation should you use?

Both implementations cover the basic workflow—TCP and UDP client connections, listeners, verbosity, time limits, and zero-I/O checks—but they are not interchangeable command-line interfaces.

Capability OpenBSD-style nc Ncat Practical implication
Default protocol TCP TCP Add -u when testing UDP.
Listen mode -l; exact port syntax can vary by build ncat -l PORT Read local help before using a listener command copied from another host.
UDP handling -u selects UDP; a listener can receive from multiple hosts -u selects UDP Neither provides a TCP-style UDP handshake.
Timeout control -w is used in the examples -w is available in Ncat syntax Bound waits in automation and troubleshooting.
Zero-I/O check -z Supports zero-I/O connection checks Use for socket acceptance, not protocol validation.
IPv4/IPv6 Supports IPv4 and IPv6; option details are implementation-specific Supports IPv4 and IPv6 Make sure the address family matches the service binding and firewall policy.
Additional modes Core TCP, UDP, and Unix-domain socket operations TLS, proxying, brokering, and explicit connection limits in addition to core modes Choose Ncat when those features are required and permitted.
Exit statuses Check the local implementation 0 success, 1 network error, 2 other error as documented by Ncat Pin scripts to the implementation whose behavior you have verified.

BusyBox and other compact builds may omit options or use different listener syntax. The authoritative answer for a particular server is its installed help output and manual.

Use netcat safely

  • Test only systems and ports you own or have explicit permission to assess.
  • Do not send passwords, API keys, player data, or other sensitive material through an unencrypted netcat session.
  • Remember that a basic nc -z test does not validate authentication, encryption, certificates, or application semantics.
  • Ncat has TLS options, but a TLS test must match the target service’s certificate, protocol, and hostname requirements. A plain-text probe against a TLS-only service is not an equivalent health check.
  • Stop temporary listeners when testing is complete, especially on publicly reachable servers.

A repeatable test procedure

  1. Identify the implementation with nc -h, nc -V where supported, and man nc.
  2. Verify the server-side process and bind address with ss -lntup.
  3. Run a bounded TCP probe: nc -v -z -w 5 SERVER_IP PORT.
  4. If the port accepts connections, perform the smallest valid application request for that protocol.
  5. For UDP, start nc -u -l 5000 on the receiving host and send a known line with printf from the client.
  6. When results are ambiguous, inspect firewall and security-group policy and compare packet captures at both ends.
  7. Record the implementation, command, destination address family, timestamp, and result so future checks are reproducible.

Netcat command reference

Purpose Command What it demonstrates
Verbose TCP attempt nc -v -w 5 SERVER_IP PORT Whether a TCP socket can be opened within five seconds.
TCP zero-I/O check nc -v -z -w 5 SERVER_IP PORT Whether a TCP daemon accepts a socket without application data.
TCP listener nc -l 5000 Accepts a test connection on TCP port 5000, subject to local syntax.
TCP payload test printf 'hello over tcpn' | nc -v -w 5 SERVER_IP 5000 Moves known bytes through an established TCP connection.
Persistent Ncat listener ncat -l -k 5000 Keeps an Ncat listener open for multiple clients.
UDP listener nc -u -l 5000 Displays datagrams received on UDP port 5000.
UDP payload test printf 'hello over udpn' | nc -u -v -w 5 SERVER_IP 5000 Sends a datagram; delivery must be confirmed separately.
TCP port range nc -vz -w 2 SERVER_IP 20-25 Performs bounded zero-I/O checks on ports 20 through 25.
Socket inventory ss -lntup Shows listening TCP/UDP sockets and, where permitted, their processes.

Key points to remember

  • TCP is the default in common OpenBSD nc and Ncat builds; use -u for UDP.
  • -l listens, -v shows status, -w bounds waiting, and -z performs a zero-I/O check.
  • A successful TCP probe confirms socket acceptance, not application health.
  • UDP has no handshake; verify delivery with a listener, an application response, or packet capture.
  • Implementation differences matter. Read the local help and manual before automating a command.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.