
{"id":83,"date":"2025-06-07T08:58:07","date_gmt":"2025-06-07T07:58:07","guid":{"rendered":"https:\/\/blog.mkcloudai.com\/?p=83"},"modified":"2025-06-07T08:58:07","modified_gmt":"2025-06-07T07:58:07","slug":"secure-your-linux-server-auto-audit-fix-ufw-firewall-rules","status":"publish","type":"post","link":"https:\/\/blog.mkcloudai.com\/?p=83","title":{"rendered":"Secure Your Linux Server: Auto-Audit &amp; Fix UFW Firewall Rules"},"content":{"rendered":"\n<p>Ideal for developers, sysadmins, or anyone managing Linux servers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\ude80 Introduction<\/h3>\n\n\n\n<p>Securing your Linux server is critical, especially when it\u2019s exposed to the internet. One of the easiest and most effective tools to manage your server firewall is <strong>UFW (Uncomplicated Firewall)<\/strong>.<\/p>\n\n\n\n<p>In this guide, I\u2019ll walk you through an interactive script I built that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Checks if UFW is installed and running<\/li>\n\n\n\n<li>Installs and enables it if needed<\/li>\n\n\n\n<li>Scans your firewall rules<\/li>\n\n\n\n<li>Identifies misconfigurations<\/li>\n\n\n\n<li>Suggests secure alternatives<\/li>\n\n\n\n<li>Optionally applies fixes (with care!)<\/li>\n<\/ul>\n\n\n\n<p>Perfect for system admins, freelancers, or anyone running a VPS (e.g., AWS Lightsail, EC2, DigitalOcean, etc.).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd27 Features of the Script<\/h3>\n\n\n\n<p>\u2705 Checks UFW status and installation<br>\u2705 Suggests rules based on common security guidelines<br>\u2705 Detects and warns about open dangerous ports (e.g., 22, 80 open to world)<br>\u2705 Recommends changing default SSH port<br>\u2705 Offers auto-fix with user confirmation<br>\u2705 Supports IPv4 and IPv6 scanning<br>\u2705 Logs findings for audit\/compliance<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udee1\ufe0f Example Recommendations:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Change SSH Port: <code>sudo nano \/etc\/ssh\/sshd_config <\/code><\/li>\n\n\n\n<li><code># Change Port 22 to 2222 <\/code><\/li>\n\n\n\n<li><code>sudo systemctl restart ssh <\/code><\/li>\n\n\n\n<li><code>sudo ufw allow 2222\/tcp <\/code><\/li>\n\n\n\n<li><code>sudo ufw delete allow 22\/tcp<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Try It!<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>git clone <\/code>https:\/\/github.com\/mxkdevops\/UFW-audit<code>.git<br>cd ufw-audit-fixer<br>chmod +x ufw_audit.sh<br>sudo .\/ufw_audit.sh<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd1a Conclusion<\/h3>\n\n\n\n<p>This tool helps Linux admins detect firewall vulnerabilities quickly, with easy-to-understand advice and the option to fix issues securely. It\u2019s ideal for compliance audits, pentest prep, or day-to-day hardening.<\/p>\n\n\n\n<p>Stay safe \u2014 automate wisely!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ideal for developers, sysadmins, or anyone managing Linux servers. \ud83d\ude80 Introduction Securing your Linux server is critical, especially when it\u2019s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8,4,7,22],"tags":[36,35,17,34,33],"class_list":["post-83","post","type-post","status-publish","format-standard","hentry","category-how-to","category-linux","category-project","category-linux-secuirty","tag-aws-lightsail-2","tag-firewall","tag-linux","tag-port","tag-security"],"_links":{"self":[{"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83"}],"version-history":[{"count":1,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":84,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions\/84"}],"wp:attachment":[{"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mkcloudai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}