ufw Command in Linux

Learn via video courses
Topics Covered

Overview

The Uncomplicated Firewall (UFW) is a user-friendly front-end for managing iptables firewall rules in Linux. The main purpose of UFW command in Linux is to simplify the process of configuring a firewall on your system. With UFW, you can create an IPv4 or IPv6 host-based firewall that will protect your system from unauthorized access.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax of ufw Command in Linux

The basic syntax of the ufw command in Linux is as follows:

Where:

  • options: These are optional arguments that modify the behavior of the ufw command. Examples include --dry-run, --verbose, etc.
  • command: This is the action you want ufw to execute. Examples include enable, disable, status, allow, deny, etc.

Options in ufw Command in Linux

  1. --dry-run: Displays what rules would be added or removed, but does not make any changes.

    For example -

    Output:

    This shows what would happen if the ufw was enabled but does not actually make any changes.

  2. --verbose: Displays more information.

    For example -

    Output:

    This provides a more detailed status of the ufw.

  3. --force: Force enable or disable of ufw, without asking for confirmation.

    For example -

    Output:

    This forcefully disables the ufw without any confirmation prompt.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Example Usages

  • Enabling the ufw:

    Output:

    Explanation: This command enables the ufw on your system.

  • Blocking an IP address:

    Output:

    Explanation: This command blocks all incoming traffic from the specified IP address.

Tips

  • Always test your rules with --dry-run before applying them.

  • The ufw reset command will disable and reset firewall to installation defaults.

  • Use ufw status numbered to get a numbered list of all firewall rules for easy reference.

Advanced Use Cases of ufw Command in Linux

  • Allowing access to a specific port:

    Output:

    Explanation: This command allows all incoming traffic to port 22, commonly used for SSH.

  • Limiting rate of incoming connections:

    Output:

    Explanation: This command limits the rate of incoming connections to the SSH port (usually port 22) to help prevent brute-force attacks.

  • Allowing access from a specific network to a specific port:

    Output:

    Explanation: This command allows all incoming traffic to port 22 from the specified network.

Conclusion

  • The ufw command in Linux is a powerful tool for managing your firewall rules.

  • UFW simplifies the process of configuring a firewall on your system.

  • Remember to always use --dry-run before applying rules to check for potential errors.

  • UFW supports both IPv4 and IPv6.