SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
Introduction to Firewalls
           through

           Linux iptables


By: Buddhika Siddhisena <bud@thinkcube.com>
Co-Founder & CTO, THINKCube,
Avid FOSS advocate
What is a firewall?
          ●   Network barrier
          ●   Packet filtering
          ●   Packet Mangling
              (NAT)
Firewall Usage
●   Personal Firewall
●   Multi-homed (DMZ) Firewall
●   Router Firewall
●   Internet connection sharing (NAT)
●   Transparent Proxying
●   Content filtering
●   Poor-mans load balancer
●   Internet Hotspots
What is iptables?

 ●   Linux's built in firewall
 ●   Successor to ipchains
 ●   Organizes several chains into
     tables, hence iptables
 ●   Consists of Userspace tool
     (iptables) and kernel drivers
A table of Chains
    Filter Table (default)
    INPUT                                 FORWARD           OUTPUT
    NAT Table
    PREROUTING                INPUT       OUTPUT            POSTROUTING
    Mangle Table
    PREROUTING        INPUT   OUTPUT      FORWARD           POSTROUTING
    X Table (user defined)

●   INPUT – Packets entering an interface and destined to a local process.
●   FORWARD – Only packets routed from one interface to another.
●   OUTPUT – Packets leaving an interface which originated from a local process.
●   PREROUTING – Before deciding to use INPUT or FORWARD. DNAT is
    configured here.
●   POSTROUTING – After OUTPUT or FORWARD but before leaving interface.
    SNAT is configured here.
A Chain of Rules
INPUT CHAIN


   Rule 1




   Rule 2



            X       Jump to Action!


   Rule 3

                    Refer to Default Policy
Chain Order
PREROUTING                           POSTROUTING
    Chain            FORWARD             Chain
 (Pre-routing          Chain          (Post routing
  Decisions)                           Decisions)




            INPUT                 OUTPUT
             Chain                 Chain




                         Local
                        Process
Security Policy
             Block everyone                          Allow everyone
                by default                              by default
            (default policy:DROP)                  (default policy:ACCEPT)
 White                                  Black
 Listing                                Listing

 Sorry!     Bang!
Can't let   Bang!
(REJECT)    (DROP)
                                    Best security is when you..

                                    ●Trust no one
                                    ● Make it un economical
Using iptables
Synopsis
iptables [table] [action] [chain] [option] [target]

