<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Karthik</title>
    <description>The latest articles on DEV Community by Karthik (@karthiksedoc).</description>
    <link>https://dev.to/karthiksedoc</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F375907%2Fc56f6c2c-aa69-46d1-881e-aad8c5cfc0b4.jpeg</url>
      <title>DEV Community: Karthik</title>
      <link>https://dev.to/karthiksedoc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/karthiksedoc"/>
    <language>en</language>
    <item>
      <title>Iptables - High availability</title>
      <dc:creator>Karthik</dc:creator>
      <pubDate>Tue, 09 Jun 2020 14:04:56 +0000</pubDate>
      <link>https://dev.to/karthiksedoc/iptables-high-availability-20g6</link>
      <guid>https://dev.to/karthiksedoc/iptables-high-availability-20g6</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                             192.168.8.45(vrrp.ext.munnar.com)
                                         |
                                         |
              _________________________________________________________
             |                                                         |
             |                                                         |
192.168.8.133(ext.ipt1.munnar.com)                         192.16.8.132(ext.ipt2.munnar.com)

..................................                         .................................
|192.168.57.3(ha.ipt1.munnar.com)|&amp;lt;&amp;lt;&amp;lt;------&amp;lt;&amp;lt;---&amp;gt;&amp;gt;------&amp;gt;&amp;gt;&amp;gt;|192.168.57.4(ha.ipt2.munnar.com)|
..................................                         .................................



192.168.56.103(internal.ipt1.munnar.com)                   192.168.56.102(internal.ipt2.munnar.com)
             |                                                         |
             |                                                         |
              _________________________________________________________
                                        |
                                        |
                           192.168.56.100(vrrp.internal.munnar.com)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Scenario&lt;/strong&gt; HA Firewall placed between internal and external network as you can assume it's multi homed. And controls access from external network to services hosted in internal networks.&lt;br&gt;&lt;br&gt;
       We have dedicated VRRP placed on both networks, systems in external network have to set the external VRRP(vrrp.ext.munnar.com) as default gateway or have to use static route for destined internal network via external VRRP. &lt;br&gt;
             The same needs to be done from internal network as well for return traffic(in our scenario), systems in internal network needs to use either vrrp.internal.munnar.com as default gateway or need to use static route for external destination via vrrp.internal.munnar.com.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Network Configuration&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Primary&lt;/th&gt;
&lt;th&gt;Secondary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;host1:ipt1.munnar.com(Primary)&lt;/td&gt;
&lt;td&gt;host2:ipt2.munnar.com(Secondary)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ha.ipt1.munnar.com&lt;/td&gt;
&lt;td&gt;ha.ipt2.munnar.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ext.ipt1.munnar.com&lt;/td&gt;
&lt;td&gt;ext.ipt2.munnar.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;vrrp.ext.munnar.com&lt;/td&gt;
&lt;td&gt;vrrp.ext.munnar.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;int.ipt1.munnar.com&lt;/td&gt;
&lt;td&gt;int.ipt2.munnar.com&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;vrrp.internal.munnar.com&lt;/td&gt;
&lt;td&gt;vrrp.internal.munnar.com&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Packages Required&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;keepalived - for VRRP&lt;br&gt;
contrack-tools - Firewall session synchronization between firewalls&lt;br&gt;
iptables-services - iptables startup package&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation Steps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yum install iptables-services keepalived conntrack-tools -y&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  VRRP configuration
&lt;/h4&gt;

&lt;p&gt;As depicted in the top layout, we are using two vrrp's one for external and another one for internal. The host ipt1.munnar.com acts as MASTER and ipt2.munnar.com is Backup.  &lt;/p&gt;

&lt;h6&gt;
  
  
  Master Keepalived
&lt;/h6&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JKzRI3PE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pnuzl6pe4g9lozkk3hm9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JKzRI3PE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pnuzl6pe4g9lozkk3hm9.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Backup Keepalived
&lt;/h6&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4e-5VvFV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s1qsmmcikt86m20r7st0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4e-5VvFV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s1qsmmcikt86m20r7st0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Conntrackd Configuration
&lt;/h4&gt;

&lt;p&gt;Conntrackd is used to synchronize the existing firewall sessions thereby maintains ongoing connections during failover.&lt;br&gt;
       ha.ipt1.munnar.com and ha.ipt2.munnar.com are the dedicated interfaces used to sync the sessions. We need to copy two key files of conntrackd for configuration, copy /usr/share/doc/conntrack-tools-1.4.4/doc/sync/ftfw/conntrackd.conf as /etc/conntrackd/conntrackd.conf &lt;code&gt;cp /usr/share/doc/conntrack-tools-1.4.4/doc/sync/ftfw/conntrackd.conf /etc/conntrackd/conntrackd.conf&lt;/code&gt;and copy /usr/share/doc/conntrack-tools-1.4.4/doc/sync/primary-backup.sh to /etc/conntrackd/ &lt;code&gt;/usr/share/doc/conntrack-tools-1.4.4/doc/sync/primary-backup.sh /etc/conntrackd/&lt;/code&gt; and set executable bit.&lt;br&gt;
            Following screen-shots shows the minimal configuration required to use conntrackd.&lt;/p&gt;

&lt;h6&gt;
  
  
  ipt1 conntrackd
&lt;/h6&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--melHWBa0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p8hr3o9w5dlbbrzocr04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--melHWBa0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p8hr3o9w5dlbbrzocr04.png" alt="ipt1 conntrackd"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  ipt2 conntrackd
&lt;/h6&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_pxkosLl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m8budsf3s4ejtfhes1kf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_pxkosLl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m8budsf3s4ejtfhes1kf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: Conntrackd content is stripped to accommodate the content &lt;/p&gt;

&lt;p&gt;Further we need to enable packet forwarding on both of our firewalls &lt;code&gt;sysctl -w net.ipv4.ip_forward=1&lt;/code&gt;,make sure to set this in /etc/sysctl.conf to make persistent across reboots. And iptables need to have access rule configured in forward chain of Filter table in order to pass the traffic between source and destination. &lt;br&gt;
             In my case I have a webserver running in internal network(192.168.56.107) and a client machine running in external network, hence I have added the following rules for accessing http from client machine.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;/code&gt;&lt;br&gt;
&lt;code&gt;iptables -A FORWARD -d 192.168.56.107/32 -p tcp -m tcp --dport 80 -j ACCEPT&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;All configuration can be found in &lt;a href="https://github.com/karthiksedoc/HA-iptables"&gt;github&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
