34
iptables and apache 魏魏魏 (Jerry Wei)

iptables and apache

  • Upload
    iren

  • View
    43

  • Download
    0

Embed Size (px)

DESCRIPTION

魏凡琮 (Jerry Wei). iptables and apache. Agenda. iptables apache. iptables. What is Firewall. 用來防範未經允許的程式或使用者來存取內部資 源的軟體或硬體。. 依據封包資訊以及 ip header 的內容來進行過濾的 一種機制。. UTM (Unified Threat Management) 。. iptables. Firewall options. Commercial firewall devices. (UTM) - PowerPoint PPT Presentation

Citation preview

Page 1: iptables and apache

iptables and apache

魏凡琮 (Jerry Wei)

Page 2: iptables and apache

Agenda

iptables apache

Page 3: iptables and apache

iptables

What is Firewall 用來防範未經允許的程式或使用者來存取內部資 源的軟體或硬體。 依據封包資訊以及 ip header 的內容來進行過濾的 一種機制。 UTM (Unified Threat Management) 。

Page 4: iptables and apache

iptables

Firewall options Commercial firewall devices. (UTM) (Cisco PIX/ASA 、 Junpier SSG 、 Fortinet fortiGate...etc.)

Router (ACL list.)

Linux (tcp wrapper 、 iptables)

Software Packages. (BlackIce 、 Norton personal firewall...etc.)

Page 5: iptables and apache

iptables

Linux Firewall ipfwadm (kernel 2.0.X)

ipchains (kernel 2.2.X)

iptables (kernel 2.4.X)

Page 6: iptables and apache

iptables

What is iptables Integration with Linux kernel (netfilter).

Stateful packet inspection.

Filter packets according to TCP header and MAC address. Network address translation (NAT).

A rate limit feature.

Page 7: iptables and apache

iptables

iptables rule table Filter : packet filter.(FORWARD 、 INPUT 、 OUTPUT)

NAT : network address translation.(PREROUTING 、 POSROUTING 、 OUPUT)

Managle : TCP header modification.(PREROUTING 、 POSTROUTING 、 OUTPUT 、 INPUT 、 FORWARD)

Page 8: iptables and apache

iptables

iptables flowmangle table

PREROUTINGnat table

PREROUTING routing

Data for the firewall?

mangle tableFORWARD

filter tableFORWARD

mangle tablePOSTROUTI

NG

nat tablePOSTROUTI

NG

mangle tableINPUT

filter tableINPUT

Local processing

Of dataroutingmangle table

OUPUT

nat tableOUTPUT

filter tablePOSTROUTIN

G

mangle tablePOSTROUTIN

G

nat tablePOSTROUTIN

G

Page 9: iptables and apache

iptables

Tagets and Jumps ACCPET

DROP

REJECT

LOG

Page 10: iptables and apache

iptables

Tagets and Jumps DNAT

SNAT

MASQUERADE

Page 11: iptables and apache

iptables

Command options 1 -t [table]

-j [target]

-A : Append rule to end of chain.

-F : Flush. Deletes all the rules in the selected table.

-D : Delete rule from the selected table.

Page 12: iptables and apache

iptables

Command options 1 -p [protocol type] : match protocol. tcp 、 udp 、 icmp 、 all. -s [ip address] : match source ip address.

-d [ip address] : match destination ip address.

-i [interface] : match“INPUT“ interface on which the packet enters. -o [interface] : match“OUTPUT“ interface on which the packet exits.

Page 13: iptables and apache

iptables

Example1-1 iptables -A INPUT -i eth0 -p icmp -s 0/0 -d 0/0 -j DROP

iptables -L --line-numbers

iptables -A OUTPUT -o eth0 -p icmp -s 0/0 -d 0/0 -j DROP iptables -F

iptables -P INPUT DROP 、 iptables -P OUTPUT DROP

Page 14: iptables and apache

iptables

Example1-2 iptables -A INPUT -i eth0 -p icmp -s 0/0 -d 0/0 -j REJECT

iptables -I INPUT -i eth0 -p icmp -s 0/0 -d 0/0 -j LOG

iptables -I INPUT -i eth0 -p icmp -s 0/0 -d 0/0 -j ACCEPT

Page 15: iptables and apache

iptables

