{"id":197,"date":"2021-07-08T04:31:02","date_gmt":"2021-07-08T04:31:02","guid":{"rendered":"https:\/\/tiruppurwebhosting.com\/blog\/?p=197"},"modified":"2021-07-08T04:31:59","modified_gmt":"2021-07-08T04:31:59","slug":"how-to-setup-the-firewall-on-dedicated-linux-server","status":"publish","type":"post","link":"https:\/\/tiruppurwebhosting.com\/blog\/how-to-setup-the-firewall-on-dedicated-linux-server\/","title":{"rendered":"How to setup the Firewall on Dedicated Linux Server"},"content":{"rendered":"<h1 class=\"entry-title\">Basic Firewall Setup on Dedicated Linux Server<\/h1>\n<p>A firewall will stop any unusual activities on one network from being passed on to another network. In most systems the Linux kernel is compiled with IP forwarding set to yes. This means is that if the computer has more than one network connected to it then network information will be passed directly from one network to the other as if it was physically connected.<\/p>\n<p>Forgetting to secure and configure a dedicated server firewall is a common mistake and a huge security flaw. Going into the firewall\u2019s configuration allows you to remove unnecessary software that\u2019s connected to the internet. This makes your server and its ports vulnerable to intrusion.<\/p>\n<p>Now, we can see how to setup basic firewall on<a href=\"https:\/\/www.squarebrothers.com\/dedicated-server-in-india\/\" target=\"_blank\" rel=\"noopener\"> dedicated linux server.<\/a><\/p>\n<h2>Installing Firewall on Linux<\/h2>\n<p><strong>On Ubuntu\/Debian:<\/strong><\/p>\n<pre class=\"code-pre\">$ sudo apt-get install iptables<\/pre>\n<p><strong>On CentOS 7\/RHEL 7:<\/strong><\/p>\n<pre># yum install iptables-services<\/pre>\n<h2>Let\u2019s decide which Firewall Ports to Block<\/h2>\n<p>The first step in firewall installation is deciding which ports has to be left open on our dedicated server. This will vary based on what you are using the dedicated host for, if you are running a web server, you would likely want the following ports open:<\/p>\n<ul>\n<li>Web: 80 and 443<\/li>\n<li>SSH: Typically run on port 22<\/li>\n<li>Email: 110 (POP3), 143 (IMAP), 993 (IMAP SSL), 995 (POP3 SSL).<\/li>\n<\/ul>\n<p>Change your SSH port to a non-default port by reading our article on\u00a0changing your servers SSH port. Want your users to only use email over SSL? Block standard POP3 and IMAP ports in your firewall to force SSL use.<\/p>\n<h4>Flush Default Firewall Rules<\/h4>\n<p>Run the below command to flush to default firewall rules.<\/p>\n<pre class=\"code-pre\"># iptables -F\r\n<\/pre>\n<h4>Block Common Server Attack Routes<\/h4>\n<p>We have to run some standard commands here to block common attacks.<\/p>\n<p><strong>Block syn-flood packets:<\/strong><\/p>\n<pre class=\"code-pre\"># iptables -A INPUT -p tcp ! \u2013syn -m state \u2013state NEW -j DROP<\/pre>\n<p><strong>Block XMAS Packets:<\/strong><\/p>\n<pre class=\"code-pre\"># iptables -A INPUT -p tcp \u2013tcp-flags ALL ALL -j DROP\r\n<\/pre>\n<p><strong>Block null packets:<\/strong><\/p>\n<pre class=\"code-pre\"># iptables -A INPUT -p tcp \u2013tcp-flags ALL NONE -j DROP\r\n<\/pre>\n<h4>Opening Required Ports<\/h4>\n<p>Run the below command to open up the ports you need. Here are some examples for you to work,<br \/>\n<strong>Allow SSH Access:<\/strong><\/p>\n<pre class=\"code-pre\"># iptables -A INPUT -p tcp -m tcp \u2013dport 22 -j ACCEPT\r\n<\/pre>\n<p><strong>Open up LOCALHOST access:<\/strong><\/p>\n<pre class=\"code-pre\"># iptables -A INPUT -i lo -j ACCEPT\r\n<\/pre>\n<p><strong>Allow web traffic:<\/strong><\/p>\n<pre class=\"code-pre\"># iptables -A INPUT -p tcp -m tcp \u2013dport 80 -j ACCEPT<\/pre>\n<pre class=\"code-pre\"># iptables -A INPUT -p tcp -m tcp \u2013dport 443 -j ACCEPT\r\n<\/pre>\n<h4>Test Firewall Configuration<\/h4>\n<p>Run the following command to save the configuration and restart your firewall:<\/p>\n<pre class=\"code-pre\"># iptables -L -n<\/pre>\n<pre class=\"code-pre\"># iptables-save | sudo tee \/etc\/sysconfig\/iptables<\/pre>\n<pre class=\"code-pre\"># service iptables restart<\/pre>\n<p>The above steps will definitely provide you the setup of Firewall in your server.For more information related to IP address or how to block particular IP address click here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Basic Firewall Setup on Dedicated Linux Server A firewall will stop any unusual activities on one network from being passed on to another network. In most systems the Linux kernel is compiled with IP forwarding set to yes. This means is that if the computer has more than one network connected to it then network<\/p>\n","protected":false},"author":1,"featured_media":199,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,92,1,9,3],"tags":[107,108,109],"class_list":["post-197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-basics","category-general","category-home","category-linux","category-linux-tutorials","tag-firewalld","tag-ip-tables","tag-ssh-port"],"_links":{"self":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=197"}],"version-history":[{"count":0,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/197\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/media\/199"}],"wp:attachment":[{"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tiruppurwebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}