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.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

CentOS 7.x Firewall: Enable/Disable and Add Ports

  In CentOS 7.x, the default firewall is firewalld. Here is an example using CentOS 7.6...

How to enable/disable ping on Linux system

To prevent others from discovering and potentially attacking your machine through network ping...

How to View Memory Usage and Clear Cache in Linux System

Sometimes, when a server becomes unresponsive, it may not necessarily be due to high CPU usage....

How to remotely access a Linux system using Putty tool

Introduction to Putty software PuTTY is a Telnet, SSH, rlogin, raw TCP, and serial interface...

Linux System RuiSu Installation Tutorial

Note: The prerequisite for installing RuiSu is to ensure that the network card is in the "eth"...