Enabling and disabling the firewall in Ubuntu

一.Overview

The firewall is a security device or software used to protect computer networks. In Ubuntu systems, the ufw (Uncomplicated Firewall) tool can be used to configure firewall rules to restrict network traffic entering and leaving the system.

 

ufw is a command-line-based tool that provides a simplified interface for configuring the firewall. It allows users to easily set and manage firewall rules. ufw supports firewall rules based on ports, protocols, IP addresses, and network interfaces, and allows users to enable or disable the firewall with ease.

 

Here are the basic steps to configure the firewall using the ufw tool:

 

 

二.Install

ufw If ufw is not installed on your Ubuntu system, you can install it using the following commands:

  • sudo apt update
  • sudo apt install ufw

 

Enable/Disable ufw

To enable the ufw firewall, use the following command:

  • sudo ufw enable

To disable the ufw firewall, use the following command:

  • sudo ufw disable

 

三.Configure ufw rules

1.You can use ufw to allow specific ports/protocols.

For example, the following commands allow incoming traffic for HTTP (port 80) and HTTPS (port 443):

  • #sudo ufw allow 80/tcp #sudo ufw allow 443/tcp

2.You can allow traffic from specific IP addresses.

For example, the following command allows traffic from the IP address 192.168.1.100:

  • #sudo ufw allow from 192.168.1.100

3.You can allow traffic from specific subnets.

For example, the following command allows traffic from the subnet 192.168.1.0/24:

  • #sudo ufw allow from 192.168.1.0/24

4.You can allow traffic on specific network interfaces.

For example, the following command allows traffic on the eth0 network interface:

  • #sudo ufw allow in on eth0

5.Allowing/Disallowing specific applications

You can allow or deny traffic for specific applications. For example, the following command allows traffic for the SSH service:

  • #sudo ufw allow OpenSSH

To deny traffic for a specific application, replace "allow" with "deny".

6.View the current firewall rules.

View current firewall rules You can use the following command to view the current ufw firewall rules:

  • #sudo ufw status

This will display the currently enabled firewall rules, including allowed or denied ports, protocols, IP addresses, network interfaces, and applications.

 

四.Precautions

When configuring firewall rules, it is important to proceed with caution and ensure that only necessary traffic is allowed while blocking unnecessary traffic to maximize system security.

Before configuring firewall rules, it is recommended to back up system configurations and firewall settings for easy recovery if needed.

The order of firewall rules is crucial as rules are matched in a top-down fashion. Therefore, when adding firewall rules, pay attention to the order to ensure that rules take effect as intended.

In addition to using the ufw tool, it is also possible to directly edit the /etc/ufw/ufw.conf file to configure firewall rules. However, exercise caution and follow the correct syntax and format.

This is just a brief Ubuntu firewall documentation, covering basic concepts and steps for configuring a firewall using the ufw tool. In practice, detailed firewall configurations should be based on specific requirements and security policies, following best practices to ensure system security and stability.

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How to switch to a different repository for CentOS 8 EOL

 CentOS 8 reached its end of life at the end of 2021. When using yum repositories for...

To change the network interface name in CentOS 7.x

一.modify GRUB 1.Edit the GRUB configuration file by running the command: `vi...

To modify the hostname on CentOS

Method One:   1.Open a terminal or SSH into the Linux system. 2.Log in to the system with...

An incorrect configuration in the /etc/fstab file on the Linux system is causing login issues

Encountering communication issues with the machine, I checked the system error messages through...

How to use the atop monitoring tool in Linux

Atop is a monitoring tool used to monitor resources and processes in Linux systems. It...