<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Iptables Archives - ServerStadium</title>
	<atom:link href="https://serverstadium.com/knowledge-base/tag/iptables/feed/" rel="self" type="application/rss+xml" />
	<link>https://serverstadium.com/knowledge-base/tag/iptables/</link>
	<description>Public Cloud Solution by ServerStadium</description>
	<lastBuildDate>Thu, 04 Jan 2024 06:17:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://serverstadium.com/wp-content/uploads/2023/04/cropped-favicon-1-32x32.png</url>
	<title>Iptables Archives - ServerStadium</title>
	<link>https://serverstadium.com/knowledge-base/tag/iptables/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How To List and Delete Iptables Firewall Rules</title>
		<link>https://serverstadium.com/knowledge-base/how-to-list-and-delete-iptables-firewall-rules/</link>
		
		<dc:creator><![CDATA[Brian K]]></dc:creator>
		<pubDate>Thu, 04 Jan 2024 06:17:22 +0000</pubDate>
				<guid isPermaLink="false">https://serverstadium.com/?post_type=epkb_post_type_1&#038;p=11836</guid>

					<description><![CDATA[<p>Introduction On Linux servers, including those provided by ServerStadium (VM Pricing, Dedicated Servers), iptables serves as a powerful tool for network traffic control. Listing and removing iptables rules helps in managing server access and protecting against unauthorized network traffic. Prerequisites A ServerStadium VM or dedicated server (VM Pricing, Dedicated Servers). Basic knowledge of Linux command&#8230;</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/how-to-list-and-delete-iptables-firewall-rules/">How To List and Delete Iptables Firewall Rules</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h3>Introduction</h3>
<p>On Linux servers, including those provided by ServerStadium (<a href="https://serverstadium.com/pricing/" target="_new" rel="noopener">VM Pricing</a>, <a href="https://serverstadium.com/dedicated-server/" target="_new" rel="noopener">Dedicated Servers</a>), iptables serves as a powerful tool for network traffic control. Listing and removing iptables rules helps in managing server access and protecting against unauthorized network traffic.</p>
<h3>Prerequisites</h3>
<ul>
<li>A ServerStadium VM or dedicated server (<a href="https://serverstadium.com/pricing/" target="_new" rel="noopener">VM Pricing</a>, <a href="https://serverstadium.com/dedicated-server/" target="_new" rel="noopener">Dedicated Servers</a>).</li>
<li>Basic knowledge of Linux command line and network security.</li>
</ul>
<h3>Listing Iptables Rules</h3>
<ol>
<li><strong>List All Iptables Rules</strong>:
<p>To view all current iptables rules:</p>
<div class="shortcode-code">
<p> sudo iptables -L -v </p></div>
<p>The <code>-L</code> option lists the rules, and <code>-v</code> provides verbose output.</li>
<li><strong>List Rules by Specific Chain</strong>:
<p>To list rules in a specific chain (e.g., INPUT, FORWARD, OUTPUT):</p>
<div class="shortcode-code">
<p> sudo iptables -L &#091;CHAIN-NAME&#093; -v </p></div>
<p>Replace <code>[CHAIN-NAME]</code> with the name of the chain.</li>
</ol>
<h3>Deleting Iptables Rules</h3>
<ol>
<li><strong>Delete by Rule Number</strong>:
<p>First, list the rules with line numbers:</p>
<div class="shortcode-code">
<p> sudo iptables -L &#8211;line-numbers </p></div>
<p>Then, delete a rule by its number in a specific chain:</p>
<div class="shortcode-code">
<p> sudo iptables -D &#091;CHAIN-NAME&#093; &#091;RULE-NUMBER&#093; </p></div>
<p>Replace <code>[CHAIN-NAME]</code> with the chain&#8217;s name and <code>[RULE-NUMBER]</code> with the rule&#8217;s line number.</li>
<li><strong>Delete by Rule Specification</strong>:
<p>Alternatively, delete a rule by specifying it:</p>
<div class="shortcode-code">
<p> sudo iptables -D &#091;CHAIN-NAME&#093; -p &#091;PROTOCOL&#093; &#8211;dport &#091;PORT&#093; -j &#091;TARGET&#093; </p></div>
<p>Replace the placeholders with the rule&#8217;s specifics. For example, <code>-p tcp --dport 22 -j ACCEPT</code> to delete a rule allowing SSH.</li>
</ol>
<h3>Saving Changes</h3>
<ol>
<li><strong>Save Iptables Changes</strong>:
<p>After modifying rules, save the changes to ensure they persist after a reboot:</p>
<div class="shortcode-code">
<p> sudo iptables-save | sudo tee /etc/iptables/rules.v4 </p></div>
<p>This command saves the current rules to the iptables configuration file.</li>
</ol>
<h3>Conclusion</h3>
<p>Effectively managing iptables rules is vital for the security and functionality of your ServerStadium Linux server. Listing and deleting rules as needed helps maintain optimal network settings and protect against threats. For further assistance, visit the <a href="https://serverstadium.com/knowledge-base/" target="_new" rel="noopener">ServerStadium knowledge base</a>.</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/how-to-list-and-delete-iptables-firewall-rules/">How To List and Delete Iptables Firewall Rules</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Securing CentOS with iptables</title>
		<link>https://serverstadium.com/knowledge-base/securing-centos-with-iptables/</link>
		
		<dc:creator><![CDATA[Brian K]]></dc:creator>
		<pubDate>Thu, 10 Dec 2020 08:44:01 +0000</pubDate>
				<guid isPermaLink="false">https://cloudraya.com/knowledge-base/?p=585</guid>

					<description><![CDATA[<p>Read this article to get a better understanding of how to secure your CentOS with iptables. The ServerStadium cloud instance control panel has its own security firewall which is based on ports (TCP, UDP, and ICMP), you can manage it through the customer panel or URL https://cp.ServerStadium.com/ However. In this article, we would give you&#8230;</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/securing-centos-with-iptables/">Securing CentOS with iptables</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Read this article to get a better understanding of how to secure your CentOS with iptables.</p>



<p class="wp-block-paragraph">The ServerStadium cloud instance control panel has its own security firewall which is based on ports (<strong>TCP</strong>, <strong>UDP,</strong> and <strong>ICMP</strong>), you can manage it through the customer panel or URL <a href="https://cp.ServerStadium.com/" target="_blank" rel="noreferrer noopener">https://cp.ServerStadium.com/</a></p>



<p class="wp-block-paragraph">However. In this article, we would give you the next layer for Hardening Server Security using iptables on the OS level, specifically CentOS. Securing Linux server is important to protect your data, intellectual property, from the hands of crackers (hackers) or even DDoS (<a href="https://en.wikipedia.org/wiki/Denial-of-service_attack" target="_blank" rel="noreferrer noopener">Denial-of-service</a> attack).</p>



<p class="wp-block-paragraph">This Linux based firewall is controlled by the program called iptables to handle filtering for IPv4.</p>



<h3 class="wp-block-heading"><strong>Prerequisites</strong></h3>



<p class="wp-block-paragraph">Before we begin the tutorial, the following are the software stack versions in this article:</p>



<ul class="wp-block-list">
<li>OS: Centos 7</li>
<li>IPTables: v1.4.21 (Installed already by default)</li>
<li>IPv4 network</li>
</ul>



<h3 class="has-vivid-cyan-blue-color has-text-color wp-block-heading">Manage IPTables Firewall rule</h3>



<p class="wp-block-paragraph">By default, IPTables is running and no rules, you can check it by executing the following command:</p>



<pre class="wp-block-preformatted">iptables -L -n</pre>



<p class="wp-block-paragraph">It will show you the following output:</p>



<pre class="wp-block-preformatted">[root@centos-iptables-cr-b4cdf33d ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination</pre>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="400" height="155" class="wp-image-587" src="https://serverstadium.com/wp-content/uploads/2020/10/image.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2020/10/image.png 400w, https://serverstadium.com/wp-content/uploads/2020/10/image-300x116.png 300w" sizes="(max-width: 400px) 100vw, 400px" /></figure>



<p class="wp-block-paragraph">The following are some iptables which based on rules can filter high degree of illegitimate access.</p>



<pre class="wp-block-preformatted"># Modify this file accordingly for your specific requirement.
# 1. Delete all existing rules
iptables -F

# 2. Set default chain policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

# 3. Block a specific ip-address
#BLOCK_THIS_IP="x.x.x.x"
iptables -A INPUT -s "$BLOCK_THIS_IP" -j DROP

# 4. Allow ALL incoming SSH
iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 5. Allow incoming SSH only from a sepcific network
iptables -A INPUT -i eth0 -p tcp -s 192.168.200.0/24 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 6. Allow incoming HTTP
iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
# Allow incoming HTTPS
iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT #iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT

# 7. MultiPorts (Allow incoming SSH, HTTP, and HTTPS)
iptables -A INPUT -i eth0 -p tcp -m multiport --dports 22,80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport --sports 22,80,443 -m state --state ESTABLISHED -j ACCEPT

# 8. Allow outgoing SSH
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 9. Allow outgoing SSH only to a specific network
iptables -A OUTPUT -o eth0 -p tcp -d 192.168.101.0/24 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT

# 10. Allow outgoing HTTPS
iptables -A OUTPUT -o eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT

# 12. Ping from inside to outside
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT

# 13. Ping from outside to inside
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT

# 14. Allow loopback access
iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT

# 15. Allow packets from internal network to reach external network.
# if eth1 is connected to external network (internet)
# if eth0 is connected to internal network (192.168.1.x)
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

# 16. Allow outbound DNS
#iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT
#iptables -A INPUT -p udp -i eth0 --sport 53 -j ACCEPT

# 18. Allow rsync from a specific network 
iptables -A INPUT -i eth0 -p tcp -s 192.168.101.0/24 --dport 873 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 873 -m state --state ESTABLISHED -j ACCEPT

# 19. Allow MySQL connection only from a specific network iptables -A INPUT -i eth0 -p tcp -s 192.168.200.0/24 --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT

# 20. Allow Sendmail or Postfix
iptables -A INPUT -i eth0 -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT

# 21. Allow IMAP and IMAPS
iptables -A INPUT -i eth0 -p tcp --dport 143 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 143 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 993 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 993 -m state --state ESTABLISHED -j ACCEPT

# 22. Allow POP3 and POP3S
iptables -A INPUT -i eth0 -p tcp --dport 110 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 110 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 995 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --sport 995 -m state --state ESTABLISHED -j ACCEPT

# 23. Prevent DoS attack
iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT

# 24. Port forwarding 80 to 8080
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

# 25. Log dropped packets
iptables -N LOGGING iptables -A INPUT -j LOGGING
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 7
iptables -A LOGGING -j DROP</pre>



<h3 class="has-vivid-cyan-blue-color has-text-color wp-block-heading">Manage IPTables Firewall rule (continue)</h3>



<p class="wp-block-paragraph">Furthermore, We can then add a few simple firewall rules to block the most common attacks, to protect our instance in <a href="https://ServerStadium.com/" target="_blank" rel="noreferrer noopener">ServerStadium</a> from script-kiddies. We can’t really count on iptables alone to protect our instances from a full-scale DDOS or similar, but we can at least put off the usual network scanning bots that will eventually find our instances and start looking for security holes to exploit.</p>



<p class="wp-block-paragraph"><strong>First of all, we start with blocking null packets.</strong></p>



<pre class="wp-block-preformatted">iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP</pre>



<figure class="wp-block-image size-large"><img decoding="async" width="665" height="24" class="wp-image-589" src="https://serverstadium.com/wp-content/uploads/2020/10/image-1.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2020/10/image-1.png 665w, https://serverstadium.com/wp-content/uploads/2020/10/image-1-300x11.png 300w" sizes="(max-width: 665px) 100vw, 665px" /></figure>



<p class="wp-block-paragraph">We told the firewall to take all incoming packets with TCP flags NONE and just DROP them all. Null packets are simply said recon packets. The attack patterns use these to try and see how we configured the Instances and find out weaknesses.</p>



<p class="wp-block-paragraph"><strong>Fragmented Packet:</strong></p>



<pre class="wp-block-preformatted">iptables -A INPUT -f -j DROP</pre>



<figure class="wp-block-image size-large"><img decoding="async" width="473" height="24" class="wp-image-590" src="https://serverstadium.com/wp-content/uploads/2020/10/image-2.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2020/10/image-2.png 473w, https://serverstadium.com/wp-content/uploads/2020/10/image-2-300x15.png 300w" sizes="(max-width: 473px) 100vw, 473px" /></figure>



<p class="wp-block-paragraph">All packets with incoming fragments drop them. This attack result in Linux server panic such data loss.</p>



<p class="wp-block-paragraph"><strong>Force SYN Packet Check:</strong></p>



<pre class="wp-block-preformatted">iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="697" height="20" class="wp-image-591" src="https://serverstadium.com/wp-content/uploads/2020/10/image-3.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2020/10/image-3.png 697w, https://serverstadium.com/wp-content/uploads/2020/10/image-3-300x9.png 300w" sizes="(max-width: 697px) 100vw, 697px" /></figure>



<p class="wp-block-paragraph">Ensure all NEW incoming TCP connections are SYN packets. Otherwise, we need to drop them, SYN-Flood-Attacks means that the attackers open a new connection, but does not state what they want (ie. SYN, ACK, whatever). They want to take up our servers’ resources. We won’t accept such packages.</p>



<p class="wp-block-paragraph"><strong>XMAS Packet:</strong></p>



<pre class="wp-block-preformatted">iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="647" height="22" class="wp-image-592" src="https://serverstadium.com/wp-content/uploads/2020/10/image-4.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2020/10/image-4.png 647w, https://serverstadium.com/wp-content/uploads/2020/10/image-4-300x10.png 300w" sizes="(max-width: 647px) 100vw, 647px" /></figure>



<p class="wp-block-paragraph">All incoming malformed XMAS packets should be dropped; XMAS packets is also a recon packet.</p>



<p class="wp-block-paragraph">The following are all rules above that we have added (<strong>blocking null packets</strong>, <strong>Fragmented Packet</strong>, <strong>Force SYN Packet Check</strong> and <strong>XMAS Packet</strong>).</p>



<pre class="wp-block-preformatted">[root@centos-iptables-cr-b4cdf33d ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:0x3F/0x00
DROP all -f 0.0.0.0/0 0.0.0.0/0
DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:!0x17/0x02 state NEW
DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:0x3F/0x3F
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination</pre>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="750" height="216" class="wp-image-593" src="https://serverstadium.com/wp-content/uploads/2020/10/image-5.png" alt="" srcset="https://serverstadium.com/wp-content/uploads/2020/10/image-5.png 750w, https://serverstadium.com/wp-content/uploads/2020/10/image-5-300x86.png 300w" sizes="(max-width: 750px) 100vw, 750px" /></figure>



<p class="wp-block-paragraph">We also recommend you install and use a sniffer such as tcpdump and ngrep to test your firewall settings.</p>



<h3 class="has-vivid-cyan-blue-color has-text-color wp-block-heading">Conclusion</h3>



<p class="wp-block-paragraph">This article only lists basic rules for new Linux users. You can create/custom and build more complex rules. This requires a good understanding of TCP/IP, Linux kernel tuning via sysctl.conf, and good knowledge of your own setup.</p>



<p class="wp-block-paragraph">Hope this helps and see you in the next article.</p>
<p>The post <a href="https://serverstadium.com/knowledge-base/securing-centos-with-iptables/">Securing CentOS with iptables</a> appeared first on <a href="https://serverstadium.com">ServerStadium</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
