ufw-insert
Insert an Uncomplicated Firewall rule at a numbered position
TLDR
SYNOPSIS
ufw [--dry-run] insert NUM allow|deny|reject|limit [rule]ufw [--dry-run] route insert NUM allow|deny|reject|limit [rule]
DESCRIPTION
ufw insert adds an Uncomplicated Firewall rule at a specific position instead of appending it. It is a ufw subcommand, not a separate binary.The first matching rule wins, so position is the point of the command. With four rules already loaded, `ufw insert 3 deny to any port 22 from 10.0.0.135 proto tcp` makes the new rule number 3 and shifts the previous third and fourth rules down.prepend is the form that does not take a number: it places the rule ahead of every existing rule of the same IP version. route insert uses the same numbering for traffic forwarded through the host.
PARAMETERS
insert NUM
Place the new user rule at that 1-based position. Later rules shift down. Read positions from `ufw status numbered`route insert NUM
Same positioning for a forwarded rule. See ufw routeallow / deny / reject / limit
Action of the inserted rule. The rest of the line is normal ufw rule syntax: a port, an application profile, or the full from / to / port / proto / on formcomment 'text'
Attach a comment to the new rule. insert cannot change the comment on a rule that already exists--dry-run
Show what would change without applying it
INSTALL
CAVEATS
Requires root or sudo. Check `ufw status numbered` immediately before inserting. Deletes and earlier inserts renumber the list. Inserting a rule that blocks the current SSH session can lock you out. Prefer --dry-run on a remote host.When IPv6 is enabled, a generic rule such as `ufw allow 22/tcp` creates paired IPv4 and IPv6 entries. insert adds a rule; it does not rewrite rules already in the list.
HISTORY
Part of ufw (Uncomplicated Firewall), the Ubuntu-originated frontend for iptables and nftables.
SEE ALSO
ufw(8), ufw-prepend(8), ufw-delete(8), ufw-status(8), ufw-allow(8), ufw-route(8), iptables(8)
