[Linuxtrent] Ipchains (lunghetto... sorry)

  • From: neugens <neugens@xxxxxxxxx>
  • To: linuxtrent@xxxxxxxxxxxxx
  • Date: Tue, 23 Apr 2002 20:11:07 +0200

Ciao!

Mi servirebbe un piccolo aiuto con ipchains...

Ho messo su queste regole, ma visto che sto imparando adesso come si usa 
ipchains, ho combinato qualche casino.

Quello che devo fare e' semplice:
Far connettere un pc interno alla rete locale, tramite gateway linux, ad 
Internet.

La situazione e' questa:

Macchina interna: Windows2k/Linux Red Hat 7.2, una ethernet,
                  chiamata orbital
Macchina esterna: Linux Red Hat 7.2, con due ethernet,
                  chiamato nirvana (si, proprio in onore del gruppo... :)

orbital e nirvana devono essere liberi di comunicare tra loro, su nirvana ho 
un web server, mysql server, server di posta e tutto il resto, non ci devono 
essere restrizioni tra nirvana e orbital.

orbital deve accedere ad internet tramite nirvana, che deve essere 
configurato per mascherare l'ip di orbital.

L'IP di rete e' 192.168.0.0, orbital ha ip 192.168.0.2, nirvana 192.168.0.1 
sulla eth1, mentre un indirizzo assegnato dal server sull'interfaccia ppp0.

nirvana deve fare in modo da mascherare gli ip, oltre che nascondere tutti i 
servizi attivi, e filtrare le richieste per orbital, in modo che non sia 
preda di attacchi (quando su orbital gira win2k...)

Il firewall che ho preparato e' riportato sotto, ma non funziona...

Per l'ip spooofing, ho settato ad uno il contenuto dei file in 
/proc/sys/net/ipv4/conf/*/rp_filter

come da manuale (ipchains how-to)

Lo script e' per ipchains, ma ovviamente, se avete regole per iptables mi 
vanno benissimo, mi interessa che funzioni, per il momento... (dopo devo 
pensare alle prestazioni) :)

scusate se e' lungo da leggere, ho tolto tutti gli spazi per non appesantirlo 
troppo, vi ringrazio anticipatamente per l'aiuto!

Mario

----------------------------------- cut ------------------------------------
#!/bin/sh
# rules to setup a simple firewall for the local network
# where is ipchains?
IPCHAINS=/sbin/ipchains
# input interface
INTIF="eth1"
# output interface
OUTIF="ppp0"
# internal network id
INTNET="192.168.0.0"
# enable ip forwarding
echo "1" > /proc/sys/net/ipv4/ip_forward
# setup the basic here, all denied except
# the traffic on the loopback interface...
$IPCHAINS -A input -i lo -j ACCEPT
$IPCHAINS -A output -i ! lo -j ACCEPT
$IPCHAINS -A forward -j DENY
# create a chain for the icmp normal traffic.
$IPCHAINS -N icmp-acc
# create chains for the internal and external NIC
$IPCHAINS -N i-input   # what the internal network can accept
$IPCHAINS -N i-output  # what the internal network can send ouside
$IPCHAINS -N o-input   # what the external network can send inside
$IPCHAINS -N o-output  # what the external network can receive
$IPCHAINS -N local     # internal network traffic
# common ICMP messages, we accept all them
$IPCHAINS -A icmp-acc -p icmp --icmp-type destination-unreachable -j ACCEPT
$IPCHAINS -A icmp-acc -p icmp --icmp-type source-quench -j ACCEPT
$IPCHAINS -A icmp-acc -p icmp --icmp-type time-exceeded -j ACCEPT
$IPCHAINS -A icmp-acc -p icmp --icmp-type parameter-problem -j ACCEPT
# forward
# set jumpers for the chains
$IPCHAINS -A forward -s $INTNET/24 -i $INTIF -j local
# traffic that goes from the local network to the outside
$IPCHAINS -A forward -s $INTNET/24 -i $OUTIF -j i-output
# traffic that goes to the internal network
$IPCHAINS -A forward -i $INTIF -j i-input
# traffic that goes inside from the Internet, very dangerous
$IPCHAINS -A forward -i $OUTIF -j o-input
# logs eveything else
$IPCHAINS -A forward -j DENY -l
# local
# local traffic is safe
$IPCHAINS -A local -s $INTNET/24 -d $INTNET/24 -j ACCEPT
# i-output
# internal interface to the world, for now accept everything
$IPCHAINS -A i-output -j ACCEPT
# i-input
$IPCHAINS -A i-input -j DENY
$IPCHAINS -A i-input -s $INTNET/24 -d $INTNET/24 -j ACCEPT
$IPCHAINS -A i-input -s 127.0.0.0/24 -d $INTNET/24 -j ACCEPT
# o-input
# just one rule: we want to stop everything
$IPCHAINS -A o-input -j DENY
# o-output
$IPCHAINS -A o-output -j ACCEPT
# now create two chains, one is for the box itself
$IPCHAINS -N bad-if  # Internet
$IPCHAINS -N good-if # local network
# set jumpers
$IPCHAINS -A input -j bad-if
$IPCHAINS -A input -i $INTIF -j good-if
# set rules
# bad-if
$IPCHAINS -A bad-if -j ACCEPT 
$IPCHAINS -A bad-if -j icmp-acc
$IPCHAINS -A bad-if -p tcp -i $OUTIF -d 0/0 0:1023 -y -j DENY
$IPCHAINS -A bad-if -p tcp -i $OUTIF -d 0/0 2049 -y -j DENY
$IPCHAINS -A bad-if -p udp -i $OUTIF -d 0/0 0:1023 -j DENY
$IPCHAINS -A bad-if -p udp -i $OUTIF -d 0/0 2049 -j DENY
$IPCHAINS -A bad-if -p tcp -i $OUTIF -d 0/0 6000:6009 -y -j DENY
$IPCHAINS -A bad-if -p tcp -i $OUTIF -d 0/0 7100 -y -j DENY
$IPCHAINS -A bad-if -p tcp -i $OUTIF -d 0/0 8100 -y -j DENY
# good-if
$IPCHAINS -A good-if -j ACCEPT
# done
-- 
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
-- 
PROSSIMA ASSEMBLEA: lunedi 29 Aprile 2002 ore 20:45
Per iscriversi  (o disiscriversi), basta spedire un  messaggio con SOGGETTO
"subscribe" (o "unsubscribe") a mailto:linuxtrent-request@xxxxxxxxxxxxxxxxx


Other related posts: