📜  ufw add rule with comment - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:35:27.113000             🧑  作者: Mango

ufw add rule with comment - Shell-Bash

Introduction

The ufw command is a simple, user-friendly interface for managing the iptables firewall on Ubuntu/Debian systems. In this tutorial, we will discuss the ufw add rule with comment command and how it can be used to add a new firewall rule with a descriptive comment.

Syntax

The syntax for the ufw add rule with comment command is as follows:

sudo ufw insert [NUM] [allow|deny] [from ADDRESS] [to ADDRESS] [port PORT] [proto PROTOCOL] [comment 'COMMENT']
Options
  • NUM: The position in the firewall rule order where the new rule should be added. Defaults to the end of the chain.
  • allow|deny: Whether to allow or deny traffic that matches the rule.
  • from ADDRESS: The source IP address or network to allow/deny traffic from.
  • to ADDRESS: The destination IP address or network to allow/deny traffic to.
  • port PORT: The port number or range to allow/deny traffic on.
  • proto PROTOCOL: The protocol (TCP/UDP) to allow/deny traffic on.
  • comment 'COMMENT': The descriptive comment to add to the new firewall rule.
Usage

To add a new firewall rule with a descriptive comment, use the following command format:

sudo ufw insert [NUM] [allow|deny] [from ADDRESS] [to ADDRESS] [port PORT] [proto PROTOCOL] [comment 'COMMENT']

For example, to add a rule to allow SSH access from the IP address 192.168.1.100 with the comment Allow SSH access from office network, use the following command:

sudo ufw insert 1 allow from 192.168.1.100 to any port 22 proto tcp comment 'Allow SSH access from office network'
Conclusion

In this tutorial, we discussed the ufw add rule with comment command and how it can be used to add a new firewall rule with a descriptive comment. By including a comment with each firewall rule, system administrators can better understand and manage their firewall rules.