| 1 | #!/bin/sh |
|---|
| 2 | |
|---|
| 3 | # $Id:$ |
|---|
| 4 | |
|---|
| 5 | # |
|---|
| 6 | # dmz-fw.ini |
|---|
| 7 | # A typical firewall subscript. |
|---|
| 8 | # |
|---|
| 9 | # Thomas Lundquist <thomasez@zelow.no> |
|---|
| 10 | # |
|---|
| 11 | |
|---|
| 12 | # If no dmz info file, there is no use for this script. |
|---|
| 13 | |
|---|
| 14 | [ -f /etc/dmz.info ] || exit; |
|---|
| 15 | |
|---|
| 16 | . /etc/functions.inc |
|---|
| 17 | |
|---|
| 18 | . /etc/config |
|---|
| 19 | |
|---|
| 20 | . /etc/dmz.info |
|---|
| 21 | . /etc/inside.info |
|---|
| 22 | . /etc/outside.info |
|---|
| 23 | |
|---|
| 24 | echo "Setting up DMZ." |
|---|
| 25 | |
|---|
| 26 | # We will automatically accept DNS requests. |
|---|
| 27 | iptables -A INPUT -i ${DMZ_DEVICE} -p TCP --dport 53 -j ACCEPT |
|---|
| 28 | iptables -A INPUT -i ${DMZ_DEVICE} -p UDP --dport 53 -j ACCEPT |
|---|
| 29 | |
|---|
| 30 | if [ "$DMZ_DHCP_SERVER" = "y" ] |
|---|
| 31 | then |
|---|
| 32 | iptables -A INPUT -i ${DMZ_DEVICE} -p TCP --dport 67 -j ACCEPT |
|---|
| 33 | iptables -A INPUT -i ${DMZ_DEVICE} -p UDP --dport 67 -j ACCEPT |
|---|
| 34 | iptables -A INPUT -i ${DMZ_DEVICE} -p TCP --dport 68 -j ACCEPT |
|---|
| 35 | iptables -A INPUT -i ${DMZ_DEVICE} -p UDP --dport 68 -j ACCEPT |
|---|
| 36 | fi |
|---|
| 37 | |
|---|
| 38 | if [ "$DMZ_USE_NAT" = "y" ] |
|---|
| 39 | then |
|---|
| 40 | iptables -t nat -A POSTROUTING -s $DMZ_NETWORK/$DMZ_NETMASK -o $OUTSIDE_DEVICE -j MASQUERADE |
|---|
| 41 | fi |
|---|
| 42 | |
|---|
| 43 | # Open ports: |
|---|
| 44 | # The big caveat here is that multiport only supports 15 ports.. |
|---|
| 45 | # We will try to pad that by giving the admin more options.. |
|---|
| 46 | if [ -n "$DMZ_ALLOW_TO_OUTSIDE" ] |
|---|
| 47 | then |
|---|
| 48 | case "$DMZ_ALLOW_TO_OUTSIDE" in |
|---|
| 49 | all) iptables -A FORWARD -i $DMZ_DEVICE -o $OUTSIDE_DEVICE -j ACCEPT |
|---|
| 50 | ;; |
|---|
| 51 | none) echo "No ports opened to OUTSIDE from DMZ" |
|---|
| 52 | ;; |
|---|
| 53 | *) iptables -A FORWARD -p tcp -i $DMZ_DEVICE -m multiport --dports $DMZ_ALLOW_TO_OUTSIDE -o $OUTSIDE_DEVICE -j ACCEPT |
|---|
| 54 | ;; |
|---|
| 55 | esac |
|---|
| 56 | fi |
|---|
| 57 | |
|---|
| 58 | if [ -n "$DMZ_ALLOW_TO_INSIDE" ] |
|---|
| 59 | then |
|---|
| 60 | case "$DMZ_ALLOW_TO_INSIDE" in |
|---|
| 61 | all) iptables -A FORWARD -i $DMZ_DEVICE -o $INSIDE_DEVICE -j ACCEPT |
|---|
| 62 | ;; |
|---|
| 63 | none) echo "No ports opened to INSIDE from DMZ" |
|---|
| 64 | ;; |
|---|
| 65 | *) iptables -A FORWARD -p tcp -i $DMZ_DEVICE -m multiport --dports $DMZ_ALLOW_TO_INSIDE -o $INSIDE_DEVICE -j ACCEPT |
|---|
| 66 | ;; |
|---|
| 67 | esac |
|---|
| 68 | fi |
|---|
| 69 | |
|---|
| 70 | if [ -n "$DMZ_ALLOW_FROM_INSIDE" ] |
|---|
| 71 | then |
|---|
| 72 | case "$DMZ_ALLOW_FROM_INSIDE" in |
|---|
| 73 | all) iptables -A FORWARD -i $INSIDE_DEVICE -o $DMZ_DEVICE -j ACCEPT |
|---|
| 74 | ;; |
|---|
| 75 | none) echo "No ports opened to DMZ from INSIDE" |
|---|
| 76 | ;; |
|---|
| 77 | *) iptables -A FORWARD -p tcp -i $INSIDE_DEVICE -m multiport --dports $DMZ_ALLOW_FROM_INSIDE -o $DMZ_DEVICE -j ACCEPT |
|---|
| 78 | ;; |
|---|
| 79 | esac |
|---|
| 80 | fi |
|---|
| 81 | |
|---|
| 82 | # I'd better read the tc man pages and make a more tailored line instead of |
|---|
| 83 | # just copying the one from firewall.ini |
|---|
| 84 | if [ -n "$DMZ_RESTRICT_KBITS" ] |
|---|
| 85 | then |
|---|
| 86 | tc qdisc add dev $DMZ_DEVICE root tbf rate ${DMZ_RESTRICT_KBITS}kbit latency 50ms burst 1540 |
|---|
| 87 | fi |
|---|
| 88 | |
|---|