Command options 2 -p tcp --sport {[port] | [start-port:end-port] } -p tcp --dport {[port] | [start-port:end-port] } -p tcp { --syn | !--sync } -p udp --sport {[port] | [start-port:end-port] } -p udp --dport {[port] | [start-port:end-port] } -p icmp --icmp-type [type]

Page 16: iptables and apache

iptables

Example2-1 iptables -A OUTPUT -o eth0 -p tcp --sport 1024:65535 --dport 80 -j DROP iptables -A OUTPUT -o eth0 -p udp --dport 53 -j ACCEPT

iptables -A INPUT -i eth0 -p icmp --icmp-type echo-request -j DROP iptables -A OUTPUT -o eth0 -p icmp --icmp-type echo-reply -j DROP

Page 17: iptables and apache

iptables

Command options 3 -m multiport --sports [port1,port2,port3] -m multiport --dports [port1,port2,port3] -m multiport --ports [port1,port2,port3] -m state --state [NEW | ESTABLISHED | RELATED | INVALID] -m limit --limit [rate] -m limit --limit-burst

Page 18: iptables and apache

iptables

Example3-1 iptables -A OUTPUT -o eth0 -p tcp -m multiport --dports 53,80 -j DROP iptables -A OUTPUT -o eth0 -s 0/0 -d 0/0 -p tcp -m state --state ESTABLISHED -j ACCEPT iptables -A INPUT -i eth0 -p icmp -m limit --limit 1/s -j ACCEPT iptables -A INPUT -i eth0 -p icmp -m limit --limit-burst 2 -j ACCEPT

Page 19: iptables and apache

iptables

NAT DNAT / IP mapping / Port forwarding

SNAT / MASQUERADE

Page 20: iptables and apache

iptables

DNAT Port forwarding.

IP mapping

Page 21: iptables and apache

iptables

SNAT SNAT.

MASQUERADE

ip_forward

Page 22: iptables and apache

iptables

Example4-1 iptables -t nat -A PREROUTING -p tcp -d 192.168.254.17 --dport 2222 -j DNAT --to 192.168.254.17:22 iptables -t nat -A PREROUTING -i eth0 -d 192.168.254.17 -j DNAT --to-destination 10.20.1.2 iptables -t nat -A POSTROUTING -o eth0 -s 10.20.1.2 -j SNAT --to-source 192.168.254.17 iptables -t nat -A POSTROUTING -o eth0 -s 10.20.1.0/24 -j SNAT --to-source 192.168.254.17

Page 23: iptables and apache

iptables

Example4-2 iptables -t nat -A POSTROUTING -o eth0 -s 10.20.1.0/24 -j SNAT --to-source 192.168.254.17 iptables -t nat -A POSTROUTING -o eth0 -s 10.20.1.0/24 -j MASQUERADE

Page 24: iptables and apache

iptables

Mangle MARK

TOS (IPV4 : Type Of Service) (IPV6 : set Traffic Control Value)

TTL

Page 25: iptables and apache

iptables

Example5-1 iptables -t mangle -A POSTROUTING -o eth0 -j TTL --ttl-set 1

Page 26: iptables and apache

iptables

Save and Restore iptables-save

iptables-restore

rc.local

Page 27: iptables and apache

Q & A

休息一下 !

Page 28: iptables and apache

apache

Install wget “source tarball file”

./configure –prefix=/usr/local/apache-version --enable-rewrite make

make install

./bin/apachectl { start | stop | restart }

Page 29: iptables and apache

apache

Configuration httpd.conf

Virtual host

.htaccess

mod_rewrite

Page 30: iptables and apache

apache

VirtualHost Include vhosts.conf

Page 31: iptables and apache

apache

.htaccess Access control.

./htpasswd -c /usr/local/apache/conf/users csie

User & group

./conf/groups

Page 32: iptables and apache

apache

.htaccess AuthName “Admin Login” AuthUserFile “/usr/local/apache/conf/users” AuthType Basic require valid-user

AuthGroupFile “/usr/local/apache/conf/groups” require group

Page 33: iptables and apache

apache

mod_rewrite Provides a rule-based rewriting engineto rewrite request URLs. --enable-rewrite

[NC] (no case) 、 [L] (last rule) 、 [R] (redirect)

RewriteRule

RewriteCond [OR] (or next)

Page 34: iptables and apache

Q & A

謝謝 !