SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
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!

Más contenido relacionado

La actualidad más candente

Presentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Presentation On Group Policy in Windows Server 2012 R2 By Barek-ITPresentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Presentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Md. Abdul Barek
 

La actualidad más candente (20)

Linux Networking Commands
Linux Networking CommandsLinux Networking Commands
Linux Networking Commands
 
Next generation firewall(ngfw)feature and benefits
Next generation firewall(ngfw)feature and benefitsNext generation firewall(ngfw)feature and benefits
Next generation firewall(ngfw)feature and benefits
 
Presentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Presentation On Group Policy in Windows Server 2012 R2 By Barek-ITPresentation On Group Policy in Windows Server 2012 R2 By Barek-IT
Presentation On Group Policy in Windows Server 2012 R2 By Barek-IT
 
Samba server configuration
Samba server configurationSamba server configuration
Samba server configuration
 
Red Hat Certified engineer course
  Red Hat Certified engineer course   Red Hat Certified engineer course
Red Hat Certified engineer course
 
HSRP ccna
HSRP ccna HSRP ccna
HSRP ccna
 
Introduction to Linux
Introduction to Linux Introduction to Linux
Introduction to Linux
 
User management
User managementUser management
User management
 
Introduction to Network and System Administration
Introduction to Network and System AdministrationIntroduction to Network and System Administration
Introduction to Network and System Administration
 
Ccnp3 lab 3_4_en
Ccnp3 lab 3_4_enCcnp3 lab 3_4_en
Ccnp3 lab 3_4_en
 
Group policy Best Practices
Group policy Best PracticesGroup policy Best Practices
Group policy Best Practices
 
Nfs
NfsNfs
Nfs
 
Network administration and Management
Network administration and ManagementNetwork administration and Management
Network administration and Management
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
VTP
VTPVTP
VTP
 
Cisco ASA Firewalls
Cisco ASA FirewallsCisco ASA Firewalls
Cisco ASA Firewalls
 
User Administration in Linux
User Administration in LinuxUser Administration in Linux
User Administration in Linux
 
ASA Firepower NGFW Update and Deployment Scenarios
ASA Firepower NGFW Update and Deployment ScenariosASA Firepower NGFW Update and Deployment Scenarios
ASA Firepower NGFW Update and Deployment Scenarios
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
Linux Tutorial For Beginners | Linux Administration Tutorial | Linux Commands...
 

Destacado

Packet Filtering Using Iptables
Packet Filtering Using IptablesPacket Filtering Using Iptables
Packet Filtering Using Iptables
Ahmed Mekkawy
 
Iptables fundamentals
Iptables fundamentalsIptables fundamentals
Iptables fundamentals
ram_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 examples
Teja Bheemanapally
 
Introduction to SSH
Introduction to SSHIntroduction to SSH
Introduction to SSH
Hemant Shah
 
Fosscon 2012 firewall workshop
Fosscon 2012 firewall workshopFosscon 2012 firewall workshop
Fosscon 2012 firewall workshop
jvehent
 

Destacado (16)

Iptables
IptablesIptables
Iptables
 
Iptables presentation
Iptables presentationIptables presentation
Iptables presentation
 
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
 
Introduction to SSH
Introduction to SSHIntroduction to SSH
Introduction to SSH
 
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
 

Similar a Introduction to firewalls through Iptables

In depth understanding network security
In depth understanding network securityIn depth understanding network security
In depth understanding network security
Thanawan 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 binding
Chanaka 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 vpn
Chanaka 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 tutorial
annik147
 
Firewalls rules using iptables in linux
Firewalls rules using iptables in linuxFirewalls rules using iptables in linux
Firewalls rules using iptables in linux
aamir 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 examples
Teja Bheemanapally
 
Router Commands Overview
Router Commands OverviewRouter Commands Overview
Router Commands Overview
Muhammed Niyas
 
Arp Dan Ipconfig Syntax
Arp Dan Ipconfig  SyntaxArp Dan Ipconfig  Syntax
Arp Dan Ipconfig Syntax
guestcc37e8c
 

Similar a 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
 
nftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewallnftables - the evolution of Linux Firewall
nftables - the evolution of Linux Firewall
 
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
 

Más de Bud Siddhisena

Más de 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
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
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...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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 ...
 
+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...
 

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