Free tools Windows power users keep installed
One-click scans. No signup required.
The safe way to combine iptables and UFW is to leave UFW’s generated chains under its control and place your own rules in /etc/ufw/before.rules or /etc/ufw/after.rules. Those files use iptables-restore syntax. Rules in before.rules run before rules created by ufw allow; rules in after.rules run afterward. Reload UFW, then verify with sudo iptables -S or sudo ufw show raw because ufw status does not list these custom rules.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What “combining iptables and UFW” actually means
UFW is not a separate packet-filtering engine that runs beside iptables. On Ubuntu, UFW is a management layer that writes iptables rules and connects its own chains to the kernel’s built-in INPUT, FORWARD and OUTPUT chains. A typical ruleset contains chains such as ufw-before-input, ufw-user-input, ufw-user-limit and ufw-user-limit-accept.
As an Amazon Associate I earn from qualifying purchases.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Commands such as sudo ufw allow 443/tcp populate UFW’s user chains. UFW then regenerates those chains when it is enabled or reloaded. Hand-editing ufw-user-input, or relying on an ad-hoc iptables -A command at a shell prompt, therefore creates a rule outside UFW’s intended configuration model.
The durable arrangement is:
- Use
ufw allow,ufw denyand related commands for ordinary service-policy rules. - Put additional filter rules in
/etc/ufw/before.ruleswhen they must be evaluated ahead of UFW’s user rules. - Put additional filter rules in
/etc/ufw/after.ruleswhen they should be evaluated after UFW’s user rules. - Use
/etc/ufw/before6.rulesand/etc/ufw/after6.rulesfor IPv6 rules.
UFW processes the “before”, user and “after” stages in that order. A terminating match, such as ACCEPT or DROP, stops traversal, so placement determines whether a custom rule can override a later rule.
#1 Best Overall
- 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.
Understand the packet path before choosing a chain
First decide whether the packet is destined for the server, passing through it, or leaving it. Traffic to a local service enters INPUT; routed traffic uses FORWARD; traffic generated by the host uses OUTPUT. UFW attaches its before, user and after chains to those built-in paths. A rule inserted in ufw-before-input cannot control a forwarded packet that never traverses INPUT.
Use sudo iptables -S to see the jumps and the exact chain in which a rule was loaded. For a forwarding change, inspect the FORWARD path and test both directions. For a host service, confirm the listening address and the interface selected by the packet. Mapping the path first prevents a syntactically correct rule from appearing ineffective simply because it was placed in the wrong chain.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Choose the right place for each rule
| Method | When it runs | Survives UFW regeneration? | Visible in ufw status? |
Main risk |
|---|---|---|---|---|
/etc/ufw/before.rules |
Before rules added with ufw allow or ufw deny |
Yes, when kept in the file | No; inspect with iptables tools or ufw show raw |
An early broad accept can bypass a later restriction |
/etc/ufw/after.rules |
After UFW’s user rules | Yes, when kept in the file | No | A preceding accept may prevent a later drop from being reached |
Direct iptables -A command |
Immediately, in the chain named by the command | Not reliably; UFW does not manage it | No | It can disappear on reboot or conflict with a later UFW reload |
ufw allow/ufw deny |
In UFW’s user chains | Yes, through UFW’s normal configuration | Yes | It is not suitable for every advanced match or NAT rule |
For a simple public port, the supported UFW command is usually the clearest choice. Use the rule files for matches UFW cannot express conveniently, special ordering, forwarding, or NAT.
Before editing: protect access and record the current state
Firewall changes can disconnect you. Open a second SSH session, keep an out-of-band console available, or make sure your hosting provider offers a recovery console before touching the rules. Do not close your known-good session until the new rules have been tested from a separate connection.
- Confirm the distribution and UFW files. The paths in this guide are the Ubuntu layout. On another distribution, check the installed UFW package and its documentation instead of assuming the same filenames.
- Save the current files.
sudo cp -a /etc/ufw/before.rules /etc/ufw/before.rules.bak
sudo cp -a /etc/ufw/after.rules /etc/ufw/after.rules.bak
sudo cp -a /etc/ufw/before6.rules /etc/ufw/before6.rules.bak
sudo cp -a /etc/ufw/after6.rules /etc/ufw/after6.rules.bak - Capture the active rules.
sudo ufw status verbose
sudo ufw show raw
sudo iptables -S
sudo ip6tables -Sufw statusis useful for UFW-managed policy, while the iptables commands expose the complete filter view, including custom entries. - Check for another persistence service. Look for
iptables-persistentornetfilter-persistent. Launchpad bug 1987227 documents cases in which those packages interfere with UFW enabling and can leave traffic blocked. Decide which service owns the saved ruleset before proceeding.
Add a filter rule to before.rules
before.rules is an iptables-restore file, not a shell script. It normally contains a *filter section, chain declarations, rules and a COMMIT line. Every table section must end with its own COMMIT. Do not paste a shell command such as sudo iptables -A ... into the file.
Insert the rule in the existing filter section
Open the file with an editor and locate the existing *filter block. Add your rule to the appropriate chain before that block’s COMMIT. For example, the following permits TCP port 8443 only from the documentation subnet shown; replace the address and port with values appropriate to your server:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11*filter
# Existing UFW chain declarations and rules remain above this point
-A ufw-before-input -p tcp --dport 8443 -s 203.0.113.0/24 -j ACCEPT
COMMIT
The example uses ufw-before-input, so it is evaluated before UFW’s user-input rules. A rule that should apply only after UFW has processed its user policy belongs in the corresponding chain in after.rules, normally ufw-after-input or another chain already present in that file. Preserve the file’s existing declarations; do not create a second copy of a chain with the same name.
Rank #2
- 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
Put narrow matches before broad matches
iptables evaluates rules from top to bottom. A terminating verdict is final for that traversal. Place a source-specific, interface-specific or protocol-specific rule before a broad rule that could accept or drop the same packet. For example, a source-restricted SSH exception must appear before a general SSH drop if the exception is meant to work.
Do not edit ufw-user-input directly. UFW owns that chain and can rewrite it. Add the rule to a supported rule file or express it with a UFW command instead.
Use after.rules when the rule must run later
The mechanics are the same: edit the existing *filter section, add the rule before its COMMIT, and keep the iptables-restore syntax valid. The difference is ordering. An after.rules rule cannot undo a previous terminating ACCEPT, because that packet will never reach the after stage. This makes after.rules suitable for additional logging, cleanup and restrictions that should apply only to traffic not already accepted by UFW’s user rules, but unsuitable for overriding an allow that has already matched.
Handle IPv6 separately
IPv4 and IPv6 are loaded from different files. Mirror an intended policy in /etc/ufw/before6.rules or /etc/ufw/after6.rules using IPv6 addresses and ip6tables syntax. Editing only before.rules leaves an IPv6 path governed by a different ruleset. Conversely, adding an IPv6 rule to a file on a host with no IPv6 traffic does not replace the need to check whether IPv6 is enabled elsewhere in the operating system or hosting platform.
Add forwarding and NAT without breaking the filter file
Forwarded traffic
For extra forwarding policy, the Ubuntu Server firewall documentation recommends placing the rule in the ufw-before-forward chain inside before.rules. Use the same restore-file rules: add the -A ufw-before-forward ... line inside the existing *filter section and leave its COMMIT in place.
Forwarding also depends on the host’s routing configuration and UFW’s forwarding policy. A syntactically valid rule cannot make a kernel that is not routing packets forward them. Test both directions and check the interface and source/destination selectors used by the rule.
Masquerading and other NAT rules
NAT belongs in a separate *nat section. Add that section after the existing filter section, give it its own COMMIT, and do not put NAT targets in the *filter table. A minimal shape is:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsRank #3
- 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)
*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 10.20.0.0/24 -o eth0 -j MASQUERADE
COMMIT
Replace the private network and interface with the values on your server. NAT and forwarding are separate decisions: the masquerade changes source addresses, while filter rules still determine whether forwarding is permitted. Test return traffic and confirm that the selected egress interface is stable.
Reload safely and verify the result
- Check the file before applying it. Review for an accidental duplicate table header, a missing chain declaration, an unmatched quote, or a missing
COMMIT. Keep the backup immediately available. - Apply the change. On releases that support it, use
sudo ufw reload. The documented fallback issudo ufw disable && sudo ufw enable; run it from the protected console or while your second SSH session is active. - Confirm the chains and rules.
sudo iptables -S
sudo iptables -L -n -v
sudo ufw show raw
For IPv6, usesudo ip6tables -Sandsudo ip6tables -L -n -v. - Test from the intended networks. Check an allowed connection, a connection that should be denied, and (for forwarding or NAT) a complete outbound and return path. Test by address family; an IPv4 success does not prove IPv6 is correct.
- Check the counters later. The packet and byte counters from
iptables -L -n -vshow whether traffic is reaching the rule. A zero counter can indicate a wrong interface, address family, port, or rule order rather than a syntax failure.
Do not use a clean-looking ufw status output as proof that the custom rule is absent. UFW’s status view lists rules created through its user-facing commands, not every line loaded from the before/after files.
Why a rule can remain after UFW is stopped
UFW’s stop and restart behavior around built-in chains has varied by release and configuration. Launchpad bug 881137, titled “UFW does not clean iptables setting from /etc/ufw/before.rules,” records the behavior in which rules from before.rules remain. Ubuntu developers have explained that clearing built-in chains automatically could remove rules placed there by other software. The exact result depends on the UFW version and settings.
If a stop operation must manage those built-ins, investigate the MANAGE_BUILTINS setting and the before.init/after.init hooks documented for the installed release. Treat those controls as version-specific. Never assume that sudo ufw disable means every rule in the kernel has disappeared; verify with iptables -S.
Docker and other software that edits iptables
Container runtimes may create their own chains and insert jumps in the forwarding path. A community recipe for Docker creates or uses a DOCKER-USER chain, jumps from it to ufw-user-input, places RETURN rules for private ranges, and removes those additions from an init hook when the firewall stops. That is a community approach, not a guarantee from current Docker or UFW documentation, and it was not validated across current versions.
If containers are involved, first map the actual path with sudo iptables -S (and the corresponding IPv6 command where applicable). Confirm whether the host is using legacy iptables or an iptables-nft compatibility layer. Test published ports, container-to-container traffic, host-to-container traffic and outbound connections separately. Do not copy a recipe written for one Docker/UFW release into production without checking its chain names and ordering.
iptables-nft and changing backends
On newer distributions, the iptables command may be a compatibility interface backed by nftables. In that case, iptables -S still reports the compatibility ruleset, while other software may be writing native nftables rules. The searches behind this guide did not establish one behavior for every current distribution. Identify the active backend on the target host, avoid managing the same policy independently through both interfaces, and validate the actual packet path after every change.
Rank #4
- 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
Keep one service responsible for persistence
UFW’s rule files are the durable home for custom entries when UFW is the firewall manager. A second restore service can load an older snapshot at boot or while UFW is being enabled, producing duplicate chains, unexpected ordering or a complete lockout. Check package status and boot hooks for iptables-persistent and netfilter-persistent, then choose one owner for the saved policy. If another application must install rules, document which chains it owns and test the combined order after updates.
Plan a rollback before you reload
Keep the original files and the exact pre-change output of iptables -S and ufw show raw. If a reload fails, use the console or still-open SSH session to restore the backups, remove the last custom block, and reload again. If the syntax is accepted but access is blocked, compare the new and old chain order and look for an early broad ACCEPT or DROP. Do not close the recovery connection until an independent test confirms the intended access.
Troubleshooting by symptom
The new rule does not appear
- Check that it was inserted before the correct
COMMITin the intended table. - Reload UFW; editing a file alone does not load it into the kernel.
- Inspect
sudo iptables -Sorsudo ufw show raw, not onlyufw status. - For IPv6 traffic, confirm that the rule was added to a
before6.rulesorafter6.rulesfile.
The rule is present but never matches
- Check source address, destination address, protocol, port and interface.
- Look for an earlier terminating rule in the same path.
- Watch packet counters while making a controlled test connection.
- Ensure the traffic is entering
INPUT, traversingFORWARDor leaving throughOUTPUTas you assumed.
Reload fails or the server becomes unreachable
- Use the console or your still-open second session to restore the backup files.
- Remove the last custom block or correct the missing declaration or
COMMIT. - Reload again and inspect the resulting rules with
iptables -S. - Only after connectivity is restored should you close the recovery session.
Rules return after a stop or conflict with another service
Compare the output before and after stopping UFW, then check for iptables-persistent, netfilter-persistent, container software and native nftables services. Establish one owner for persistent policy and remove or coordinate duplicate restore mechanisms.
A repeatable operating procedure
For ongoing administration, document each custom rule with its purpose, address scope, protocol, table, chain and intended order. Keep the backup beside your change record, apply changes during a console-access window, and verify both the UFW view and the kernel’s complete ruleset. This discipline prevents a later UFW reload, package upgrade or container installation from silently changing the path you tested.
Frequently Asked Questions
Can I run iptables -A while UFW is enabled?
You can add a rule at the shell, but UFW will not manage it. It may disappear on reboot, be bypassed or reordered during a UFW reload, and conflict with another persistence service. Use before.rules or after.rules for a durable custom rule.
Why does ufw status not show my custom iptables rule?
That status view lists rules created through UFW’s user commands such as ufw allow and ufw deny. Rules loaded from the before/after files are still active but are outside that summary. Inspect them with sudo iptables -S, the verbose list command, or sudo ufw show raw.
Should a rule go in before.rules or after.rules?
Use before.rules when the rule must be evaluated before UFW user rules, such as a narrowly scoped exception that must precede a general decision. Use after.rules for policy that should apply only after UFW’s user chains have run. A later rule cannot undo an earlier terminating ACCEPT or DROP.
Best Value
- 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.
Do I need to edit IPv6 files too?
Yes, if the policy is intended to cover IPv6. IPv4 uses before.rules and after.rules; IPv6 uses before6.rules and after6.rules. Test each address family separately because successful IPv4 connectivity says nothing about the IPv6 path.
Where do forwarding and masquerading rules belong?
Add extra filter rules for routed traffic to the ufw-before-forward chain in the existing *filter section. Put masquerading in a separate *nat section after the filter section, with its own COMMIT. NAT changes addresses but does not by itself permit forwarding.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Why are rules still present after ufw disable?
Behavior around built-in chains varies by UFW release and configuration. Launchpad bug 881137 records rules from before.rules remaining because automatically clearing built-in chains could remove rules installed by other software. Check iptables -S, and consult the installed release’s MANAGE_BUILTINS, before.init and after.init documentation.
What should I check when Docker and UFW both manage firewall rules?
Inspect the actual chain order instead of assuming a community recipe applies. Docker may add its own chains and forwarding jumps. Verify whether DOCKER-USER exists, identify the legacy or iptables-nft backend, and test published ports, container traffic and outbound connections separately. Treat recipes that jump to ufw-user-input as version-dependent.
How do I avoid locking myself out during a change?
Back up all relevant files, keep a second SSH session or provider console open, reload from that protected access, and test an independent connection before closing it. If the reload fails, restore the backups and correct the table, chain declaration or missing COMMIT before trying again.
The Bottom Line
Use UFW commands for ordinary ports and keep advanced rules in UFW’s own restore files. Put early decisions in before.rules, later decisions in after.rules, mirror IPv6 policy in the corresponding *6.rules files, and place NAT in its own table with its own COMMIT. Reload from a protected session and verify the complete kernel ruleset with iptables tools—never rely on ufw status alone.
Recommended Free Tools
Quick Recap
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.




