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
World desk8 min

UFW Essentials: Common Firewall Rules and Commands for Linux

A practical UFW guide for Ubuntu and similar Linux systems, covering the safe SSH-first setup, common rules, defaults, logging, troubleshooting, and rule management.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

UFW (Uncomplicated Firewall) is Ubuntu’s simpler command-line front end for building host firewall rules. A safe first setup is to deny unsolicited incoming traffic, allow outgoing traffic, permit SSH before turning the firewall on, enable UFW, and then add only the services your machine must expose. The commands below cover that workflow, rule syntax, source restrictions, rate limiting, logging, deletion, recovery, and the limits of what UFW’s interface can configure.

What UFW is—and what it is not

UFW provides a friendlier way to manage firewall rules than working directly with iptables. It can build rules for IPv4 and IPv6 and is available by default in Ubuntu installations beginning with Ubuntu 8.04 LTS. Ubuntu ships it disabled, so installing Ubuntu does not automatically activate these rules.

As an Amazon Associate I earn from qualifying purchases.

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

UFW is a host-based firewall: it controls traffic entering or leaving the individual Linux system where it is configured. It is useful on a server, desktop, virtual machine, or cloud instance, but it is not a replacement for a network firewall, cloud security group, intrusion-prevention system, or application-level access control.

Canonical’s Ubuntu Server documentation also cautions that UFW’s command interface is not intended to expose every firewall capability. It is designed for adding and removing straightforward rules. Advanced packet-filtering requirements may need another layer or direct firewall tooling. For syntax supported by the exact version installed on your machine, treat man ufw as the final reference.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Check the current state before changing anything

Always inspect the existing configuration first. A system may already have rules created by an image, provisioning script, or administrator.

Command What it shows
sudo ufw status Whether UFW is active and a short view of rules.
sudo ufw status verbose Status plus default policies and the logging level.
sudo ufw status numbered Rules with numbers, which is the safest way to identify one for deletion.
sudo ufw app list Application profiles installed on the system, such as an OpenSSH profile.

An inactive result means UFW is not enforcing the stored rules. The rules can still be present; enforcement begins only after sudo ufw enable.

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

Prepare a safe baseline

The commonly used baseline is to reject unsolicited inbound connections while allowing the host to initiate outbound connections. Set these policies before adding service-specific exceptions:

sudo ufw default deny incoming
sudo ufw default allow outgoing

The first command applies to inbound traffic that does not match a more specific allow rule. The second permits normal outbound connections unless a more specific rule says otherwise. This is a policy choice, not a substitute for reviewing which services are listening on the machine.

Allow SSH before enabling UFW

If you are connected remotely over SSH, create the SSH exception before enabling the firewall. Enabling UFW without an SSH allow rule can terminate your management connection and lock you out of the host.

You can allow the standard TCP port directly:

sudo ufw allow 22/tcp

Or use the installed application profile:

sudo ufw allow OpenSSH

The profile name must exist in sudo ufw app list. If SSH runs on a different port, allow that actual TCP port instead of 22. Keep an already-open administrative session available while testing a new policy, and verify a second connection before closing the first.

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

Enable, verify, and temporarily disable the firewall

Once the management path is allowed, activate UFW:

sudo ufw enable

UFW normally confirms that the firewall is active. Immediately inspect the result:

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
sudo ufw status verbose

To stop enforcement without deleting the configured rules, run:

sudo ufw disable

Disabling is useful for controlled troubleshooting, but it leaves the machine without UFW filtering. Re-enable it with sudo ufw enable after testing.

Common allow rules

Rules can name a port and protocol or refer to an application profile. TCP and UDP are separate: allowing one does not automatically allow the other.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Purpose Command Result
Allow SSH on the standard port sudo ufw allow 22/tcp Permits TCP connections to port 22.
Allow DNS over UDP sudo ufw allow 53/udp Permits UDP traffic to port 53.
Allow HTTP by service name sudo ufw allow http Uses UFW’s service definition for HTTP.
Allow HTTPS by service name sudo ufw allow https Uses UFW’s service definition for HTTPS.
Allow an installed profile sudo ufw allow OpenSSH Uses the matching application profile.

After adding a rule, check the active list with sudo ufw status numbered. Do not open a port merely because software is installed; first confirm that the service should be reachable and from which networks.

Restrict rules by source address

Leaving a service open to every source is often unnecessary. UFW can scope an allow rule to one host or a subnet.

sudo ufw allow from 192.168.10.0/24
sudo ufw allow from 192.168.1.7 port ssh

The first example allows traffic from every address in the 192.168.10.0/24 subnet. The second allows SSH from one specified host. Restricting administration to a trusted network reduces exposure, but make sure the source address is stable: a changing residential or mobile address can make a valid rule appear to stop working.

You can also block one source from an individual service. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
sudo ufw deny from 192.0.2.44 to any port 22 proto tcp

Use an address appropriate to your own environment; the documentation example of blocking an individual address from SSH illustrates the same principle.

