UFW (Uncomplicated Firewall) is a firewall utility that makes it easy to configure and manage the firewall on a Ubuntu 18.04 LTS server. Here is how you can set up a UFW firewall on Ubuntu 18.04 LTS server:
UFW is pre-installed on Ubuntu 18.04 LTS, so you don't need to install it. If it is not installed, you can install it using the following command:
refer to:uttualri.comsudo apt-get install ufw
By default, UFW allows all incoming and outgoing traffic. To set the default policies for incoming and outgoing traffic, run the following commands:
sudo ufw default deny incoming sudo ufw default allow outgoing
This will deny all incoming traffic and allow all outgoing traffic.
To allow specific services or ports, you can use the ufw allow
command. For example, to allow SSH connections, use the following command:
sudo ufw allow ssh
To allow HTTP and HTTPS connections, use the following command:
sudo ufw allow 80/tcp sudo ufw allow 443/tcp
You can also specify a specific IP address or IP range to allow or deny access. For example, to allow access from a specific IP address, use the following command:
sudo ufw allow from <ip-address>
After you have set the default policies and allowed specific services or ports, you can enable UFW using the following command:
sudo ufw enable
This will activate the firewall and apply the rules that you have set.
To check the status of UFW and view the firewall rules, you can use the ufw status
command. This will show the active firewall rules and the default policies for incoming and outgoing traffic.