{"id":1055,"date":"2019-04-11T22:10:00","date_gmt":"2019-04-11T21:10:00","guid":{"rendered":"https:\/\/www.balajibandi.com\/?p=1055"},"modified":"2020-07-11T18:33:34","modified_gmt":"2020-07-11T17:33:34","slug":"linux-firewall-ufw-made-simple","status":"publish","type":"post","link":"https:\/\/www.balajibandi.com\/?p=1055","title":{"rendered":"Linux Firewall UFW &#8211; Made simple"},"content":{"rendered":"\n<p>I want to run web Server Locally and safeguard my webserver decided to use UFW ( old school it was iptables &#8211; behind UFW).<\/p>\n\n\n\n<p><strong>What is UFW ?<\/strong><\/p>\n\n\n\n<p>UFW (Uncomplicated Firewall)\u00a0 &#8211; it is available from Ubunut 15.X<\/p>\n\n\n\n<p><strong>Install UFW simple on Linux<\/strong><\/p>\n\n\n\n<p>I am using ubuntu most famous distro and most people use easy ( copy of debian).<\/p>\n\n\n\n<p>#<strong>apt-get install ufw<\/strong><\/p>\n\n\n\n<p>by dfault it was disabled as service &#8211; enable service.<\/p>\n\n\n\n<p><strong>#ufw enable<\/strong><\/p>\n\n\n\n<p>Command may disrupt existing ssh connections. Proceed with operation (y|n)? <strong>y<\/strong><br>Firewall is active and enabled on system startup<\/p>\n\n\n\n<p>Checking the Service running or not by issuing below command :<\/p>\n\n\n\n<p><strong>#ufw status verbose<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"519\" height=\"253\" src=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2020\/07\/image.png\" alt=\"\" class=\"wp-image-1056\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2020\/07\/image.png 519w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2020\/07\/image-300x146.png 300w\" sizes=\"auto, (max-width: 519px) 100vw, 519px\" \/><\/figure>\n\n\n\n<p><strong>UFW Deny Command<\/strong><\/p>\n\n\n\n<p>The &#8220;deny&#8221; command works similar to the &#8220;allow&#8221; command and is used to close a port in the firewall:<\/p>\n\n\n\n<p>Deny with Port option:<\/p>\n\n\n\n<p><strong>#ufw deny 80<\/strong><\/p>\n\n\n\n<p>Allow a Port Range<\/p>\n\n\n\n<p>You can allow a range of ports in UFW. Some services like FTP or IRC use a range of ports to communicate with its clients.<\/p>\n\n\n\n<p>For this example we will allow the port range that used range is port 3000 to 7000.<\/p>\n\n\n\n<p><strong>#ufw allow 3000:7000\/tcp<br>#ufw allow 3000:7000\/udp<\/strong><\/p>\n\n\n\n<p><br>The command will allow connections to ports 3000-7000 via TCP and UDP protocol.<\/p>\n\n\n\n<p><strong>Allow a specific IP Address<\/strong><\/p>\n\n\n\n<p>And you can add a specific IP to allow access to all services by adding the &#8220;from&#8221; option. <\/p>\n\n\n\n<p><strong>#ufw allow from 192.168.1.81<\/strong><\/p>\n\n\n\n<p><strong>Allow Subnet<\/strong><\/p>\n\n\n\n<p>If you want to allow all IP addresses on your subnet, you can add the IP subnet (range of IP addresses) to the UFW command like this:<\/p>\n\n\n\n<p><strong>#ufw allow from 192.168.1.0\/24<\/strong><\/p>\n\n\n\n<p>If you have a complex rule then there is a simple way to identify and delete the rule by its rule ID. Run the following command to get a list of all rules with their ID&#8217;s:<\/p>\n\n\n\n<p><strong>#ufw status numbered<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"469\" height=\"174\" src=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2020\/07\/image-1.png\" alt=\"\" class=\"wp-image-1057\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2020\/07\/image-1.png 469w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2020\/07\/image-1-300x111.png 300w\" sizes=\"auto, (max-width: 469px) 100vw, 469px\" \/><figcaption><br><\/figcaption><\/figure>\n\n\n\n<p>Now delete the SSH rule for IPv6 only by using the number of the rule:<\/p>\n\n\n\n<p>#<strong>ufw delete 1<\/strong><\/p>\n\n\n\n<p>Note : make you list again befre deleting another rule, since numbers are changed after deleting<\/p>\n\n\n\n<p><strong>Disable and Reset UFW<\/strong><\/p>\n\n\n\n<p><strong>#ufw disable<\/strong><\/p>\n\n\n\n<p>Firewall stopped and disabled on system startup<br>The UFW status command.<\/p>\n\n\n\n<p>If you want to turn off UFW completely and delete all the rules, you can use &#8220;reset&#8221; command:<\/p>\n\n\n\n<p><strong>#ufw reset<\/strong>  &#8211; make you understand this before executing, this will remove all rules<br><\/p>\n\n\n\n<p>happy Labbbbbbbbbbbbbing&#8230;!!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to run web Server Locally and safeguard my webserver decided to use UFW ( old school it was iptables &#8211; behind UFW). What is UFW ? UFW (Uncomplicated Firewall)\u00a0 &#8211; it is available from Ubunut 15.X Install UFW simple on Linux I am using ubuntu most famous distro and most people use easy [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1055","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/1055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1055"}],"version-history":[{"count":1,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/1055\/revisions"}],"predecessor-version":[{"id":1058,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/1055\/revisions\/1058"}],"wp:attachment":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}