Archive

Archive for 2008k2008 Otsaila 13

Proxy Gardena

2008k2008 Otsaila 13 irakasleibiltaria Utzi zure iruzkina

Helburua proxy firewall bat jartzea da:

| 10.14.4.0/22 |———-|eth1 (PROXY) eth0|——–| ROUTER |—— INTERNET

Barne sarea: 10.14.4.0/22

Proxy:

  • eth0: 10.14.7.253/26 (maskara honekin Routerra bakarrik ikusiko du)
  • eth1: 10.14.5.31/22 (Barne sareko edozein izan daiteke)

Router: 10.14.7.254

Pausoak:

1. Sistema eragilea instalatu. Debian NetInst

2. Sistema eguneratu:

  • /etc/sources.list aldatu, CDROM-eko lerroa partxeatuz
  • apt-get uptade
  • apt-get dist-upgrade
    (informazio geio, BULMA)

3. SSH Zerbitzua instalatu:

  • apt-get install openssh-server

4. Sarea konfiguratu:

  • /etc/network/interfaces:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 10.14.7.253
netmask 255.255.255.252
gateway 10.14.7.254

auto eth1
iface eth1 inet static
address 10.14.5.31
netmask 255.255.252.0

  • /etc/init.d/networking restart

[hemendik aurrera, proxyra ssh bidez sartu gaitezke 10.14.7.253 ipa erabiliz]

5. Squid instalatu:

  • apt-get install squid
  • Instalatua amaitzean martxan jartzen saiatzen da. Gure PC-aren izena egokia ez bada (izena.domeinua) errorea emango du. Hau aldatzeko /etc/hostname fitxategia editatu, adibidez:

proxy proxy.localdomain

squid.conf fitxategia izugarri handia da eta gainera aukera gehienak komentatuta ditu. Azpiko aginduaren bidez komentario eta lero hutsak kendu daitezke. Oso erabilgarria:

# cat /etc/squid/squid.conf | sed '/^#/d; /^$/d'
(azalpena: /^#/ #-z asten den lerroa eta /^$/ lerro hutsa. 'd'-k delete esan nahi du)

hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
access_log /var/log/squid/access.log squid
hosts_file /etc/hosts
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl purge method PURGE
acl CONNECT method CONNECT
acl barne_sarea src 10.14.5.1-10.14.5.254
acl debekatutako_URLak url_regex youtube.com
http_access deny debekatutako_URLak
http_access allow barne_sarea
http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all

cache_effective_user erabiltzailea
cache_effective_group erabiltzailea

#oharra: erabiltzaile sistemako erabiltzaile bat izango da. kasu #batzutan proxy erabiltzailea sortzen da

coredump_dir /var/spool/squid
visible_hostname localhost.localdomain
http_port 3128 transparent

  • /etc/init.d/squid restart

6. IPTABLES erregelak jarri:

#!/bin/sh
# ————————————————————————————
# See URL: http://www.cyberciti.biz/tips/linux-setup-transparent-proxy-squid-howto.html
# (c) 2006, nixCraft under GNU/GPL v2.0+
# ————————————————————————————-
# squid server IP
SQUID_SERVER=”10.14.5.31″
# Interface connected to Internet
INTERNET=”eth0″
# Interface connected to LAN
LAN_IN=”eth1″
# Squid port
SQUID_PORT=”3128″

# DO NOT MODIFY BELOW
# Clean old firewall
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
# Load IPTABLES modules for NAT and IP conntrack support
modprobe ip_conntrack
modprobe ip_conntrack_ftp
# For win xp ftp client
#modprobe ip_nat_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i $INTERNET -m state –state ESTABLISHED,RELATED -j ACCEPT
# set this system as a router for Rest of LAN
iptables –table nat –append POSTROUTING –out-interface $INTERNET -j MASQUERADE
iptables –append FORWARD –in-interface $LAN_IN -j ACCEPT
# unlimited access to LAN
iptables -A INPUT -i $LAN_IN -j ACCEPT
iptables -A OUTPUT -o $LAN_IN -j ACCEPT
# DNAT port 80 request comming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp –dport 80 -j DNAT –to $SQUID_SERVER:$SQUID_PORT
# if it is same system
iptables -t nat -A PREROUTING -i $INTERNET -p tcp –dport 80 -j REDIRECT –to-port $SQUID_PORT
# DROP everything and Log it
#iptables -A INPUT -j LOG
iptables -A INPUT -j DROP

  • Erregele hauek proxy-gardena izeneko fitxategian gorde eta
  • # chown root:root proxy-gardena
  • # chmod 755 proxy-gardena
  • # mv proxy-gardena /etc/init.d/
  • # cd /etc/rc2.d/
  • # ln -s /etc/init.d/proxy-gardena S20proxy-gardena

Modu honetara sistema hasieratzen denean iptables erregelak ejekutatuko dira eta 80 portura doazen eskaerak Proxy-tik pasako ditugu.

Monitorizazioa

Interesgarria izan daiteke iptraf tresna instalatzea. Modu honetan trafiko guztia monitorizatu dezakegu.

  • # apt-get install iptraf

Beste aukera log fitxategiak aztertzea:

  • # tail -f /vat/log/squid/access.log

Beste bat. log fitxategia HTML bat bihurtzeko

  • # cat /var/log/squid/access.log | calamaris -a -F html > squid.log.html
Categories: Uncategorized