table – {filter, nat, mangle}
 action – {-A (add), -D (delete), -R (replace)}
 chain – {INPUT, FORWARD, OUTPUT etc.}
 options - {-s(source), -d(destination), --sport(source port,
--dport(destination port), -m (module), --sync (sync
packed) etc.}
  target – {ACCEPT, DROP, REJECT, MASQUERADE,
DNAT etc.}
Basic Usage
iptables -L     // List all rules for filter table

iptables -t nat -L // List all rules for nat table

iptables -F    // Flush (clear) all rules of all chains

iptables -F INPUT // Flush all rules for INPUT chain

iptables -P INPUT DROP // Set default policy of INPUT
Filtering
                Soure IP: 192.168.1.80
                Source Port: 80
                Dest IP: 192.168.2.10
                Dest Port: X?



                                    Soure IP: 192.168.2.10
                                    Source Port: X?
                                    Dest IP: 192.168.1.80
                                    Dest Port: 80


iptables -P INPUT DROP       // Drop (block) everything
iptables -P OUTPUT DROP
iptables -A INPUT -p tcp --dport 80 -j ACCEPT // Only allow http
iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT // allow packet
to go out
Filtering Examples
// Allow ping
iptables -A INPUT -p icmp -j ACCEPT

// Allow all incoming tcp connections on interface eth0 to port 80
(www)
iptables -A INPUT -i eth0 -p tcp --sport 1024: --dport
80 -j ACCEPT

// Allow DNS
iptables -A INPUT -p udp --dport 53 -j ACCEPT

// Allow multiple ports for Email
iptables -A INPUT -p tcp -m multiport --dport 25,110,143 -j ACCEPT

// Allow a MAC
iptables -A INPUT -m mac --mac-source 00:02:8A:A1:71:71 -j ACCEPT
Connection Tracking
         Soure IP: 192.168.1.80
         Source Port: 80
         Dest IP: 192.168.2.10
         Dest Port: X?



                            Soure IP: 192.168.2.10
                            Source Port: X?
                            Dest IP: 192.168.1.80
                            Dest Port: 80

// Allow http new and existing connections
iptables -A INPUT -p tcp -m state --state
NEW,ESTABLISHED,RELATED --dport 80 -j ACCEPT

// Allow only existing connections to go out
iptables -A OUTPUT -p tcp -m state --state
ESTABLISHED,RELATED --sport 80 -j ACCEPT
No Action, Log only

// Log Syn flooding

iptables -A INPUT -p tcp --syn -m limit
--limit 1/s --limit-burst 3 -j LOG --log-prefix
“SYN flood: ”
Network Address Translation
      SNAT (Source)                DNAT (Dest)

     Change source from          Change destination from
      private to public IP         public to pirvate IP


●   Your ADSL Router         ●    DMZ setups
●   Internet Connection      ●    Transparent Proxies
    Sharing                  ●    Load balancers
●   WiFi hotspots            ●    High availability
●   IP Spoofing
NATing Examples
// First enable ip forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

// Sharing internet (3G)
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

// Poor man's http load balancer
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to
192.168.1.80:8080

// Transparent Proxy
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j
REDIRECT --to-port 3128
Persistence
// Save rules
iptables-save > /etc/iptables.conf

// Restore rules
iptables-restore < /etc/iptables.conf

// If you have virtual service
/etc/init.d/iptables [stop|start|save]

// If you don't have virtual service to auto start add restore
command to /etc/rc.local or any other bootup script
Thank You!

Weitere ähnliche Inhalte

Was ist angesagt?

VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux KernelKernel TLV
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabMichelle Holley
 
Access Control List (ACL)
Access Control List (ACL)Access Control List (ACL)
Access Control List (ACL)ISMT College
 
A Quick Introduction to Linux
A Quick Introduction to LinuxA Quick Introduction to Linux
A Quick Introduction to LinuxTusharadri Sarkar
 
Differences of the Cisco Operating Systems
Differences of the Cisco Operating SystemsDifferences of the Cisco Operating Systems
Differences of the Cisco Operating Systems美兰 曾
 
Vlans and inter vlan routing
Vlans and inter vlan routingVlans and inter vlan routing
Vlans and inter vlan routingMohammedseleim
 
From Cisco ACS to ISE
From Cisco ACS to ISE From Cisco ACS to ISE
From Cisco ACS to ISE Mahzad Zahedi
 
Spanning tree protocol (stp)
Spanning tree protocol (stp)Spanning tree protocol (stp)
Spanning tree protocol (stp)RaghulR21
 
Introduction to SSH
Introduction to SSHIntroduction to SSH
Introduction to SSHHemant Shah
 
nftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewallnftables - the evolution of Linux Firewall
nftables - the evolution of Linux FirewallMarian Marinov
 
TRex Realistic Traffic Generator - Stateless support
TRex  Realistic Traffic Generator  - Stateless support TRex  Realistic Traffic Generator  - Stateless support
TRex Realistic Traffic Generator - Stateless support Hanoch Haim
 

Was ist angesagt? (20)

VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux Kernel
 
Bgp protocol
Bgp protocolBgp protocol
Bgp protocol
 
NMAP
NMAPNMAP
NMAP
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on Lab
 
hpsr-2020-srv6-tutorial
hpsr-2020-srv6-tutorialhpsr-2020-srv6-tutorial
hpsr-2020-srv6-tutorial
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
Access Control List (ACL)
Access Control List (ACL)Access Control List (ACL)
Access Control List (ACL)
 
A Quick Introduction to Linux
A Quick Introduction to LinuxA Quick Introduction to Linux
A Quick Introduction to Linux
 
Differences of the Cisco Operating Systems
Differences of the Cisco Operating SystemsDifferences of the Cisco Operating Systems
Differences of the Cisco Operating Systems
 
Vlans and inter vlan routing
Vlans and inter vlan routingVlans and inter vlan routing
Vlans and inter vlan routing
 
From Cisco ACS to ISE
From Cisco ACS to ISE From Cisco ACS to ISE
From Cisco ACS to ISE
 
Spanning tree protocol (stp)
Spanning tree protocol (stp)Spanning tree protocol (stp)
Spanning tree protocol (stp)
 
Introduction to SSH
Introduction to SSHIntroduction to SSH
Introduction to SSH
 
2011 cisco icons 6_8_11
2011 cisco icons 6_8_112011 cisco icons 6_8_11
2011 cisco icons 6_8_11
 
Cisco ASA Firewalls
Cisco ASA FirewallsCisco ASA Firewalls
Cisco ASA Firewalls
 
An Introduction To Linux
An Introduction To LinuxAn Introduction To Linux
An Introduction To Linux
 
Iptables the Linux Firewall
Iptables the Linux Firewall Iptables the Linux Firewall
Iptables the Linux Firewall
 
nftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewallnftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewall
 
Ether channel fundamentals
Ether channel fundamentalsEther channel fundamentals
Ether channel fundamentals
 
TRex Realistic Traffic Generator - Stateless support
TRex  Realistic Traffic Generator  - Stateless support TRex  Realistic Traffic Generator  - Stateless support
TRex Realistic Traffic Generator - Stateless support
 

Andere mochten auch

Packet Filtering Using Iptables
Packet Filtering Using IptablesPacket Filtering Using Iptables
Packet Filtering Using IptablesAhmed Mekkawy
 
Iptables fundamentals
Iptables fundamentalsIptables fundamentals
Iptables fundamentalsram_b17
 
25 most frequently used linux ip tables rules examples
25 most frequently used linux ip tables rules examples25 most frequently used linux ip tables rules examples
25 most frequently used linux ip tables rules examplesTeja Bheemanapally
 
Fighting Identity Theft: Big Data Analytics to the Rescue
Fighting Identity Theft: Big Data Analytics to the RescueFighting Identity Theft: Big Data Analytics to the Rescue
Fighting Identity Theft: Big Data Analytics to the RescueSeshika Fernando
 
Basics of firewall, ebtables, arptables and iptables
Basics of firewall, ebtables, arptables and iptablesBasics of firewall, ebtables, arptables and iptables
Basics of firewall, ebtables, arptables and iptablesPrzemysław Piotrowski
 
Iptables Configuration
Iptables ConfigurationIptables Configuration
Iptables Configurationstom123
 
Snort it-slideshares.blogspot.com
Snort it-slideshares.blogspot.comSnort it-slideshares.blogspot.com
Snort it-slideshares.blogspot.comphanleson
 
Fosscon 2012 firewall workshop
Fosscon 2012 firewall workshopFosscon 2012 firewall workshop
Fosscon 2012 firewall workshopjvehent
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017Drift
 

Andere mochten auch (14)

Iptables
IptablesIptables
Iptables
 
Packet Filtering Using Iptables
Packet Filtering Using IptablesPacket Filtering Using Iptables
Packet Filtering Using Iptables
 
Iptables in linux
Iptables in linuxIptables in linux
Iptables in linux
 
Iptables fundamentals
Iptables fundamentalsIptables fundamentals
Iptables fundamentals
 
Ip tables
Ip tablesIp tables
Ip tables
 
25 most frequently used linux ip tables rules examples
25 most frequently used linux ip tables rules examples25 most frequently used linux ip tables rules examples
25 most frequently used linux ip tables rules examples
 
Fighting Identity Theft: Big Data Analytics to the Rescue
Fighting Identity Theft: Big Data Analytics to the RescueFighting Identity Theft: Big Data Analytics to the Rescue
Fighting Identity Theft: Big Data Analytics to the Rescue
 
Basics of firewall, ebtables, arptables and iptables
Basics of firewall, ebtables, arptables and iptablesBasics of firewall, ebtables, arptables and iptables
Basics of firewall, ebtables, arptables and iptables
 
iptables
iptablesiptables
iptables
 
Iptables Configuration
Iptables ConfigurationIptables Configuration
Iptables Configuration
 
Snort it-slideshares.blogspot.com
Snort it-slideshares.blogspot.comSnort it-slideshares.blogspot.com
Snort it-slideshares.blogspot.com
 
Fosscon 2012 firewall workshop
Fosscon 2012 firewall workshopFosscon 2012 firewall workshop
Fosscon 2012 firewall workshop
 
Projet IPTable
Projet  IPTableProjet  IPTable
Projet IPTable
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
 

Ähnlich wie Introduction to firewalls through Iptables

How to convert your Linux box into Security Gateway - Part 1
How to convert your Linux box into Security Gateway - Part 1How to convert your Linux box into Security Gateway - Part 1
How to convert your Linux box into Security Gateway - Part 1n|u - The Open Security Community
 
Modul 3 Firewalll.ppt
Modul 3 Firewalll.pptModul 3 Firewalll.ppt
Modul 3 Firewalll.pptcemporku
 
CCNA_LAB_MANUAL_part1.pptx
CCNA_LAB_MANUAL_part1.pptxCCNA_LAB_MANUAL_part1.pptx
CCNA_LAB_MANUAL_part1.pptxSanathKumarV3
 
In depth understanding network security
In depth understanding network securityIn depth understanding network security
In depth understanding network securityThanawan Tuamyim
 
Complete squid &amp; firewall configuration. plus easy mac binding
Complete squid &amp; firewall configuration. plus easy mac bindingComplete squid &amp; firewall configuration. plus easy mac binding
Complete squid &amp; firewall configuration. plus easy mac bindingChanaka Lasantha
 
Athenticated smaba server config with open vpn
Athenticated smaba server  config with open vpnAthenticated smaba server  config with open vpn
Athenticated smaba server config with open vpnChanaka Lasantha
 
Linux internet server security and configuration tutorial
Linux internet server security and configuration tutorialLinux internet server security and configuration tutorial
Linux internet server security and configuration tutorialannik147
 
Firewalls rules using iptables in linux
Firewalls rules using iptables in linuxFirewalls rules using iptables in linux
Firewalls rules using iptables in linuxaamir lucky
 
25 most frequently used linux ip tables rules examples
25 most frequently used linux ip tables rules examples25 most frequently used linux ip tables rules examples
25 most frequently used linux ip tables rules examplesTeja Bheemanapally
 
Stupid iptables tricks
Stupid iptables tricksStupid iptables tricks
Stupid iptables tricksJim MacLeod
 
Router Commands Overview
Router Commands OverviewRouter Commands Overview
Router Commands OverviewMuhammed Niyas
 
Pf: the OpenBSD packet filter
Pf: the OpenBSD packet filterPf: the OpenBSD packet filter
Pf: the OpenBSD packet filterGiovanni Bechis
 
Arp Dan Ipconfig Syntax
Arp Dan Ipconfig  SyntaxArp Dan Ipconfig  Syntax
Arp Dan Ipconfig Syntaxguestcc37e8c
 
Reducing iptables configuration complexity using chains
Reducing iptables configuration complexity using chainsReducing iptables configuration complexity using chains
Reducing iptables configuration complexity using chainsDieter Adriaenssens
 
IPv6 for Pentesters
IPv6 for PentestersIPv6 for Pentesters
IPv6 for Pentesterscamsec
 

Ähnlich wie Introduction to firewalls through Iptables (20)

How to convert your Linux box into Security Gateway - Part 1
How to convert your Linux box into Security Gateway - Part 1How to convert your Linux box into Security Gateway - Part 1
How to convert your Linux box into Security Gateway - Part 1
 
Modul 3 Firewalll.ppt
Modul 3 Firewalll.pptModul 3 Firewalll.ppt
Modul 3 Firewalll.ppt
 
IPTABLES
IPTABLESIPTABLES
IPTABLES
 
CCNA_LAB_MANUAL_part1.pptx
CCNA_LAB_MANUAL_part1.pptxCCNA_LAB_MANUAL_part1.pptx
CCNA_LAB_MANUAL_part1.pptx
 
In depth understanding network security
In depth understanding network securityIn depth understanding network security
In depth understanding network security
 
Complete squid &amp; firewall configuration. plus easy mac binding
Complete squid &amp; firewall configuration. plus easy mac bindingComplete squid &amp; firewall configuration. plus easy mac binding
Complete squid &amp; firewall configuration. plus easy mac binding
 
Athenticated smaba server config with open vpn
Athenticated smaba server  config with open vpnAthenticated smaba server  config with open vpn
Athenticated smaba server config with open vpn
 
Linux internet server security and configuration tutorial
Linux internet server security and configuration tutorialLinux internet server security and configuration tutorial
Linux internet server security and configuration tutorial
 
Ip6 tables in linux
Ip6 tables in linuxIp6 tables in linux
Ip6 tables in linux
 
Firewalls rules using iptables in linux
Firewalls rules using iptables in linuxFirewalls rules using iptables in linux
Firewalls rules using iptables in linux
 
25 most frequently used linux ip tables rules examples
25 most frequently used linux ip tables rules examples25 most frequently used linux ip tables rules examples
25 most frequently used linux ip tables rules examples
 
Stupid iptables tricks
Stupid iptables tricksStupid iptables tricks
Stupid iptables tricks
 
Router Commands Overview
Router Commands OverviewRouter Commands Overview
Router Commands Overview
 
Pf: the OpenBSD packet filter
Pf: the OpenBSD packet filterPf: the OpenBSD packet filter
Pf: the OpenBSD packet filter
 
Arp Dan Ipconfig Syntax
Arp Dan Ipconfig  SyntaxArp Dan Ipconfig  Syntax
Arp Dan Ipconfig Syntax
 
Reducing iptables configuration complexity using chains
Reducing iptables configuration complexity using chainsReducing iptables configuration complexity using chains
Reducing iptables configuration complexity using chains
 
IPv6 for Pentesters
IPv6 for PentestersIPv6 for Pentesters
IPv6 for Pentesters
 
IPv6 for Pentesters
IPv6 for PentestersIPv6 for Pentesters
IPv6 for Pentesters
 
Ccna Imp Guide
Ccna Imp GuideCcna Imp Guide
Ccna Imp Guide
 
03 linuxfirewall1
03 linuxfirewall103 linuxfirewall1
03 linuxfirewall1
 

Mehr von Bud Siddhisena

Building apis that don’t suck!
Building apis that don’t suck!Building apis that don’t suck!
Building apis that don’t suck!Bud Siddhisena
 
Why should you android (archived)
Why should you android (archived)Why should you android (archived)
Why should you android (archived)Bud Siddhisena
 
Virtualization, The future of computing (archived)
Virtualization, The future of computing (archived)Virtualization, The future of computing (archived)
Virtualization, The future of computing (archived)Bud Siddhisena
 
Building the Next big thing (archived)
Building the Next big thing (archived)Building the Next big thing (archived)
Building the Next big thing (archived)Bud Siddhisena
 
GNU/Linux for a better home (archived)
GNU/Linux for a better home (archived)GNU/Linux for a better home (archived)
GNU/Linux for a better home (archived)Bud Siddhisena
 
Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Bud Siddhisena
 
Gaming on linux (archived)
Gaming on linux (archived)Gaming on linux (archived)
Gaming on linux (archived)Bud Siddhisena
 
FOSS in Sri Lanka (archived)
FOSS in Sri Lanka (archived)FOSS in Sri Lanka (archived)
FOSS in Sri Lanka (archived)Bud Siddhisena
 
Contributing to FOSS (archived)
Contributing to FOSS (archived)Contributing to FOSS (archived)
Contributing to FOSS (archived)Bud Siddhisena
 
Choosing your GNU/Linux distribution (archived)
Choosing your GNU/Linux distribution (archived)Choosing your GNU/Linux distribution (archived)
Choosing your GNU/Linux distribution (archived)Bud Siddhisena
 
Beyond desktop/server with GNU/Linux (archived)
Beyond desktop/server with GNU/Linux (archived)Beyond desktop/server with GNU/Linux (archived)
Beyond desktop/server with GNU/Linux (archived)Bud Siddhisena
 
Opensource opportunity
Opensource opportunityOpensource opportunity
Opensource opportunityBud Siddhisena
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with NginxBud Siddhisena
 
Secure your IT infrastructure with GNU/Linux
Secure your IT infrastructure  with GNU/LinuxSecure your IT infrastructure  with GNU/Linux
Secure your IT infrastructure with GNU/LinuxBud Siddhisena
 
Kernel Configuration and Compilation
Kernel Configuration and CompilationKernel Configuration and Compilation
Kernel Configuration and CompilationBud Siddhisena
 

Mehr von Bud Siddhisena (20)

JIT qa-docker
JIT qa-dockerJIT qa-docker
JIT qa-docker
 
Building apis that don’t suck!
Building apis that don’t suck!Building apis that don’t suck!
Building apis that don’t suck!
 
Why should you android (archived)
Why should you android (archived)Why should you android (archived)
Why should you android (archived)
 
Virtualization, The future of computing (archived)
Virtualization, The future of computing (archived)Virtualization, The future of computing (archived)
Virtualization, The future of computing (archived)
 
Building the Next big thing (archived)
Building the Next big thing (archived)Building the Next big thing (archived)
Building the Next big thing (archived)
 
GNU/Linux for a better home (archived)
GNU/Linux for a better home (archived)GNU/Linux for a better home (archived)
GNU/Linux for a better home (archived)
 
Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)
 
Gaming on linux (archived)
Gaming on linux (archived)Gaming on linux (archived)
Gaming on linux (archived)
 
FOSS in Sri Lanka (archived)
FOSS in Sri Lanka (archived)FOSS in Sri Lanka (archived)
FOSS in Sri Lanka (archived)
 
Contributing to FOSS (archived)
Contributing to FOSS (archived)Contributing to FOSS (archived)
Contributing to FOSS (archived)
 
Choosing your GNU/Linux distribution (archived)
Choosing your GNU/Linux distribution (archived)Choosing your GNU/Linux distribution (archived)
Choosing your GNU/Linux distribution (archived)
 
Beyond desktop/server with GNU/Linux (archived)
Beyond desktop/server with GNU/Linux (archived)Beyond desktop/server with GNU/Linux (archived)
Beyond desktop/server with GNU/Linux (archived)
 
UX talk
UX talkUX talk
UX talk
 
Opensource opportunity
Opensource opportunityOpensource opportunity
Opensource opportunity
 
Remembering steve
Remembering steveRemembering steve
Remembering steve
 
Scale Apache with Nginx
Scale Apache with NginxScale Apache with Nginx
Scale Apache with Nginx
 
FOSS and Security
FOSS and SecurityFOSS and Security
FOSS and Security
 
