{"id":751,"date":"2024-03-11T12:00:17","date_gmt":"2024-03-11T12:00:17","guid":{"rendered":"https:\/\/linuxresellerwebhosting.in\/blog\/?p=751"},"modified":"2024-03-30T12:27:40","modified_gmt":"2024-03-30T12:27:40","slug":"ufw-commands-for-firewall-access","status":"publish","type":"post","link":"https:\/\/linuxresellerwebhosting.in\/blog\/ufw-commands-for-firewall-access\/","title":{"rendered":"ufw commands for Firewall access"},"content":{"rendered":"<p>ufw commands: &#8211;<\/p>\n<p>Ubuntu, like most <a href=\"https:\/\/www.squarebrothers.com\/linux-vps-hosting-india\/\" target=\"_blank\" rel=\"noopener\">Linux<\/a> distributions, comes with a built-in firewall called <code>iptables<\/code> or <code>ufw<\/code><\/p>\n<p data-gtm-vis-recent-on-screen1014405_503=\"262\" data-gtm-vis-first-on-screen1014405_503=\"262\" data-gtm-vis-total-visible-time1014405_503=\"100\" data-gtm-vis-has-fired1014405_503=\"1\">The Linux kernel includes the <em>Netfilter<\/em> subsystem, which is used to manipulate or decide the fate of network traffic headed into or through your server. All modern Linux firewall solutions use this system for packet filtering.<\/p>\n<p data-gtm-vis-has-fired1014405_503=\"1\">The kernel\u2019s packet filtering system would be of little use to administrators without a userspace interface to manage it. This is the purpose of iptables: When a packet reaches your server, it will be handed off to the Netfilter subsystem for acceptance, manipulation, or rejection based on the rules supplied to it from userspace via iptables. Thus, iptables is all you need to manage your firewall, if you\u2019re familiar with it, but many frontends are available to simplify the task.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"ufw_commands_-_ufw_%E2%80%93_Uncomplicated_Firewall\"><\/span>ufw commands:- ufw &#8211; Uncomplicated Firewall<span class=\"ez-toc-section-end\"><\/span><\/h2><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/ufw-commands-for-firewall-access\/#ufw_commands_-_ufw_%E2%80%93_Uncomplicated_Firewall\" >ufw commands:- ufw &#8211; Uncomplicated Firewall<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/ufw-commands-for-firewall-access\/#Testing_Open_Ports\" >Testing Open Ports<\/a><\/li><\/ul><\/nav><\/div>\n\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-758\" src=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/03\/UFW-Firewall-300x225.jpeg\" alt=\"\" width=\"324\" height=\"243\" srcset=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/03\/UFW-Firewall-300x225.jpeg 300w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/03\/UFW-Firewall.jpeg 320w\" sizes=\"auto, (max-width: 324px) 100vw, 324px\" \/><\/p>\n<p data-gtm-vis-has-fired1014405_503=\"1\">The default firewall configuration tool for Ubuntu is ufw. Developed to ease iptables firewall configuration, ufw provides a user-friendly way to create an IPv4 or IPv6 host-based firewall.<\/p>\n<p data-gtm-vis-has-fired1014405_503=\"1\">ufw by default is initially disabled. From the ufw man page:<\/p>\n<p data-gtm-vis-has-fired1014405_503=\"1\">\u201cufw is not intended to provide complete firewall functionality via its command interface, but instead provides an easy way to add or remove simple rules. It is currently mainly used for host-based firewalls.\u201d<\/p>\n<p data-gtm-vis-has-fired1014405_503=\"1\">Below is some examples for ubuntu commands and how to use ufw<\/p>\n<p data-gtm-vis-has-fired1014405_503=\"1\">First ufw needs to be enabled, From a terminal or SSH enter<\/p>\n<pre>sudo ufw enable<\/pre>\n<p>To open a port (SSH in this example):<\/p>\n<pre>sudo ufw allow 22<\/pre>\n<p>Rules can also be added using a numbered format:<\/p>\n<pre>sudo ufw insert 1 allow 80<\/pre>\n<p>Similarly, to close an opened port:<\/p>\n<pre>sudo ufw deny 22<\/pre>\n<p>To remove a rule, use delete followed by the rule:<\/p>\n<pre>sudo ufw delete deny 22<\/pre>\n<p>It is also possible to allow access from specific hosts or networks to a port. The following example allows SSH access from host 192.168.0.2 to any IP address on this host:<\/p>\n<pre>sudo ufw allow proto tcp from 192.146.0.1 to any port 22<\/pre>\n<p>Replace 192.146.0.1 with 192.146.0.0\/24 to allow SSH access from the entire subnet.<\/p>\n<p>Adding the \u2013dry-run option to a ufw command will output the resulting rules, but not apply them. For example, the following is what would be applied if opening the HTTP port:<\/p>\n<pre>sudo ufw --dry-run allow http<\/pre>\n<pre>*filter\r\n:ufw-user-input - [0:0]\r\n:ufw-user-output - [0:0]\r\n:ufw-user-forward - [0:0]\r\n:ufw-user-limit - [0:0]\r\n:ufw-user-limit-accept - [0:0]\r\n### RULES ###\r\n\r\n### tuple ### allow tcp 80 0.0.0.0\/0 any 0.0.0.0\/0\r\n-A ufw-user-input -p tcp --dport 80 -j ACCEPT\r\n\r\n### END RULES ###\r\n-A ufw-user-input -j RETURN\r\n-A ufw-user-output -j RETURN\r\n-A ufw-user-forward -j RETURN\r\n-A ufw-user-limit -m limit --limit 3\/minute -j LOG --log-prefix \"[UFW LIMIT]: \"\r\n-A ufw-user-limit -j REJECT\r\n-A ufw-user-limit-accept -j ACCEPT\r\nCOMMIT\r\nRules updated<\/pre>\n<p>ufw can be disabled by:<\/p>\n<pre>sudo ufw disable<\/pre>\n<p>To see the firewall status, enter:<\/p>\n<pre>sudo ufw status<\/pre>\n<p>And for more verbose status information use:<\/p>\n<pre>sudo ufw status verbose<\/pre>\n<p>To view the numbered format:<\/p>\n<pre>sudo ufw status numbered<\/pre>\n<p>Note<\/p>\n<p>If the port you want to open or close is defined in \/etc\/services, you can use the port name instead of the number. In the above examples, replace 22 with ssh.<\/p>\n<p>This is a quick introduction to using ufw. Please refer to the ufw man page for more information.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-759\" src=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/03\/1_WrqqZXugisLg5Xd9kq6Pnw-300x161.png\" alt=\"\" width=\"395\" height=\"212\" srcset=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/03\/1_WrqqZXugisLg5Xd9kq6Pnw-300x161.png 300w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/03\/1_WrqqZXugisLg5Xd9kq6Pnw.png 596w\" sizes=\"auto, (max-width: 395px) 100vw, 395px\" \/><\/p>\n<h2 id=\"ftoc-heading-8\" class=\"wp-block-heading ftwp-heading\"><span class=\"ez-toc-section\" id=\"Testing_Open_Ports\"><\/span>Testing Open Ports<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>After using any of the methods above to open a port in Linux, ensure that the process is successful. The following methods are simple ways to check the open ports on a system.<\/p>\n<p>View the listening ports with the <strong><code>netstat<\/code><\/strong> command:<\/p>\n<p class=\"wp-block-code copy-the-code-target\">netstat -lntu<\/p>\n<p>The above article will help you to know the basic commands to access firewall in ubuntu.<\/p>\n<p>In order to Disabling direct SSH Root Login and Permitting through \u201csu\u201d user in Linux <a href=\"https:\/\/linuxresellerwebhosting.in\/blog\/disabling-direct-ssh-root-login\/\">click here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ufw commands: &#8211; Ubuntu, like most Linux distributions, comes with a built-in firewall called iptables or ufw The Linux kernel<\/p>\n","protected":false},"author":2,"featured_media":757,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[1],"tags":[43],"class_list":["post-751","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-security"],"_links":{"self":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=751"}],"version-history":[{"count":6,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/751\/revisions"}],"predecessor-version":[{"id":760,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/751\/revisions\/760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/media\/757"}],"wp:attachment":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}