<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Deelaka Perera on Medium]]></title>
        <description><![CDATA[Stories by Deelaka Perera on Medium]]></description>
        <link>https://medium.com/@deelaka.perera?source=rss-5ecbc36792dd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YJI87UqOhhQBFE20E_ayBQ.png</url>
            <title>Stories by Deelaka Perera on Medium</title>
            <link>https://medium.com/@deelaka.perera?source=rss-5ecbc36792dd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:02:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deelaka.perera/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Configuring DNS Server on CentOS 7]]></title>
            <link>https://medium.com/@deelaka.perera/configuring-dns-server-on-centos-7-6ebc2db5a141?source=rss-5ecbc36792dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ebc2db5a141</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Deelaka Perera]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 05:35:28 GMT</pubDate>
            <atom:updated>2022-07-19T05:35:28.901Z</atom:updated>
            <content:encoded><![CDATA[<h4>Domain Name System translates user’s web address (<em>eg. google.com</em>) into IP address which web browsers use.</h4><p>Lets create a simple authoritative DNS server in CentOS 7 according to following simple scenario. A company has <strong>web server</strong>(<em>10.0.1.4</em>) which uses www.localdns.com, a <strong>doc server</strong>(<em>10.0.1.5</em>) which uses doc.localdns.com and <strong>mail server</strong> (<em>10.0.1.6</em>) uses mail.localdns.com. <strong>DNS server(<em>10.0.1.2</em>)</strong> should be configured to have DNS records for each server. All servers should have static IP addresses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*ZnE8z-PDajthEWNbvzKOwA.png" /><figcaption>Example architecture</figcaption></figure><p>Rest of the article flows as follows</p><ol><li>Main configuration</li><li>Forward zone configuration</li><li>Reverse zone configuration</li><li>Client machine configuration</li><li>Verifications</li></ol><p><strong>Required tools</strong>:- CentOS provides package bind as DNS software. bind-utils packages has tools such as nslookup, dig etc. First login to CentOS and install these packages.</p><p># yum install bind bind-utils</p><h4>1. Main Configuration</h4><p>Edit bind main configuration file.</p><p># vi /etc/named.conf</p><p>listen-on port 53 { 127.0.0.1;<strong>10.0.1.1/24;</strong> }; This is the configuration for which ipv4 address server is listening. Add DNS server’s static IP <strong>10.0.1.1/24;</strong> or any; to any available IP address which enables clients to connect.</p><p>directory “/var/named”; This specifies the directory to check zone files.</p><p>allow-query { localhost;<strong>10.0.1.0/24;</strong>}; This option specifies for which clients bind will answer. Can define ACL group, network group or any as options.</p><p>Next specify forwarding and reverse zone files.</p><pre>zone &quot;localdns.com&quot; IN {<br>        type master;<br>        file &quot;localdns.forward.zone&quot;;<br>        allow-update { none; };<br>        allow-query { 10.0.1.0/24; };<br>};</pre><p>Here zone name is localdns.com and forwarding file name is localdns.forward.zone</p><p>Next specify reverse zone file details.</p><pre>zone &quot;1.0.10.in-addr.arpa&quot; IN {<br>        type master;<br>        file &quot;localdns.reverse.zone&quot;;<br>        allow-update { none; };<br>        allow-query { 10.0.1.0/24; };<br>};</pre><p>Here zone name is 1.0.10.in-addr.arpa it is generated by writing DNS server network address(10.0.1.0) backwards (1.0.10.) and with .in-addr.arpa suffix. Zone file is localdns.reverse.zone</p><pre>//<br>// named.conf<br>//<br>// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS<br>..</pre><pre>..</pre><pre>// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html</pre><pre>options {<br>        <strong>listen-on port 53 { 127.0.0.1;10.0.1.2/24; };</strong><br>        listen-on-v6 port 53 { ::1; };<br>        directory       &quot;/var/named&quot;;<br>        dump-file       &quot;/var/named/data/cache_dump.db&quot;;<br>        statistics-file &quot;/var/named/data/named_stats.txt&quot;;<br>        memstatistics-file &quot;/var/named/data/named_mem_stats.txt&quot;;<br>        recursing-file  &quot;/var/named/data/named.recursing&quot;;<br>        secroots-file   &quot;/var/named/data/named.secroots&quot;;<br>        <strong>allow-query     { localhost;10.0.1.0/24;};</strong></pre><pre>        recursion yes;<br>        dnssec-enable yes;<br>        dnssec-validation yes;</pre><pre>        /* Path to ISC DLV key */<br>        bindkeys-file &quot;/etc/named.root.key&quot;;</pre><pre>        managed-keys-directory &quot;/var/named/dynamic&quot;;<br>        pid-file &quot;/run/named/named.pid&quot;;<br>        session-keyfile &quot;/run/named/session.key&quot;;<br>};</pre><pre>logging {<br>        channel default_debug {<br>                file &quot;data/named.run&quot;;<br>                severity dynamic;<br>        };<br>};</pre><pre>zone &quot;.&quot; IN {<br>        type hint;<br>        file &quot;named.ca&quot;;<br>};</pre><pre><strong>// forward zone<br>zone &quot;localdns.com&quot; IN {<br>        type master;<br>        file &quot;localdns.forward.zone&quot;;<br>        allow-update { none; };<br>        allow-query { 10.0.1.0/24; };<br>};</strong></pre><pre><strong>// reverse zone<br>zone &quot;1.0.10.in-addr.arpa&quot; IN {<br>        type master;<br>        file &quot;localdns.reverse.zone&quot;;<br>        allow-update { none; };<br>        allow-query { 10.0.1.0/24; };<br>};</strong></pre><pre>include &quot;/etc/named.rfc1912.zones&quot;;<br>include &quot;/etc/named.root.key&quot;;</pre><p>Next create zone files. Server checks both forward and reverse zone files in above specified directory location (var/named).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*7LcnAdczDikG9Du_naKbrw.png" /><figcaption>Forward &amp; Reverse lookup</figcaption></figure><h4>2. Forward zone</h4><p>Create file <em>localdns.forward.zone</em></p><p># vi /var/named/localdns.forward.zone</p><p>Add following codes</p><pre>$TTL 3H<br>@       IN SOA  servera.localdns.com. root.servera.localdns.com. (<br>                                        0       ; serial<br>                                        1D      ; refresh<br>                                        1H      ; retry<br>                                        1W      ; expire<br>                                        3H )    ; minimum<br>; name server information<br>@       IN NS   servera.localdns.com.<br>; name server IP address<br>servera IN A    10.0.1.2</pre><pre>; doc server entry (doc.localdns.com)<br>doc     IN A    10.0.1.5</pre><pre>;web server entry (web.localdns.com)<br>web     IN A    10.0.1.4</pre><pre>; mail server entry (mail.localdns.com)<br>1W      IN MX 10 mail<br>mail    IN A    10.0.1.6</pre><p>Here time to live (TTL) specifies the default caching time for domain. Next section is Start of Authority (SOA). Briefly, @ is alias for Fully Qualified Domain Name (FQDN). Next servera.localdns.com. is FQDN for authoritative name server. FQDN has “.” at end. Next root.servera.localdns.com. specifies admin email account. “@” is replaced by “.”.</p><pre>@ IN NS servera.localdns.com.</pre><p>IN sets record type as internet.</p><p>NS sets record type as Name Server Record.</p><p>servera.localdns.com. is FQDN of name server.</p><p>Next each host record has IP record (which specifies each server located in which IP address).</p><p>servera IN A 10.0.1.2This record resolves servera record to 10.0.1.2 IP address.</p><p>A specifies IPV4 address. Use AAAA for IPV6.</p><p>Similarly in above example, record for doc host is resolved to 10.0.1.5 and web host for 10.0.1.4.</p><pre>doc     IN A    10.0.1.5<br>web     IN A    10.0.1.4</pre><p>Mail record has 1W IN MX 10 mail.</p><p>1W is TTL for mail record.</p><p>MX sets record type as <em>mail exchange</em> where SMTP server looks for. Next number 10 is the preference number. Lower number means higher preference. Finally mail record is mapped to 10.0.1.6 mail IN A 10.0.1.6</p><h4>3. Reverse zone</h4><p>Create file <em>localdns.reverse.zone</em></p><p># Vi /var/named/localdns.reverse.zone</p><p>Add following codes and save file.</p><pre>$TTL 3H<br>@       IN SOA  servera.localdns.com. root.servera.localdns.com. (<br>                                        0       ; serial<br>                                        1D      ; refresh<br>                                        1H      ; retry<br>                                        1W      ; expire<br>                                        3H )    ; minimum<br>; Name server<br>@       IN      NS      servera.localdns.com.<br>2       IN      NS      servera.localdns.com.</pre><pre>; Doc server<br>5       IN      PTR     doc.localdns.com.</pre><pre>; Web server<br>4       IN      PTR     web.localdns.com.</pre><pre>; Mail server<br>6       IN      PTR     mail.localdns.com.</pre><p>These lines specify name server record. 5 IN PTR doc.localdns.com. Specifies doc server’s hostname doc.localdns.com. to .5 address. PTR (Pointer) used to map IP address to a host. Similarly web server is mapped to 4 and, mail server is pointed to 6 address.</p><p>At this point, DNS configurations are complete and server is ready.</p><p>Also need to open firewall ports in CentOS.</p><pre># firewall-cmd –add-port=53/udp –permanent<br># firewall-cmd –reload</pre><p>Finally start start name server service.</p><p># systemctl start named</p><h4>4. Client side configuration</h4><p>Client machine should have DNS server address as 10.0.1.2 and should connected to same network. Next edit /etc/resolv.conf <strong>(This client side nameserver configuration is temporary)</strong></p><p># vi /etc/resolv.conf</p><p>Add following lines</p><pre>nameserver <strong>10.0.1.2</strong><br>search <strong>localdns.com</strong></pre><p>Add nameserver record 10.0.1.2 on top if there are multiple servers. Then the resolver library queries them in the order listed. Next add search localdns.com This way, the host can also able to browse internet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*B5GmXbwX6hbMcKC6dwwtOg.png" /></figure><h4>5. Verification</h4><p>Now we can query specified hostnames from client machine.</p><p>Use <strong>Nslookup</strong> tool to querry Name servers.</p><p>nslookup web.localdns.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*HIbu1CvL2_x7I5IfULs4yg.png" /></figure><p>Use <strong>dig</strong> tool to perform DNS lookups and display answers check for Answer Section.</p><p>dig mail.localdns.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6jOraKd3He7X5s-Hmoc-mQ.png" /></figure><p>Use command digwith -x flag to perform reverse lookup. Check Answer Section.</p><p>dig -x 10.0.1.5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*AkaD730rQSE649G-N6UCJw.png" /></figure><h4>Summary</h4><p>In this example a DNS server is configured in CentOS 7. DNS server’s forward and reverse zones configured to contain records of hostnames and IP addresses of 3 other servers. A client machine is configured to access the DNS service. Finally, the client machine quarried both forward and reverse DNS records with nslookup and dig tools.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ebc2db5a141" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple network topology using Mininet and installing flow rules directly on controller]]></title>
            <link>https://medium.com/@deelaka.perera/simple-network-topology-using-mininet-and-installing-flow-rules-directly-on-controller-3ec61ca2b962?source=rss-5ecbc36792dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ec61ca2b962</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Deelaka Perera]]></dc:creator>
            <pubDate>Tue, 05 Jul 2022 07:42:45 GMT</pubDate>
            <atom:updated>2022-07-05T07:42:45.180Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*gr1m0TatwY7HrxQ7wYFtZw.png" /></figure><p>Mininet is a software emulator for simulating a big network on one computer for the development of Software-Defined Networks (SDN). It can be used to quickly build an accurate virtual network running real kernel, switch, and software application code, interact with, customize, and share a Software-Defined Network (SDN) prototype, and mimic a network topology using OpenFlow switches. The major purpose of Mininet is to test, experiment, and learn about software-defined networks.</p><h4>Installing Mininet</h4><p>Mininet Virtual Machine installation is the easiest way to installing Mininet. Select required Mininet version and download VM image from <a href="https://github.com/mininet/mininet/releases/">here</a>. After that it is just running the image using your preferred virtualization system (VMware, VirtualBox).</p><p>Refer <a href="http://mininet.org/download/">this</a> for more installation options. Boot up Mininet VM and you will land into login screen. Default username: mininet, password: mininet</p><h4>Create simple topology</h4><p>Create custom topology using a python file. The topology is as follows:</p><p>There are 5 hosts (from <em>10.0.0.1 to 10.0.0.5</em>), 4 switches and 1 POX controller. The controller is connected to all 4 switches. All hosts should be able to communicate with each other except both<strong> <em>h1(10.0.0.1), h2(10.0.0.2)</em> should not be able to communicate with <em>h5(10.0.0.5)</em></strong> and, <strong><em>h5(10.0.0.5)</em> should not be able to communicate with <em>h1(10.0.0.1), h2(10.0.0.2)</em></strong> hosts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*EN8I5lLEm9pYXENNDd0mTQ.png" /></figure><p>First create python file in mininet including topology information. Use command vi topology.py</p><pre>from mininet.net import Mininet<br>from mininet.node import Controller, OVSKernelSwitch, RemoteController<br>from mininet.cli import CLI<br>from mininet.log import setLogLevel, info</pre><pre>def emptyNet():<br>    net = Mininet(controller=RemoteController, switch=OVSKernelSwitch)<br>    c1 = net.addController(&#39;c1&#39;, controller=RemoteController, ip=&#39;127.0.0.1&#39;, port=6633 )</pre><pre>    h1 = net.addHost(&#39;h1&#39;, ip=&#39;10.0.0.1&#39;)<br>    h2 = net.addHost(&#39;h2&#39;, ip=&#39;10.0.0.2&#39;)<br>    h3 = net.addHost(&#39;h3&#39;, ip=&#39;10.0.0.3&#39;)<br>    h4 = net.addHost(&#39;h4&#39;, ip=&#39;10.0.0.4&#39;)<br>    h5 = net.addHost(&#39;h5&#39;, ip=&#39;10.0.0.5&#39;)</pre><pre>    s1 = net.addSwitch(&#39;s1&#39;)<br>    s2 = net.addSwitch(&#39;s2&#39;)<br>    s3 = net.addSwitch(&#39;s3&#39;)<br>    s4 = net.addSwitch(&#39;s4&#39;)</pre><pre>    s1.linkTo(h1)<br>    s1.linkTo(h2)<br>    s2.linkTo(h3)<br>    s3.linkTo(h4)<br>    s4.linkTo(h5)<br>    s1.linkTo(s2)<br>    s2.linkTo(s3)<br>    s2.linkTo(s4)</pre><pre>    net.build()<br>    c1.start()</pre><pre>    s1.start([c1])<br>    s2.start([c1])<br>    s3.start([c1])<br>    s4.start([c1])</pre><pre>    CLI(net)<br>    net.stop()</pre><pre>if __name__ == &#39;__main__&#39;:<br>    setLogLevel(&#39;info&#39;)<br>    emptyNet()</pre><p>First import required libraries such as Controller, OVSKernelSwitch</p><p>Add controller information such as controller name (c1), controller’s ip address (127.0.0.1) and port. Port should be the OpenFlow port of the controller. Default ports are 6633, 6653.</p><p>Next hosts are added using net.addHost()as h1, h2 … and ip addresses are assigned for each host.</p><pre>h1 = net.addHost(‘h1’, ip=’10.0.0.1&#39;)</pre><pre>h2 = net.addHost(‘h2’, ip=’10.0.0.2&#39;)</pre><p>Next add switches using net.addSwitch(). 4 switches are added from s1 to s4.</p><pre>s1 = net.addSwitch(‘s1’)</pre><pre>s2 = net.addSwitch(‘s2’)</pre><p>Use linkTo()to add links between each host to a switch. And also to link each switches.</p><pre>s1.linkTo(h1)</pre><pre>s1.linkTo(s2)</pre><p>Line c1.start()starts controller. Here c1 is the variable name where controller information is saved. Next lines start each switch. This line s1.start([c1]) starts switch S1 with controller C1 connected.</p><p>Below codes are for main function. Here log level is set to info and topology function emptyNet()is called. Save file and exit.</p><h4>Starting topology</h4><p>Use command sudo python topology.pyto run topology file which create our topology in Mininet. Make sure to remove previously deployed topologies before running. Use command sudo mn -cto remove.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*CXdQ6PLpFgJmJCtbgCXZIw.png" /></figure><h4>Configuring controller</h4><p>POX controller is used here. Rules to flow control are directly installed in POX. Separate Python file is created to deploy flow rules to the network. Refer <a href="https://noxrepo.github.io/pox-doc/html/#ofp-flow-mod-flow-table-modification">this</a> for more information. From Mininet home, locate to the pox directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*xtFipuphfKkZbIPC2kBfJw.png" /></figure><p>OpenFlow has several steps to handle events.</p><p>Step 1: Listener: Listener says what to do with the packet. Main functions are connectionUp (Establish new control channel with a switch), connectionDown (Connection with a switch terminated), packetIn (OpenFlow packet-in message caused by switch cannot handle arriving packet), portStatus etc.</p><p>Step 2: Execute control logic: Commands to what to do with the packet; packet matching rules and actions (forward, flood, block etc).</p><p>Step 3: Send instruction to switch.</p><p>Create rules Python file using vi editor. Name used here is rulesPOX.py Content in rules file is as following</p><pre>from pox.core import core<br>import pox.openflow.libopenflow_01 as of<br>from pox.lib.util import dpid_to_str<br>from pox.openflow.of_json import*<br>log = core.getLogger()<br>s1_dpid = 0<br>s2_dpid = 0<br>s3_dpid = 0<br>s4_dpid = 0<br>def _ConnectionUp (event):<br>    global s1_dpid, s2_dpid, s3_dpid, s4_dpid<br>    for m in event.connection.features.ports:<br>        if m.name == &quot;s1-eth1&quot;:<br>            s1_dpid = event.connection.dpid<br>        elif m.name == &quot;s2-eth1&quot;:<br>            s2_dpid = event.connection.dpid<br>        elif m.name == &quot;s3-eth1&quot;:<br>            s3_dpid = event.connection.dpid<br>        elif m.name == &quot;s4-eth1&quot;:<br>            s4_dpid = event.connection.dpid</pre><pre>def _PacketIn (event):<br>    global s1_dpid, s2_dpid, s3_dpid, s4_dpid<br>    if event.connection.dpid == s1_dpid:<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.2&quot;, nw_dst=&quot;10.0.0.5&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.1&quot;, nw_dst=&quot;10.0.0.5&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.1&quot;, nw_dst=&quot;10.0.0.5&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.5&quot;, nw_dst=&quot;10.0.0.1&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.5&quot;, nw_dst=&quot;10.0.0.2&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.1&quot;, nw_dst=&quot;10.0.0.2&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=3),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.1&quot;, nw_dst=&quot;10.0.0.3&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=3),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.1&quot;, nw_dst=&quot;10.0.0.4&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=1),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.2&quot;, nw_dst=&quot;10.0.0.1&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=3),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.2&quot;, nw_dst=&quot;10.0.0.3&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=3),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.2&quot;, nw_dst=&quot;10.0.0.4&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=1),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.0/24&quot;, nw_dst=&quot;10.0.0.1&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.0/24&quot;, nw_dst=&quot;10.0.0.2&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_ALL), match=of.ofp_match(dl_type=0x806)))<br>    elif event.connection.dpid == s2_dpid:<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.3&quot;, nw_dst=&quot;10.0.0.1&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.3&quot;, nw_dst=&quot;10.0.0.2&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=3),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.3&quot;, nw_dst=&quot;10.0.0.4&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=4),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.3&quot;, nw_dst=&quot;10.0.0.5&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=1),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.0/24&quot;, nw_dst=&quot;10.0.0.3&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_ALL),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.0/24&quot;, nw_dst=&quot;10.0.0.0/24&quot;))) <br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_ALL), match=of.ofp_match(dl_type=0x806)))<br>    elif event.connection.dpid == s3_dpid:<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.4&quot;, nw_dst=&quot;10.0.0.0/24&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=1),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.0/24&quot;, nw_dst=&quot;10.0.0.4&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_ALL), match=of.ofp_match(dl_type=0x806)))<br>    elif event.connection.dpid == s4_dpid:<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.1&quot;, nw_dst=&quot;10.0.0.5&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.2&quot;, nw_dst=&quot;10.0.0.5&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.5&quot;, nw_dst=&quot;10.0.0.1&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_NONE),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.5&quot;, nw_dst=&quot;10.0.0.2&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.5&quot;, nw_dst=&quot;10.0.0.3&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=2),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.5&quot;, nw_dst=&quot;10.0.0.4&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=1),match=of.ofp_match(dl_type=0x800, nw_src=&quot;10.0.0.0/24&quot;, nw_dst=&quot;10.0.0.5&quot;)))<br>        event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=of.OFPP_ALL), match=of.ofp_match(dl_type=0x806)))</pre><pre>def launch():<br>    core.openflow.addListenerByName(&quot;ConnectionUp&quot;, _ConnectionUp)<br>    core.openflow.addListenerByName(&quot;PacketIn&quot;, _PacketIn)</pre><p>First import required libraries such as OpenFlow libraries. Implement ConnectionUp event. This get dpid (Data Path ID) of connected switches. Next PacketIn event defines control rules for packets at each switch.</p><p>Here rules are configured for each switch. In rules for S1, first incoming and outgoing HTTP traffic is blocked from <em>10.0.0.5</em> to <em>10.0.0.1, 10.0.0.2</em>. Next each port number is configured for each destination ip address.</p><pre>Eg: event.connection.send(of.ofp_flow_mod(action=of.ofp_action_output(port=3),match=of.ofp_match(dl_type=0x800, nw_src=”10.0.0.1&quot;, nw_dst=”10.0.0.3&quot;)))</pre><p>This command tells to forward HTTP traffic (0x800), to port 3 when incoming packet matches <em>src ip = 10.0.0.1</em> and <em>dst ip = 10.0.0.3</em></p><p>Switch 1 drops HTTP packets using OFPP_NONE when src ip 10.0.0.1 and dst ip = 10.0.0.5 Also ARP (0x806) packets are forwarded to all ports except in port.</p><p>Similarly S2 is configured with port numbers to its directly connected host and if a packet is received from any other src/dst ip, it forwards to all ports. Then that packet will reach to its relevant switch or else dropped.</p><p>Rules can be configured one by one in this case for each ip address or simply use wildcard such as 10.0.0.0/24 to reduce number of rules required. Also take note of the order of the rules when access controlling.</p><p>Following are the supported forwarding options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*112e2txDDzKSgOZyS87Zbw.png" /></figure><h4>Testing the network</h4><p>Start POX controller with created custom rules file using command <em>sudo ./pox.py &lt;filename&gt; </em>POX logger displays which switches are connected with their IDs. Make sure topology is running.</p><pre>sudo ./pox.py rulesPOX</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*oazJsqOaCHRFs7EYNZxITA.png" /></figure><p>Now the connectivity can be checked by issuing command pingall. If POX rules added correctly, the output should be similar to following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*fwi-x-14bYGxen3QZw1iyA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ec61ca2b962" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>