Secure your IT infrastructure with GNU/Linux
Secure your IT infrastructure  with GNU/LinuxSecure your IT infrastructure  with GNU/Linux
Secure your IT infrastructure with GNU/Linux
 
Kernel Configuration and Compilation
Kernel Configuration and CompilationKernel Configuration and Compilation
Kernel Configuration and Compilation
 
Foss Gadgematics
Foss GadgematicsFoss Gadgematics
Foss Gadgematics
 

Kürzlich hochgeladen

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Introduction to firewalls through Iptables

  • 1. Introduction to Firewalls through Linux iptables By: Buddhika Siddhisena <bud@thinkcube.com> Co-Founder & CTO, THINKCube, Avid FOSS advocate
  • 2. What is a firewall? ● Network barrier ● Packet filtering ● Packet Mangling (NAT)
  • 3. Firewall Usage ● Personal Firewall ● Multi-homed (DMZ) Firewall ● Router Firewall ● Internet connection sharing (NAT) ● Transparent Proxying ● Content filtering ● Poor-mans load balancer ● Internet Hotspots
  • 4. What is iptables? ● Linux's built in firewall ● Successor to ipchains ● Organizes several chains into tables, hence iptables ● Consists of Userspace tool (iptables) and kernel drivers
  • 5. A table of Chains Filter Table (default) INPUT FORWARD OUTPUT NAT Table PREROUTING INPUT OUTPUT POSTROUTING Mangle Table PREROUTING INPUT OUTPUT FORWARD POSTROUTING X Table (user defined) ● INPUT – Packets entering an interface and destined to a local process. ● FORWARD – Only packets routed from one interface to another. ● OUTPUT – Packets leaving an interface which originated from a local process. ● PREROUTING – Before deciding to use INPUT or FORWARD. DNAT is configured here. ● POSTROUTING – After OUTPUT or FORWARD but before leaving interface. SNAT is configured here.
  • 6. A Chain of Rules INPUT CHAIN Rule 1 Rule 2 X Jump to Action! Rule 3 Refer to Default Policy
  • 7. Chain Order PREROUTING POSTROUTING Chain FORWARD Chain (Pre-routing Chain (Post routing Decisions) Decisions) INPUT OUTPUT Chain Chain Local Process
  • 8. Security Policy Block everyone Allow everyone by default by default (default policy:DROP) (default policy:ACCEPT) White Black Listing Listing Sorry! Bang! Can't let Bang! (REJECT) (DROP) Best security is when you.. ●Trust no one ● Make it un economical
  • 9. Using iptables Synopsis iptables [table] [action] [chain] [option] [target] table – {filter, nat, mangle} action – {-A (add), -D (delete), -R (replace)} chain – {INPUT, FORWARD, OUTPUT etc.} options - {-s(source), -d(destination), --sport(source port, --dport(destination port), -m (module), --sync (sync packed) etc.} target – {ACCEPT, DROP, REJECT, MASQUERADE, DNAT etc.}
  • 10. Basic Usage iptables -L // List all rules for filter table iptables -t nat -L // List all rules for nat table iptables -F // Flush (clear) all rules of all chains iptables -F INPUT // Flush all rules for INPUT chain iptables -P INPUT DROP // Set default policy of INPUT
  • 11. Filtering Soure IP: 192.168.1.80 Source Port: 80 Dest IP: 192.168.2.10 Dest Port: X? Soure IP: 192.168.2.10 Source Port: X? Dest IP: 192.168.1.80 Dest Port: 80 iptables -P INPUT DROP // Drop (block) everything iptables -P OUTPUT DROP iptables -A INPUT -p tcp --dport 80 -j ACCEPT // Only allow http iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT // allow packet to go out
  • 12. Filtering Examples // Allow ping iptables -A INPUT -p icmp -j ACCEPT // Allow all incoming tcp connections on interface eth0 to port 80 (www) iptables -A INPUT -i eth0 -p tcp --sport 1024: --dport 80 -j ACCEPT // Allow DNS iptables -A INPUT -p udp --dport 53 -j ACCEPT // Allow multiple ports for Email iptables -A INPUT -p tcp -m multiport --dport 25,110,143 -j ACCEPT // Allow a MAC iptables -A INPUT -m mac --mac-source 00:02:8A:A1:71:71 -j ACCEPT
  • 13. Connection Tracking Soure IP: 192.168.1.80 Source Port: 80 Dest IP: 192.168.2.10 Dest Port: X? Soure IP: 192.168.2.10 Source Port: X? Dest IP: 192.168.1.80 Dest Port: 80 // Allow http new and existing connections iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED --dport 80 -j ACCEPT // Allow only existing connections to go out iptables -A OUTPUT -p tcp -m state --state ESTABLISHED,RELATED --sport 80 -j ACCEPT
  • 14. No Action, Log only // Log Syn flooding iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j LOG --log-prefix “SYN flood: ”
  • 15. Network Address Translation SNAT (Source) DNAT (Dest) Change source from Change destination from private to public IP public to pirvate IP ● Your ADSL Router ● DMZ setups ● Internet Connection ● Transparent Proxies Sharing ● Load balancers ● WiFi hotspots ● High availability ● IP Spoofing
  • 16. NATing Examples // First enable ip forwarding echo 1 > /proc/sys/net/ipv4/ip_forward // Sharing internet (3G) iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE // Poor man's http load balancer iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to 192.168.1.80:8080 // Transparent Proxy iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
  • 17. Persistence // Save rules iptables-save > /etc/iptables.conf // Restore rules iptables-restore < /etc/iptables.conf // If you have virtual service /etc/init.d/iptables [stop|start|save] // If you don't have virtual service to auto start add restore command to /etc/rc.local or any other bootup script