Deny, reject, and rate-limit traffic

Deny

A deny rule drops matching traffic without accepting the connection. For example:

sudo ufw deny 3306/tcp

This explicitly blocks TCP port 3306, even if another broader rule might otherwise permit it. Rule ordering and the complete rule set matter, so inspect the numbered status after changes.

Reject

A reject rule actively tells the peer that the connection is refused instead of silently dropping it. Apply the reject action to a specific service rule when an immediate refusal is preferable to a timeout, for example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo ufw reject 23/tcp

Whether reject or deny is preferable depends on the service and the information you want to reveal. A silent drop can make unwanted probes wait; an explicit rejection gives faster feedback to legitimate clients.

Limit

Use rate limiting for services that need to remain reachable but are frequent brute-force targets:

sudo ufw limit 22/tcp

This is intended to slow repeated SSH connection attempts. It is not a complete intrusion-prevention system and should not replace strong authentication, patching, or key-based SSH access.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Understand application profiles

UFW application profiles map a readable name to one or more ports and protocols. List the profiles available on the current machine:

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

Then allow a profile by its exact displayed name, such as:

sudo ufw allow OpenSSH

Profiles are local metadata, so names and definitions can differ between distributions or installed packages. If a profile is missing or does not match the service’s real listening port, use an explicit port rule and verify the application’s configuration separately.

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

Delete, reload, or reset rules

Delete by rule number

First list numbered rules:

sudo ufw status numbered

Then remove the unwanted entry by its displayed number:

sudo ufw delete NUMBER

Replace NUMBER with the actual number shown on your system. Numbers can change after a deletion, so rerun the numbered status command before removing another entry.

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.

Delete by repeating the original rule

You can also prefix the original rule with delete. For example:

sudo ufw delete allow 22/tcp

This is convenient when you know the exact rule text. If several similar entries exist, deleting by number makes the target unambiguous.

Reload without clearing rules

sudo ufw reload

Reload reapplies the configured rules. It does not erase them.

Reset everything

sudo ufw reset

Reset clears all UFW rules and returns the firewall to its initial disabled state. Treat it as a destructive operation: record the current configuration first if you may need to rebuild it.

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

Configure logging

Turn UFW logging on when you need evidence of blocked or allowed traffic:

sudo ufw logging on

UFW also supports named logging levels:

sudo ufw logging LEVEL

Replace LEVEL with a level supported by the installed version. Because logging volume and available levels can vary, check man ufw and your system’s log configuration before selecting a more verbose setting. Excessive firewall logging can consume disk space and obscure useful events.

A complete first-time sequence

For a typical Ubuntu server managed over SSH, this is the compact order of operations:

  1. sudo ufw default deny incoming
  2. sudo ufw default allow outgoing
  3. sudo ufw allow OpenSSH
  4. sudo ufw enable
  5. sudo ufw status verbose

Add rules for the services the host actually provides only after this baseline is verified. If the server offers web traffic, for example, add sudo ufw allow http and/or sudo ufw allow https; if it provides DNS, add the required protocol and port explicitly.

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

Troubleshoot the most common failures

“I enabled UFW and lost SSH access”

The usual cause is that no SSH rule existed before activation, or the rule allowed the wrong port or source network. Use an out-of-band console supplied by your host or virtualization platform, run sudo ufw status numbered, and add the correct SSH rule. If you cannot access a console, the provider may need to restore access. Do not disable SSH protection permanently just to regain convenience.

“The rule exists, but the service is unreachable”

  • Confirm UFW is active with sudo ufw status verbose.
  • Check that the service is listening on the port and protocol you allowed; TCP and UDP rules are independent.
  • Check source restrictions: a subnet or single-host rule may exclude the client you are testing.
  • Check upstream controls such as a cloud security group, router ACL, or provider firewall.
  • Inspect logs after enabling an appropriate logging level.

“I deleted the wrong rule”

Run sudo ufw status numbered again, then recreate the intended rule with its original command. Avoid repeated blind deletions because rule numbers shift after each removal.

“I need a feature UFW does not expose”

Read the installed manual with man ufw first. Ubuntu’s documentation describes UFW as an easy interface for simple rule management, not a complete firewall configuration language. For advanced matching, translation, or packet-processing requirements, use the firewall tooling appropriate to your distribution and operational design, and document how it interacts with UFW.

Operational checklist

  • Inspect existing rules before changing them.
  • Set inbound and outbound defaults deliberately.
  • Allow the correct SSH port and source before enabling UFW.
  • Open only required services, with the correct protocol.
  • Prefer source-restricted administration where practical.
  • Use status numbered before deleting anything.
  • Use logging during diagnosis, then review the resulting log volume.
  • Keep a tested recovery path, such as a provider console, before making remote firewall changes.
  • Verify command details against man ufw on the target system, especially when moving between Ubuntu releases or other Linux distributions.

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.

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.

Leave a Reply

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

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

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.