Your Search Bar For Shrewd Tips

How To Close Udp Port


Closing an unwanted UDP port can reduce your device’s exposure to network traffic, but the right method depends on what is using the port and where the traffic is coming from. You might need to stop an application, add a firewall rule, change a router setting, or update a cloud security policy. This guide explains how to identify a UDP port and close it on common systems, then check that the change worked.

What Does It Mean to Close a UDP Port?

UDP, or User Datagram Protocol, is used by applications that send data without establishing a connection first. Streaming, voice and video calls, gaming, DNS, and device discovery are among the activities that may use UDP. A UDP port is a numbered endpoint that an application can use to receive network traffic.

Closing a UDP port usually means one of two things: stopping the application that listens on the port, or configuring a firewall to block traffic to it. These approaches are different. Stopping an application removes its listener, while a firewall can block incoming packets even if the application is still running. In some cases, you may want to do both.

Before making a change, confirm that the port is not required by an important service. Blocking a port can interrupt applications or network functions. Avoid changing ports you do not recognize until you have identified the process and checked its purpose.

Find Out Which Application Is Using the UDP Port

Start by identifying the port number and the process associated with it. Replace 12345 in the examples below with the UDP port you want to investigate. You may need administrator or root permissions to see process details.

  • Linux: Run sudo ss -lunp to list UDP sockets and, where available, the processes using them. To look for one port, use sudo ss -lunp | grep ':12345'.
  • Linux alternative: Run sudo lsof -nP -iUDP:12345 to check which process has the port open.
  • Windows: In PowerShell, run Get-NetUDPEndpoint -LocalPort 12345. Note the process ID shown in the output, then check it with Get-Process -Id PROCESS_ID, replacing PROCESS_ID with the number.
  • macOS: In Terminal, run sudo lsof -nP -iUDP:12345 to look for a process using that port.

If these commands show no listener, the port may not be open on the device itself. A router, firewall, virtual machine, or cloud network rule could still be forwarding or allowing UDP traffic. Check those layers too.

Close a UDP Port on Linux with UFW

UFW, or Uncomplicated Firewall, is a common firewall interface on Ubuntu and other Linux distributions. Check its status before changing rules:

sudo ufw status verbose

To block incoming UDP traffic on a specific port, run:

sudo ufw deny 12345/udp

Then confirm the rule appears in the firewall status:

sudo ufw status numbered

UFW rules typically persist across restarts. If you later decide the rule is unnecessary, remove it by its number using sudo ufw delete NUMBER, substituting the rule’s number from the status output. Review the displayed rule carefully before deleting it.

Blocking incoming traffic is not the same as stopping the program. If you also want to stop the application, identify its system service and stop it with the appropriate service manager. For example, a known service can often be stopped with sudo systemctl stop SERVICE_NAME. Do not guess the service name; confirm it first, and consider whether it should start automatically again after a reboot.

Close a UDP Port with firewalld

Many Red Hat-based distributions use firewalld. First check which zone is active and which ports or services it allows:

sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-all

If UDP port 12345 was explicitly allowed, remove that allowance from the active zone and make the change permanent. Replace public with the zone that applies to your network:

sudo firewall-cmd --zone=public --remove-port=12345/udp
sudo firewall-cmd --zone=public --permanent --remove-port=12345/udp
sudo firewall-cmd --reload

Removing an allow rule does not always guarantee that the port is blocked. Another rule, service entry, or policy may still allow it. Review the active zone and any custom policies after making the change. If you need a specific deny rule, use the firewall configuration supported by your distribution and test it carefully.

Block a UDP Port in Windows Firewall

On Windows, you can create an inbound firewall rule to block UDP traffic on a particular local port. Open PowerShell as an administrator and run:

New-NetFirewallRule -DisplayName "Block UDP 12345" -Direction Inbound -Protocol UDP -LocalPort 12345 -Action Block

Verify the rule in Windows Defender Firewall with Advanced Security or with PowerShell:

Get-NetFirewallRule -DisplayName "Block UDP 12345"

To remove the rule later, run:

Remove-NetFirewallRule -DisplayName "Block UDP 12345"

An inbound rule blocks traffic arriving at the computer. If your goal is to prevent a local application from sending UDP traffic outward, create an outbound rule instead by changing -Direction Inbound to -Direction Outbound. Use the narrowest rule that meets your needs, and check for other firewall rules that could affect the same application or port.

Close a UDP Port on macOS

macOS includes an application firewall, but its standard settings are mainly designed to control incoming connections to applications rather than provide a simple port-by-port interface. First identify the process with lsof, then check the application’s own settings for an option to disable its network service or listener.

For more specific packet filtering, macOS includes the pf firewall. Its configuration can affect network connectivity, and a mistaken rule may block more traffic than intended. If you are not familiar with pf, use a trusted network administration tool or consult Apple’s current documentation rather than editing system firewall files by trial and error. For a home network, blocking the port on the router may be the simpler option.

Close a UDP Port on a Router

If traffic is reaching a device from the internet, check your router’s administration page. Look for sections named Port Forwarding, Virtual Server, NAT, or Firewall. Remove any forwarding entry for the UDP port you want to close, then save or apply the settings. Menu names vary by manufacturer.

Port forwarding sends traffic arriving at the router to a device inside your network. Removing a forwarding rule can prevent unsolicited internet traffic from reaching that device, but it does not stop local devices from communicating with each other. It also does not stop an application from listening on the computer itself.

Check for separate rules for IPv4 and IPv6. A router may handle the two protocols differently, and an IPv4 forwarding change does not necessarily control IPv6 traffic. If you use a mesh system or more than one router, check the settings on the device that actually handles the internet connection.

Close a UDP Port in a Cloud Environment

For a virtual machine or hosted server, review the cloud provider’s network controls as well as the operating system firewall. Depending on the platform, these controls may be called security groups, network security groups, firewall rules, or virtual network access rules.

Remove or narrow any inbound rule that allows the UDP port. If the service only needs access from a specific trusted address range, limiting the rule to that range may be more appropriate than allowing traffic from everywhere. Check both IPv4 and IPv6 rules and review any network-level firewall in front of the virtual machine.

Cloud network rules and host firewalls are separate layers. A restrictive rule at one layer may block traffic even if another layer allows it, while an overlooked rule at either layer could leave the service reachable. Document the change so it can be reviewed or reversed if the application stops working.

Verify That the UDP Port Is Closed

After changing a rule, check both the application and the network path. Run the socket-listing command again to see whether a local process is still listening. Then review the firewall’s active rules and confirm that the correct protocol, port, direction, and network interface are covered.

You can also test from another device on the relevant network using a reputable port-checking or network diagnostic tool that supports UDP. UDP checks can be inconclusive: unlike TCP, UDP does not complete a connection handshake, and a service may silently ignore packets. A timeout alone does not prove that the port is closed. Test from the location that matters, such as another computer on your LAN or an external network, and interpret results alongside your firewall configuration.

Common Mistakes to Avoid

  • Blocking the wrong protocol: A rule for TCP does not block UDP. Confirm that the rule specifies UDP.
  • Changing only one network layer: Check the operating system, router, and cloud controls that apply to your setup.
  • Ignoring IPv6: Verify that the relevant IPv6 traffic is covered, not just IPv4.
  • Stopping an unfamiliar process: Identify the application and check whether it supports an essential feature before disabling it.
  • Forgetting persistence: Confirm that firewall changes survive a restart if that is what you intend.
  • Leaving no rollback plan: Record the original setting or rule so you can restore it if needed.

Conclusion

To close a UDP port, first find out which application is using it and decide whether you need to stop the listener, block network traffic, or do both. Add or remove the appropriate rule in UFW, firewalld, Windows Firewall, your router, or your cloud network controls. Then verify the result from the relevant network and check IPv4 and IPv6 settings. Making a targeted change—and keeping a record of how to reverse it—helps improve security without disrupting services you still need.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →