Firewalling With Netfilter/Iptables. What Is Netfilter/Iptables? Improved successor to ipchains available in linux kernel 2.4/2.6. Netfilter is a set.

Slides:



Advertisements
Similar presentations
1 Network Address Translation (NAT) Relates to Lab 7. Module about private networks and NAT.
Advertisements

IUT– Network Security Course 1 Network Security Firewalls.
Ipchains and Iptables Linux operating system natively supports packet-filtering rules: Kernel versions 2.2 and earlier support the ipchains command. Kernel.
CSCI 530 Lab Firewalls. Overview Firewalls Capabilities Limitations What are we limiting with a firewall? General Network Security Strategies Packet Filtering.
Mateti/PacketFilters1 Packet Filtering Prabhaker Mateti Prabhaker Mateti.
Securing Network using Linux. Lesson Outline Setting up a secure system TCP Wrapper configuration Firewalls in Linux Authentication Systems –NIS –Kerberos.
1 Network Address Translation (NAT) Relates to Lab 7. Module about private networks and NAT.
Packet Filtering CS-480b Dick Steflik. Stateless Packet Filters A border router configured to pass or reject packets based on information in the header.
1 Firewall & IP Tables. 2 Firewall IP Tables FIREWALLS All previous security measures cannot prevent Eve from sending a harmful message to a system.
Ipchains A packet-filtering Firewalls supported by Linux distributions.
Module 10 Linux Gateway (NAT) 10.1 – Introduction 10.2 – Official website and list 10.3 – Two types of NAT 10.4 – Controlling what to NAT 10.5 – How to.
LİNUX-ROUTER-1 Gw1: GW2: ISP1 eth eth /30 LİNUX-ROUTER-2 Gw1: Gw2: eth1.
System Administration Network Tools. ping Test connectivity / latency (RTT) ICMP echo request/reply Variants ◦ARP ping  Send ARP instead  May also ping.
Cs490ns - cotter1 Firewalls What they do. How they work.
NetFilter – IPtables Firewall –Series of rules to govern what Kind of access to allow on your system –Packet filtering –Drop or Accept packets NAT –Network.
07/11/ L10/1/63 COM342 Networks and Data Communications Ian McCrumRoom 5B18 Tel: voice.
Packet Filtering and Firewall
Karlstad University Introduction to Vulnerability Assessment Labs Ge Zhang Dvg-C03.
IPtables Objectives –to learn the basics of iptables Contents –Start and stop IPtables –Checking IPtables status –Input and Output chain –Pre and Post.
SCSC 455 Computer Security Network Security. Control access to system Access control mechanisms in specific network programs  e.g. 1, wu-FTP server support.
Iptables and apache 魏凡琮 (Jerry Wei). Agenda iptables apache.
1 The Firewall Menu. 2 Firewall Overview The GD eSeries appliance provides multiple pre-defined firewall components/sections which you can configure uniquely.
CSCE 815 Network Security Lecture 23 Jails and such April 15, 2003.
Firewalls A device that screens incoming and outgoing network traffic and allows or disallows traffic based on a set of rules The “device” –Needs at least.
1 Firewalls. ECE Internetwork Security 2 Overview Background General Firewall setup Iptables Introduction Iptables commands “Limit” Function Explanation.
1 實驗九:建置網路安全閘道器 教師: 助教:. 2 Outline  Background  Proxy – Squid  Firewall – IPTables  VPN – OpenVPN  Experiment  Internet gateway  Firewall  VPN.
NETWORK SECURITY USING IPTABLES. TOPICS OF DISCUSSION NETWORK TRAFFIC IN PRESENT SCENARIO !! WHY WE NEED SECURITY ? T TYPE OF ATTACKS & WAYS TO TACKLE.
IPtables Objectives Contents Practicals Summary
Firewall Tutorial Hyukjae Jang Nc lab, CS dept, Kaist.
Le firewall Technofutur. Table des matières Schémas du réseau Routage sans VPN Routage avec VPN Le NAT Le firewall.
© 2006 Cisco Systems, Inc. All rights reserved.Cisco PublicITE I Chapter 6 1 Filtering Traffic Using Access Control Lists Introducing Routing and Switching.
© 2006 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 Filtering Traffic Using Access Control Lists Introducing Routing and Switching.
CSN09101 Networked Services Week 6 : Firewalls + Security Module Leader: Dr Gordon Russell Lecturers: G. Russell.
Network Configuration in Linux
1 Network Address Translation (NAT) and Dynamic Host Configuration Protocol (DHCP) Relates to Lab 7. Module about private networks and NAT.
ECE Prof. John A. Copeland fax Office: GCATT Bldg.
1 Firewalls. ECE Internetwork Security 2 Overview Background General Firewall setup Iptables Introduction Iptables commands “Limit” Function Explanation.
Unit - III. Providing a Caching Proxy Server (1) A caching proxy server is software that stores (caches) frequently requested internet objects such as.
Firewall C. Edward Chow CS691 – Chapter 26.3 of Matt Bishop Linux Iptables Tutorial by Oskar Andreasson.
Introduction to Linux Firewall
Firewalls Chien-Chung Shen The Need for Firewalls Internet connectivity is essential –however it creates a threat (from the network) vs.
LINUX® Netfilter The Linux Firewall Engine. Overview LINUX® Netfilter is a firewall engine built into the Linux kernel Sometimes called “iptables” for.
1 CNLab/University of Ulsan Chapter 19 Firewalls  Packet Filtering Firewall  Application Gateway Firewall  Firewall Architecture.
Linux Firewall Iptables.
Routing with Linux 'cause you really love the command line
Netfilter Framework Jimit Mahadevia Nishit Shah This work is licensed under a Creative Commons Attribution-Share.
Basic Linux Desktop Security © Konrad Rosenbaum this presentation is protected by the GNU General Public License version 2 or any newer.
Firewalls. A Firewall is: a) Device that interconnects two networks b) Network device that regulates the access to an internal network c) Program that.

Network and System Security Risk Assessment
Firewalls Dr. X (Derived from slides by Prof. William Enck, NCSU)
FIREWALL configuration in linux
Firewalls.
Network Address Translation (NAT)
The Linux Operating System
ECE 544: Middlebox lab Abhigyan Sharma.
or call for office visit, or call Kathy Cheek,
Mateti/PacketFilters
Network Address Translation (NAT)
Packet Filtering Dick Steflik.
CIT 480: Securing Computer Systems
Chapter 4: Access Control Lists (ACLs)
Setting Up Firewall using Netfilter and Iptables
OPS235: Configuring a Network Using Virtual Machines – Part 2
Firewalls By conventional definition, a firewall is a partition made
From ACCEPT to MASQUERADE Tim(othy) Clark (eclipse)
Firewalls.
Presentation transcript:

Firewalling With Netfilter/Iptables

What Is Netfilter/Iptables? Improved successor to ipchains available in linux kernel 2.4/2.6. Netfilter is a set of kernel hooks for allowing kernel modules to register callbacks with the network stack. Iptables is the generic structure for the definition of rulesets. Provides connection tracking as well as NAT/IP Masquerading

What can be done with it? Stateful(ipV4 only)/Stateless packet filtering Connection Tracking NAT and NAPT QoS routing (not handled directly w/iptables, but using packet marking through netfilter) Packet Mangling (alteration of headers, etc)

Enabling Options in the Kernel Networking-> Networking Options-> Network packet filtering (replaces ipchains) ---> IP: Netfilter Configuration ---> It is safe to enable all modules, I recommend compiling the ftp and other connection tracking modules as modules and not into the kernel so that you can verify they are loaded and functioning.

Rule Structure Append or Delete Rule: iptables [-t table] -[AD] chain rule-specification [options] Insert New Rule: iptables [-t table] -I chain [rulenum] rule-specification [options] Replace Rule: iptables [-t table] -R chain rulenum rule-specification [options] Delete Rule: iptables [-t table] -D chain rulenum [options] List Rules, Flush Rules, Zero counters: iptables [-t table] -[LFZ] [chain] [options] New Chain iptables [-t table] -N chain Delete Chain: iptables [-t table] -X [chain] Set Chain Policy (Accept, Drop): iptables [-t table] -P chain target [options] Rename Chain: iptables [-t table] -E old-chain-name new-chain-name

Simple Example Scenario: Personal Firewall that should allow all outbound connections and restrict all inbound traffic to just an SSH server running on port 22.

Simple Example Initial Rules: # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination

Simple Example Lets add the rule to allow incoming tcp connections on 22: # iptables -I INPUT -p tcp --dport 22 -j ACCEPT # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:ssh Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination

Simple Example Lets add a rule to allow incoming connections from ourself (on the loopback interface only – outside interface could be spoofed). # iptables -I INPUT -i lo -j ACCEPT # iptables –A INPUT –i eth0 –s localhost –j DROP # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere DROP all -- localhost anywhere ACCEPT tcp -- anywhere anywhere tcp dpt:ssh Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination

Simple Example Lets add a rule to allow incoming connections on any port if it is already established or related to an established connection. # iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere tcp dpt:ssh Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination

Simple Example Now lets add a rule to log all packets before we drop them: # iptables -A INPUT -j LOG --log-level debug --log-prefix "IPTABLES: DROPPED" # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere tcp dpt:ssh LOG all -- anywhere anywhere LOG level debug prefix `IPTABLES: DROPPED' Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination

Simple Example Now our drop rule, we have a choice here we can either drop the packet (black holes it) or we can reject the packet, which sends a response to the sender. My preference is to drop the packet, as it can signify that there is no host attached to the address, but it can interfere with programs that rely on a reject.

Simple Example # iptables -A INPUT -j DROP # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere tcp dpt:ssh LOG all -- anywhere anywhere LOG level debug prefix `IPTABLES: DROPPED' DROP all -- anywhere anywhere Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination

Simple Example Now to view our rules in the form we entered them: # iptables-save # Generated by iptables-save v1.3.3 on Fri Oct 14 13:40: *nat :PREROUTING ACCEPT [ : ] :POSTROUTING ACCEPT [ : ] :OUTPUT ACCEPT [ : ] COMMIT # Completed on Fri Oct 14 13:40: # Generated by iptables-save v1.3.3 on Fri Oct 14 13:40: *mangle :PREROUTING ACCEPT [ : ] :INPUT ACCEPT [ : ] :FORWARD ACCEPT [749:162783] :OUTPUT ACCEPT [ : ] :POSTROUTING ACCEPT [ : ] COMMIT # Completed on Fri Oct 14 13:40: # Generated by iptables-save v1.3.3 on Fri Oct 14 13:40: *filter :INPUT ACCEPT [3736:606637] :FORWARD ACCEPT [749:162783] :OUTPUT ACCEPT [ : ] :SSHD - [0:0] -A INPUT -i lo -j ACCEPT -A INPUT –i eth0 –s localhost –j DROP -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -j LOG --log-prefix "IPTABLES: DROPPED" --log-level 7 -A INPUT -j DROP COMMIT # Completed on Fri Oct 14 13:40:

Something More Complex When creating a more involved firewall ruleset, it is a good idea to write down all the functionality that you require before starting. Make sure that you identify all services, their ports, and the address that need access.

Something More Complex Scenario: Linux machine will function as router, 2 separate subnets. Eth0 is the WAN interface, Eth1 connects to subnet /24, Eth2 connects to subnet /24. We wish to provide NAT to the two subnets, both subnets should be able to freely communicate with each other and the server. The server will be running an http server on ports 80 and 443, an ssh server on port 22. We will be running an ftp server on the router, port 21, that will require passive ftp access (no SSL) and active ftp access. Port 8080 needs to be forwarded to machine for a web program.

Something More Complex iptables -I INPUT -s localhost -i eth0 -j DROP iptables -A INPUT -m tcp -m match multiport --dport 22,21,80,443 -j ACCEPT iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -i eth0 -p udp -m udp mulitports --dports 57,63 -j REJECT --reject-with icmp- port-unreachable iptables -A INPUT -i eth0 -p tcp -s 0/0 --sport 1024: dport 1024: m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -i eth0 -p icmp -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -j LOG --log-prefix "[INPUT DROPPED]:" --log-level debug iptables -I FORWARD -d /24 -i eth2 -j ACCEPT iptables -A FORWARD -d /24 -i eth1 -j ACCEPT iptables -A FORWARD -s /24 -i eth1 -j ACCEPT iptables -A FORWARD -s /24 -i eth2 -j ACCEPT iptables -A FORWARD -j LOG --log-prefix "[FORWARD DROPPED]:" --log-level debug iptables -P FORWARD DROP iptables -t nat -I POSTROUTING -o eth2 -j MASQUERADE iptables -t nat -I POSTROUTING -o eth1 -j MASQUERADE iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE iptables -t nat -I PREROUTING -i eth0 -p tcp -m tcp --dport j DNAT --to-destination

Your Own Your Own Now! Netfilter Homepage GUIs: Firewall Builder Knetfilter (KDE application) Other Tools: Firewalk