{"id":800,"date":"2023-01-07T21:46:44","date_gmt":"2023-01-07T21:46:44","guid":{"rendered":"https:\/\/formatswap.com\/blog\/?p=800"},"modified":"2023-07-10T14:01:05","modified_gmt":"2023-07-10T14:01:05","slug":"how-to-configure-a-firewall-in-linux-using-ufw","status":"publish","type":"post","link":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/","title":{"rendered":"How to Configure a Firewall in Linux using UFW"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"576\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-1024x576.jpg\" alt=\"ufw linux firewall splash image\" class=\"wp-image-829\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-1024x576.jpg 1024w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-300x169.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-768x432.jpg 768w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-1536x864.jpg 1536w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p>This tutorial will teach you how to install and configure <a href=\"https:\/\/en.wikipedia.org\/wiki\/Uncomplicated_Firewall\">UFW <\/a>(Uncomplicated Firewall) in Linux. Firewalls are vital to keep your applications and systems secure. UFW provides a command line frontend interface for <a href=\"https:\/\/en.wikipedia.org\/wiki\/Iptables\">iptables<\/a> using a few simple commands. It is designed to be easy to use and uncomplicated to configure. Using only <a href=\"https:\/\/en.wikipedia.org\/wiki\/Netfilter\">Netfilter <\/a>in <a href=\"https:\/\/en.wikipedia.org\/wiki\/Iptables\">iptables<\/a> for firewalls can be a daunting task. UFW is a simple solution to using a firewall in Linux. In this tutorial we will be using Ubuntu 22.04 but any <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ubuntu\">Ubuntu <\/a>or <a href=\"https:\/\/en.wikipedia.org\/wiki\/Debian\">Debian <\/a>based Linux distribution will work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Check if UFW is Installed<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"876\" height=\"657\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/2-verify-ufw-is-installed.png\" alt=\"ufw status\" class=\"wp-image-812\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/2-verify-ufw-is-installed.png 876w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/2-verify-ufw-is-installed-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/2-verify-ufw-is-installed-768x576.png 768w\" sizes=\"auto, (max-width: 876px) 100vw, 876px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw status<\/code><\/pre>\n\n\n\n<p>The first thing you need to do is check if UFW is already installed. It is installed by default on most Linux distributions. You can check if UFW is currently installed by opening a terminal shell and running the &#8220;ufw status&#8221; command. If UFW is already installed you will see a similar output to what is above. It will say &#8220;Status: inactive&#8221;. If you get an error you will have to install UFW.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install UFW<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"875\" height=\"660\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/3-install-ufw-if-not-installed.png\" alt=\"install ufw\" class=\"wp-image-813\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/3-install-ufw-if-not-installed.png 875w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/3-install-ufw-if-not-installed-300x226.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/3-install-ufw-if-not-installed-768x579.png 768w\" sizes=\"auto, (max-width: 875px) 100vw, 875px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo apt install ufw<\/code><\/pre>\n\n\n\n<p>To install UFW run the command &#8220;sudo apt install ufw&#8221;. Then click yes on the confirmation dialog.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deny Outgoing and Incoming Connections<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"878\" height=\"661\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/4-deny-outgoing-connections.png\" alt=\"ufw allow outgoing\" class=\"wp-image-815\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/4-deny-outgoing-connections.png 878w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/4-deny-outgoing-connections-300x226.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/4-deny-outgoing-connections-768x578.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw default allow outgoing<\/code><\/pre>\n\n\n\n<p>The first thing you want to do when configuring the firewall is to deny all incoming and outgoing connections. To deny outgoing connections run the command &#8220;sudo ufw default deny outgoing&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"877\" height=\"659\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/5-deny-incoming-connections.png\" alt=\"ufw allow deny incoming\" class=\"wp-image-816\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/5-deny-incoming-connections.png 877w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/5-deny-incoming-connections-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/5-deny-incoming-connections-768x577.png 768w\" sizes=\"auto, (max-width: 877px) 100vw, 877px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw default deny incoming<\/code><\/pre>\n\n\n\n<p>Then repeat the same step using &#8220;sudo ufw default deny incoming&#8221; to deny the incoming connections.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configure Firewall Rules<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Allow a Program<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"877\" height=\"658\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/6-allow-a-program.png\" alt=\"allow ftp ufw\" class=\"wp-image-817\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/6-allow-a-program.png 877w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/6-allow-a-program-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/6-allow-a-program-768x576.png 768w\" sizes=\"auto, (max-width: 877px) 100vw, 877px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw allow ftp<\/code><\/pre>\n\n\n\n<p>You can allow individual programs through the firewall using their names. Above I allow ftp using the command &#8220;sudo ufw allow ftp&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Allow a Specific Port<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"878\" height=\"659\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/7-allow-a-port.png\" alt=\"allow port 21 ufw\" class=\"wp-image-818\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/7-allow-a-port.png 878w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/7-allow-a-port-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/7-allow-a-port-768x576.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw allow 21<\/code><\/pre>\n\n\n\n<p>To allow a specific port use the command &#8220;sudo ufw allow 21&#8221;. In the above example I am allowing the FTP port 21.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Deny a Specific Port<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"877\" height=\"660\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/8-deny-a-port.png\" alt=\"deny port 22 ufw\" class=\"wp-image-819\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/8-deny-a-port.png 877w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/8-deny-a-port-300x226.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/8-deny-a-port-768x578.png 768w\" sizes=\"auto, (max-width: 877px) 100vw, 877px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw deny 22<\/code><\/pre>\n\n\n\n<p>You can also allow specific programs and ports. In the above example I deny port 22 using &#8220;sudo ufw deny 22&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Allow a TCP Port<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"879\" height=\"660\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/9-allow-port-tcp-only-png.png\" alt=\"allow tcp port 443 ufw\" class=\"wp-image-820\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/9-allow-port-tcp-only-png.png 879w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/9-allow-port-tcp-only-png-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/9-allow-port-tcp-only-png-768x577.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw allow 443\/tcp<\/code><\/pre>\n\n\n\n<p>You can also allow or deny specific ports to be tcp or udp only. In the above example I allow only tcp traffic on port 443.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Allow a UDP Port<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"879\" height=\"659\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/10-allow-a-udp-port.png\" alt=\"allow udp port 111 ufw\" class=\"wp-image-821\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/10-allow-a-udp-port.png 879w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/10-allow-a-udp-port-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/10-allow-a-udp-port-768x576.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw allow 111\/udp<\/code><\/pre>\n\n\n\n<p>You can also allow any deny udp ports as shown above. By default it will allow or deny on both tcp and udp unless you specify one of the two.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Allow and Deny Access to IP Addresses<\/h2>\n\n\n\n<p>Sometimes you may want to only allow certain IP addresses access to your system. In this case you can setup a rule to control access on a per IP basis. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Allow an IP<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"880\" height=\"663\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/allow-ip.jpg\" alt=\"allow an ip address\" class=\"wp-image-872\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/allow-ip.jpg 880w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/allow-ip-300x226.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/allow-ip-768x579.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<p>Using the above rule you are able to allow only specific IP addresses to access your system. This is the securest way to setup a FTP or SSH server that needs remote access. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Deny an IP<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"878\" height=\"661\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/deny-ip.jpg\" alt=\"deny an ip address\" class=\"wp-image-873\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/deny-ip.jpg 878w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/deny-ip-300x226.jpg 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/deny-ip-768x578.jpg 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<p>This rule is useful in situations where you are allowing all IP addresses through the firewall, but just want to block certain ones.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enable or Disable UFW Firewall Rules<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Enable UFW<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"878\" height=\"659\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/11-enable-the-firewall.png\" alt=\"enable ufw\" class=\"wp-image-822\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/11-enable-the-firewall.png 878w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/11-enable-the-firewall-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/11-enable-the-firewall-768x576.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw enable<\/code><\/pre>\n\n\n\n<p>Now you will need to enable the firewall to apply the rule set you created. To enable the UFW firewall type &#8220;sudo ufw enable&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Disable UFW<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"878\" height=\"660\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/12-disable-the-firewall.png\" alt=\"disable ufw\" class=\"wp-image-823\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/12-disable-the-firewall.png 878w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/12-disable-the-firewall-300x226.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/12-disable-the-firewall-768x577.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw disable<\/code><\/pre>\n\n\n\n<p>If you need to disable the firewall you can run the command &#8220;sudo ufw disable&#8221;. This will keep the firewall disabled until you enable it again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">View the Firewalls Status<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"878\" height=\"659\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/13-check-ufw-status.png\" alt=\"ufw view status\" class=\"wp-image-824\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/13-check-ufw-status.png 878w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/13-check-ufw-status-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/13-check-ufw-status-768x576.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw status<\/code><\/pre>\n\n\n\n<p>To view the status of the firewall type &#8220;sudo ufw status&#8221;. This will show you all of the ports and or programs that you are allowing or denying through the firewall. It will also show you whether UFW is active or inactive.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advanced UFW Rules<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"879\" height=\"659\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/14-edit-ufw-rules-files.png\" alt=\"ufw edit rules files\" class=\"wp-image-835\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/14-edit-ufw-rules-files.png 879w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/14-edit-ufw-rules-files-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/14-edit-ufw-rules-files-768x576.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>cd \/etc\/ufw\/<\/code><\/pre>\n\n\n\n<p>Most rules can be applied using the command line but sometimes you want more control over the rules. In this case you can directly edit the rules using the &#8220;before.rules&#8221; and &#8220;after.rules&#8221; files located in the &#8220;<code>\/etc\/ufw\/<\/code>&#8221; directory. The before rules are applied before UFW is launched while the after rules apply after UFW is running.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"879\" height=\"661\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/15-edit-ufw-config-file.png\" alt=\"ufw edit config file\" class=\"wp-image-836\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/15-edit-ufw-config-file.png 879w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/15-edit-ufw-config-file-300x226.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/15-edit-ufw-config-file-768x578.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>nano \/etc\/default\/ufw<\/code><\/pre>\n\n\n\n<p> You can also edit the UFW configuration file located at &#8220;<code>\/etc\/default\/ufw<\/code>&#8221; for more advanced configurations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enable Logging<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"879\" height=\"659\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/16-sudo-ufw-enable-logging.png\" alt=\"ufw enable logging\" class=\"wp-image-837\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/16-sudo-ufw-enable-logging.png 879w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/16-sudo-ufw-enable-logging-300x225.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/16-sudo-ufw-enable-logging-768x576.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>sudo ufw logging on<\/code><\/pre>\n\n\n\n<p>You can enable logging in UFW by running the command &#8220;sudo ufw logging on&#8221;. This will enable the logs in the lowest mode by default. If you want to specify the log level use the command &#8220;<code>sudo ufw logging low|medium|high<\/code>&#8220;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"875\" height=\"639\" loading=\"lazy\" src=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/17-ufw-log-file.png\" alt=\"view of ufw log\" class=\"wp-image-838\" srcset=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/17-ufw-log-file.png 875w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/17-ufw-log-file-300x219.png 300w, https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/17-ufw-log-file-768x561.png 768w\" sizes=\"auto, (max-width: 875px) 100vw, 875px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code has-vivid-cyan-blue-color has-black-background-color has-text-color has-background\"><code>nano \/var\/log\/ufw.log<\/code><\/pre>\n\n\n\n<p>The UFW log file will be located at &#8220;\/var\/log\/ufw.log&#8221; by default. I have set my logging level to low. Above is an example of what your log file may look like.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Additional Questions?<\/h2>\n\n\n\n<p>If you have any additional questions or thoughts feel free to comment them below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Resources<\/h2>\n\n\n\n<p>View our <strong><a href=\"https:\/\/formatswap.com\/blog\/os-installs\/how-to-install-kali-linux-2022-3-step-by-step\/\">How to install Kali Linux 2022.3 [step by step]<\/a><\/strong> tutorial.<\/p>\n\n\n\n<p>Learn <a href=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-use-the-alias-command-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><strong><a href=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-use-the-alias-command-in-linux\/\">How to Use the Alias Command in Linux<\/a><\/strong>.<\/p>\n\n\n\n<p>Check out our <strong><a href=\"https:\/\/formatswap.com\/blog\/windows-tutorials\/how-to-add-a-network-location-in-windows-10\/\">How to Add a Network Location in Windows 10<\/a><\/strong> tutorial.<\/p>\n\n\n\n<p>View our <a href=\"https:\/\/formatswap.com\/blog\/windows-tutorials\/how-to-setup-a-ftp-server-with-filezilla-in-windows\/\"><\/a><strong><a href=\"https:\/\/formatswap.com\/blog\/windows-tutorials\/how-to-setup-a-ftp-server-with-filezilla-in-windows\/\">How to Setup a FTP Server with FileZilla in Windows<\/a><\/strong> tutorial.<\/p>\n\n\n\n<p>Learn more cool things in Windows with our <a href=\"https:\/\/formatswap.com\/blog\/category\/linux-tutorials\/\" target=\"_blank\" rel=\"noreferrer noopener\">Windows Tutorials.<\/a><\/p>\n\n\n\n<p>View all of our available online utilities and converters at <a href=\"https:\/\/formatswap.com\" target=\"_blank\" rel=\"noreferrer noopener\">Formatswap.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will teach you how to install and configure UFW (Uncomplicated Firewall) in Linux. Firewalls are vital to keep your applications and systems secure. UFW provides a command line frontend interface for iptables using a few simple commands. It is designed to be easy to use and uncomplicated to configure. Using only Netfilter in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[4],"tags":[8,43,14],"class_list":["post-800","post","type-post","status-publish","format-standard","hentry","category-linux-tutorials","tag-linux","tag-security","tag-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Configure a Firewall in Linux using UFW - Format Swap - Tech Tutorials<\/title>\n<meta name=\"description\" content=\"In this tutorial, you\u2019ll learn how to configure a firewall using UFW (Uncomplicated Firewall) to secure an Ubuntu or Debian cloud server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Configure a Firewall in Linux using UFW - Format Swap - Tech Tutorials\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you\u2019ll learn how to configure a firewall using UFW (Uncomplicated Firewall) to secure an Ubuntu or Debian cloud server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/\" \/>\n<meta property=\"og:site_name\" content=\"Format Swap - Tech Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-07T21:46:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-10T14:01:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-1024x576.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#\\\/schema\\\/person\\\/3d01ee8e1e4f3718cfcc57eeb8ad6188\"},\"headline\":\"How to Configure a Firewall in Linux using UFW\",\"datePublished\":\"2023-01-07T21:46:44+00:00\",\"dateModified\":\"2023-07-10T14:01:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/\"},\"wordCount\":825,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/ufw-tux-firewall-1024x576.jpg\",\"keywords\":[\"linux\",\"security\",\"tutorial\"],\"articleSection\":[\"Linux Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/\",\"url\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/\",\"name\":\"How to Configure a Firewall in Linux using UFW - Format Swap - Tech Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/ufw-tux-firewall-1024x576.jpg\",\"datePublished\":\"2023-01-07T21:46:44+00:00\",\"dateModified\":\"2023-07-10T14:01:05+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#\\\/schema\\\/person\\\/3d01ee8e1e4f3718cfcc57eeb8ad6188\"},\"description\":\"In this tutorial, you\u2019ll learn how to configure a firewall using UFW (Uncomplicated Firewall) to secure an Ubuntu or Debian cloud server.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/#primaryimage\",\"url\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/ufw-tux-firewall.jpg\",\"contentUrl\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/01\\\/ufw-tux-firewall.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/linux-tutorials\\\/how-to-configure-a-firewall-in-linux-using-ufw\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Configure a Firewall in Linux using UFW\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/\",\"name\":\"Format Swap - Tech Tutorials\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/#\\\/schema\\\/person\\\/3d01ee8e1e4f3718cfcc57eeb8ad6188\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/formatswap.com\\\/blog\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCsIPLkRPTbbTaT8YX0Dh2-A\"],\"url\":\"https:\\\/\\\/formatswap.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Configure a Firewall in Linux using UFW - Format Swap - Tech Tutorials","description":"In this tutorial, you\u2019ll learn how to configure a firewall using UFW (Uncomplicated Firewall) to secure an Ubuntu or Debian cloud server.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure a Firewall in Linux using UFW - Format Swap - Tech Tutorials","og_description":"In this tutorial, you\u2019ll learn how to configure a firewall using UFW (Uncomplicated Firewall) to secure an Ubuntu or Debian cloud server.","og_url":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/","og_site_name":"Format Swap - Tech Tutorials","article_published_time":"2023-01-07T21:46:44+00:00","article_modified_time":"2023-07-10T14:01:05+00:00","og_image":[{"url":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-1024x576.jpg","type":"","width":"","height":""}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/#article","isPartOf":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/"},"author":{"name":"admin","@id":"https:\/\/formatswap.com\/blog\/#\/schema\/person\/3d01ee8e1e4f3718cfcc57eeb8ad6188"},"headline":"How to Configure a Firewall in Linux using UFW","datePublished":"2023-01-07T21:46:44+00:00","dateModified":"2023-07-10T14:01:05+00:00","mainEntityOfPage":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/"},"wordCount":825,"commentCount":0,"image":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/#primaryimage"},"thumbnailUrl":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-1024x576.jpg","keywords":["linux","security","tutorial"],"articleSection":["Linux Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/","url":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/","name":"How to Configure a Firewall in Linux using UFW - Format Swap - Tech Tutorials","isPartOf":{"@id":"https:\/\/formatswap.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/#primaryimage"},"image":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/#primaryimage"},"thumbnailUrl":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall-1024x576.jpg","datePublished":"2023-01-07T21:46:44+00:00","dateModified":"2023-07-10T14:01:05+00:00","author":{"@id":"https:\/\/formatswap.com\/blog\/#\/schema\/person\/3d01ee8e1e4f3718cfcc57eeb8ad6188"},"description":"In this tutorial, you\u2019ll learn how to configure a firewall using UFW (Uncomplicated Firewall) to secure an Ubuntu or Debian cloud server.","breadcrumb":{"@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/#primaryimage","url":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall.jpg","contentUrl":"https:\/\/formatswap.com\/blog\/wp-content\/uploads\/2023\/01\/ufw-tux-firewall.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/formatswap.com\/blog\/linux-tutorials\/how-to-configure-a-firewall-in-linux-using-ufw\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/formatswap.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Configure a Firewall in Linux using UFW"}]},{"@type":"WebSite","@id":"https:\/\/formatswap.com\/blog\/#website","url":"https:\/\/formatswap.com\/blog\/","name":"Format Swap - Tech Tutorials","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/formatswap.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/formatswap.com\/blog\/#\/schema\/person\/3d01ee8e1e4f3718cfcc57eeb8ad6188","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55cb3548d8c931eac3f2facbca246c6bde86082f48ca304906d7da2214191b72?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/formatswap.com\/blog","https:\/\/www.youtube.com\/channel\/UCsIPLkRPTbbTaT8YX0Dh2-A"],"url":"https:\/\/formatswap.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/posts\/800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/comments?post=800"}],"version-history":[{"count":5,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/posts\/800\/revisions"}],"predecessor-version":[{"id":1378,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/posts\/800\/revisions\/1378"}],"wp:attachment":[{"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/media?parent=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/categories?post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/formatswap.com\/blog\/wp-json\/wp\/v2\/tags?post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}