Re: linux - iptable firewall DNS question

From: Baptiste Pillot (baptiste.pillot_at_atgp.net)
Date: 10/22/03


Date: Wed, 22 Oct 2003 20:51:16 +0200

Do you have a concrete example to give to me ? I did not understand all the
aspects of iptables and some iptables lines will probably guide me...

"Joe Beasley" <jbeasley@xyz123.com> a écrit dans le message de
news:4LAkb.182416$%h1.172016@sccrnsc02...
> You need a rule for udp on port 53 for DNS.
>
> If your default output policy is DROP, you will need a rule on the
> output chain also.
>
> Baptiste Pillot wrote:
> > A unsolvable problem for me :
> >
> > When my firewall is active, i am unable to use name solving features
from my
> > firewall computer.
> > For example ping www.yahoo.com does not resolve the domaine name.
> >
> > with this script, name solving works :
> >
> > iptables -F
> > iptables -X
> > iptables -P INPUT ACCEPT
> > iptables -P OUTPUT ACCEPT
> > iptables -P FORWARD ACCEPT
> >
> > when I mage a drop, and a lot of opennings, it does not work. here is my
> > complete firewall script (sorry for its length) :
> >
> >
> > #!/bin/sh
> > # interfaces
> > #------------
> > # $ethmod -> modem adsl
> > # $ethloc -> local network
> > # $ethdmz -> DMZ
> > # $ethnet -> INTERNET
> > ethmod=eth2
> > ethloc=eth1
> > ethdmz=eth0
> > ethnet=ppp+
> > ethlo=lo
> > # adresses ip
> > #-------------
> > # $ipmod -> adresse ip de l'interface connectée au modem adsl
> > # $iploc -> adresse ip de l'interface connectée au réseau local
> > # $ipdmz -> adresse ip de l'interface connectée à la DMZ
> > # $ipnet -> adresse ip de l'interface connectée à internet
> > ipmod=10.0.0.10
> > iploc=192.168.0.254
> > ipdmz=192.168.0.254
> > ipnet=`ifconfig | grep P-t-P | cut -b 20- | cut -d " " -f 1`
> > # adresses ip serveurs locaux
> > #-----------------------------
> > # $ethweb -> interface réseau où se trouve le serveur web
> > # $ipweb -> adresse ip du serveur web
> > ethweb=$ethdmz
> > ipweb=192.168.0.28
> > #
> >
============================================================================
> > ==============
> > # PREPARATION
> > echo PREPARATION
> > # activation du forwarding
> > echo 1 > /proc/sys/net/ipv4/ip_forward
> > # je ne veux pas de spoofing
> > if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]
> > then
> > for filtre in /proc/sys/net/ipv4/conf/*/rp_filter
> > do
> > echo 1 > $filtre
> > done
> > fi
> > # pas de icmp
> > echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
> > echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
> > # chargement du module ip_tables
> > modprobe ip_tables
> > modprobe ip_nat_ftp
> > modprobe ip_nat_irc
> > modprobe iptable_filter
> > modprobe iptable_nat
> > # (BP)
> > # modprobe ip_conntrack_ftp
> > # vider toutes les règles
> > iptables -F
> > iptables -X
> > # deux nouvelles chaînes pour le log
> > iptables -N LOG_DROP
> > iptables -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP] : '
> > iptables -A LOG_DROP -j DROP
> > iptables -N LOG_ACCEPT
> > iptables -A LOG_ACCEPT -j LOG --log-prefix '[IPTABLES ACCEPT] : '
> > iptables -A LOG_ACCEPT -j ACCEPT
> > # on bloque tout
> > iptables -P INPUT DROP
> > iptables -P OUTPUT DROP
> > iptables -P FORWARD DROP
> > #
> >
============================================================================
> > =================
> > # ACCES AU FIREWALL DEPUIS LOCAL
> > echo ACCES AU FIREWALL DEPUIS LOCAL
> > # on accepte tout sur la machine en local
> > iptables -A INPUT -i $ethlo -j ACCEPT
> > iptables -A OUTPUT -o $ethlo -j ACCEPT
> > iptables -A FORWARD -i $ethlo -j ACCEPT
> > iptables -A FORWARD -o $ethlo -j ACCEPT
> > # on accepte toutes les connexions depuis le réseau local
> > iptables -A INPUT -i $ethloc -p tcp -m state --state NEW,ESTABLISHED -j
> > LOG_ACCEPT
> > iptables -A OUTPUT -o $ethloc -p tcp -m state --state ESTABLISHED -j
> > LOG_ACCEPT
> > # on accepte toutes les connexions depuis la DMZ
> > iptables -A INPUT -i $ethdmz -p tcp -m state --state NEW,ESTABLISHED -j
> > LOG_ACCEPT
> > iptables -A OUTPUT -o $ethdmz -p tcp -m state --state ESTABLISHED -j
> > LOG_ACCEPT
> > # on accepte particulièrement ssh depuis le réseau local
> > iptables -A INPUT -i $ethloc -p tcp --dport 22 -m state --state
> > NEW,ESTABLISHED -j LOG_ACCEPT
> > iptables -A OUTPUT -o $ethloc -p tcp --sport 22 -m state --state
> > ESTABLISHED -j LOG_ACCEPT
> > # on accepte particulièrement ssh depuis la DMZ
> > iptables -A INPUT -i $ethdmz -p tcp --dport 22 -m state --state
> > NEW,ESTABLISHED -j LOG_ACCEPT
> > iptables -A OUTPUT -o $ethdmz -p tcp --sport 22 -m state --state
> > ESTABLISHED -j LOG_ACCEPT
> > #
> >
============================================================================
> > =================
> > # ACCES AU FIREWALL DEPUIS INTERNET
> > echo ACCES AU FIREWALL DEPUIS INTERNET
> > # on accepte le serveur web depuis internet
> > iptables -A INPUT -i $ethnet -p tcp --dport 80 -m state --state
> > NEW,ESTABLISHED -j LOG_ACCEPT
> > iptables -A OUTPUT -o $ethnet -p tcp --sport 80 -m state --state
> > NEW,ESTABLISHED -j LOG_ACCEPT
> > #
> >
============================================================================
> > =================
> > # ACCES AU DMZ
> > echo ACCES AU DMZ
> > # DMZ Serveur de news jana depuis réseau local et internet
> > iptables -A PREROUTING -t nat -p tcp -d $iploc --dport 119 -j DNAT --to
> > $ipweb:119
> > iptables -A FORWARD -i $ethnet -o $ethweb -p tcp --destination-port
119 -m
> > state --state NEW,ESTABLISHED -j ACCEPT
> > iptables -A FORWARD -o $ethnet -i $ethweb -p tcp --source-port 119 -m
> > state --state ESTABLISHED -j ACCEPT
> > iptables -A FORWARD -i $ethloc -o $ethweb -p tcp --destination-port
119 -m
> > state --state NEW,ESTABLISHED -j ACCEPT
> > iptables -A FORWARD -o $ethloc -i $ethweb -p tcp --source-port 119 -m
> > state --state ESTABLISHED -j ACCEPT
> > # DMZ Webcam (bpillot28)
> > iptables -A PREROUTING -t nat -p tcp -d $ipnet --dport 8080 -j DNAT --to
> > $ipweb:8080
> > iptables -A FORWARD -i $ethnet -o $ethweb -p tcp --destination-port
8080 -m
> > state --state NEW,ESTABLISHED -j ACCEPT
> > iptables -A FORWARD -o $ethnet -i $ethweb -p tcp --source-port 8080 -m
> > state --state ESTABLISHED -j ACCEPT
> > # DMZ PC Anywhere depuis internet
> > # iptables -A PREROUTING -t nat -p tcp -d $ipnet --dport 50631 -j
DNAT --to
> > 192.168.0.1:5631
> > # iptables -A FORWARD -i $ethnet -o $ethloc -p tcp --destination-port
> > 5631 -m state --state NEW,ESTABLISHED -j ACCEPT
> > # iptables -A FORWARD -o $ethnet -i $ethloc -p tcp --source-port 5631 -m
> > state --state ESTABLISHED -j ACCEPT
> > # iptables -A PREROUTING -t nat -p tcp -d $ipnet --dport 50632 -j
DNAT --to
> > 192.168.0.1:5632
> > # iptables -A FORWARD -i $ethnet -o $ethloc -p tcp --destination-port
> > 5632 -m state --state NEW,ESTABLISHED -j ACCEPT
> > # iptables -A FORWARD -o $ethnet -i $ethloc -p tcp --source-port 5632 -m
> > state --state ESTABLISHED -j ACCEPT
> > # DMZ Serveur Web depuis internet
> > # iptables -A PREROUTING -t nat -p tcp -d $ipnet --dport 80 -j DNAT --to
> > $ipweb:80
> > # iptables -A FORWARD -i $ethnet -o $ethweb -p tcp --destination-port
80 -m
> > state --state NEW,ESTABLISHED -j ACCEPT
> > # iptables -A FORWARD -o $ethnet -i $ethweb -p tcp --source-port 80 -m
> > state --state ESTABLISHED -j ACCEPT
> > # DMZ Serveur Web depuis réseau local
> > # iptables -A PREROUTING -t nat -p tcp -d $iploc --dport 80 -j DNAT --to
> > $ipweb:80
> > # iptables -A FORWARD -i $ethloc -o $ethweb -p tcp --destination-port
80 -m
> > state --state NEW,ESTABLISHED -j ACCEPT
> > # iptables -A FORWARD -o $ethloc -i $ethweb -p tcp --destination-port
80 -m
> > state --state ESTABLISHED -j ACCEPT
> > #
> >
============================================================================
> > =================
> > # ACCES A INTERNET DEPUIS LOCAL
> > echo ACCES A INTERNET DEPUIS LOCAL
> > # le firewall a un accès complet à internet
> > iptables -A FORWARD -i $ethlo -o $ethnet -j ACCEPT
> > iptables -A FORWARD -o $ethlo -i $ethnet -j ACCEPT
> > # le LAN a un accès complet à internet
> > iptables -A FORWARD -i $ethloc -o $ethnet -j ACCEPT
> > iptables -A FORWARD -o $ethloc -i $ethnet -j ACCEPT
> > # la DMZ a un accès complet à internet
> > iptables -A FORWARD -i $ethdmz -o $ethnet -j ACCEPT
> > iptables -A FORWARD -o $ethdmz -i $ethnet -j ACCEPT
> > # le LAN et le DMZ ont un accès complet l'un avec l'autre
> > iptables -A FORWARD -i $ethloc -o $ethdmz -j ACCEPT
> > iptables -A FORWARD -o $ethloc -i $ethdmz -j ACCEPT
> > #
> >
============================================================================
> > =================
> > # CONCLUSION
> > echo CONCLUSION
> > # tous accès internet avec la même ip (y compris DMZ)
> > iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o $ethnet -j
MASQUERADE
> > iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o $ethnet -j
MASQUERADE
> > # bloquage des règles refusées par firewall
> > iptables -A FORWARD -j LOG_DROP
> > iptables -A INPUT -j LOG_DROP
> > iptables -A OUTPUT -j LOG_DROP
> > # fini
> > echo " [termine]"
> >
> >
>