How to Secure Linux Server

How to Secure Linux Server

Firewall is a system of securing Linux Server which is designed to prevent unwanted access from or to the local network. With a firewall, it allows us to do connection tracing, which later we can choose whether the connection will be forwarded, dropped, or rejected.

By default, GNU Linux itself has a built in firewall, namely netfilter or iptables. However, the configuration is quite complicated. So, we can use UFW which can be used to facilitate firewall configuration.

Steps to Configure Firewall with UFW

The following are the steps you can take if you want to configure a firewall using UFW on Secure Linux Server.

Install UFW

The first thing you definitely have to do is install UFW, the method is as follows:

To install UFW, you can use the apt gate package management. To install it, just type the command below, then press enter.

install UFW

  • Then enter the password “root”, and press enter

install UFW pass root

  • Now UFW is installed on your Linux

install ufw di linux

Check the UFW Service

If it is installed, then the next step is to check whether the UFW service is running well or not, the method is:

  • In apt gate management, type the following command:

Cek Service UFW

As you can see, the status of UFW is still inactive, so the service is still not running.

Basic Configuration

The next step is to do a basic configuration. So, make sure the UFW does not become your weapon. As you know, the purpose of this firewall is to block unwanted access. Don’t get blocked connections.

  • The first step is to deny incoming and allow outgoing. The command is like this:

Basic Configuration

So, you can give an example if the Linux server you have is on a VPS. To root it usually is to establish an SSH connection. So, make sure the SSH service has been allowed first.

Allow SSH and Web Server

To allow SSH is to type a command like this:

Allow SSH dan Web Server

If possible SSH uses the TCP protocol and port 22, so the command would be like this:

protokol TCPIf you are sure that the connection you are using has been allowed, you can enable UFW by using the command:

enable UFW

After successfully activating and allowing basic configuration of UFW, next is to check if the rule is running properly or not.

Check whether UFW is working properly

  • Check the status by typing a command like this:

Cek UFW

Here you can see that the TCP protocol and port 22 have been allowed.

  • In this example server, there are already many services running to run UFW.

port 22

  • You can verify whether this UFW rule has been running or not by accessing one of the services that have been allowed. For example, telnet and http are missing in this example.

Before that, you have to check how many ip by typing the command as below:

rule UFW

  • Open a browser and type in the URL bar for the ip address.

URL bar ip address

If you have loaded like this and don’t open the landing page, chances are that the UFW service is already running well.

  • Check back on the server and type a command like this:

Cek kembali pada server

In the picture above, only the SSH status is running well.

  • Now try to allow other services by typing the following command:

allow layanan

You can see if there are 3 firewall rules on your UFW and that is the sign, these three services have been allowed by UFW to be accessible from the public.

  • Please verify again, whether it can run well or not.

verifikasi kembali

If it can be opened with an IP that cannot be opened, then UFW can run properly. Now the 9090 port can also be opened properly.

port 9090

So, this UFW firewall can work properly.

Allow Telnet

Allow Telnet

All rules have worked well, but telnet is still not allowed and we still don’t know whether it can work or not. So the way is like this:

  • Open a terminal, then type the command telnet

ketikkan perintah telnet

  • Type ip telnet underneath

ip telnet

If it’s still trying, it’s still blocked with a Firewall.

How to Allow Multiple Ports Quickly

To allow multiple ports at once, the point is to be able to configure this UFW firewall quickly. The method is as follows:

  • Suppose you are going to allow ports from 1000 to 2000. You do this by typing the following command:

allow port

These are the commands for UFW on the tcp protocol.

  • Then try adding the allow port again in the same way but on the udp port. The method is not much different:

port udp

  • Now try to verify

coba verifikasi

Here you have succeeded in adding 1000 to 2000 rules for the TCP and UDP protocols.

How to Allow UFW Based on Specific IP Address

To allow UFW configuration based on a specific IP address is as follows:

Cara Allow UFW Berdasarkan IP Address Tertentu

  • Type in the IP address that you will allow as shown above
  • The next step is to verify by typing the command as below:

firewall UFW

How to Delete Rules on UFW

The way to remove rules on the UFW firewall is quite simple

Cara Menghapus Rule pada UFW

  • Just add “delete” before the allow command. And the rule has been successfully deleted.
  • Try to verify whether it has been deleted or not.

perintah allow

You can see that the rule that was deleted has been verified and has indeed been deleted.

How to Reset UFW

Reset UFW is usually very necessary, this is so that the configuration that has been made can be lost, you can do the command as below:

Cara Reset UFW

Here all rules have been reset successfully, now verify so that you are sure whether all rules have been successfully reset or not.

reset UFW

How to Stop the UFW Firewall Service

The method is quite easy, you can use the command as below:

Cara Menghentikan Service Firewall UFW

You can see, the UFW firewall status is no longer active.

Want to know more about Securing Linux Server? You can contact us for further questions. This is the way to secure Linux servers by using the UFW Firewall. Hopefully it can be helpful and useful for you to secure your Linux server or maybe just a study reference!

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *

Semua operasional PT. Network Data Sistem akan menggunakan domain nds.id per tanggal 8 Mei 2019. Semua informasi/promosi dalam bentuk apapun selain menggunakan domain nds.id bukan tanggung jawab PT. Network Data Sistem Dismiss