Hej gruppe.
Jeg prøver at få nedestående script til at virke men jeg må overse et
eller andet, jeg kan ikke få forbindelse til dmz inde fra lokal
netværket, kun udefra.
My script:
##############################################################################
# The network and machines
##############################################################################
### Netvaerk ###
LAN="172.16.0.0/24"
ETH_LAN="eth0"
WAN="192.168.0.199"
ETH_WAN="eth1"
DMZ="172.16.10.0/24"
ETH_DMZ="eth2"
WRL="172.16.1.0/24"
ETH_WRL="eth3"
LO="127.0.0.1/8"
ETH_LO="lo"
### Machines ###
ATLANTIS="172.16.10.10"
HERCULES="172.16.0.2"
##############################################################################
# The chains
##############################################################################
# Disable routing before rules are startet
echo > /proc/sys/net/ipv4/ip_forward
# Rules and policies flushes
echo " Flushing rules and policies"
iptables -t filter -F
iptables -t nat -F
iptables -t mangle -F
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
echo " Done...."
# making chains
echo "Making the new chains"
iptables -N lo
iptables -F lo
iptables -N lan
iptables -F lan
iptables -N wan
iptables -F wan
iptables -N dmz
iptables -F dmz
iptables -N wrl
iptables -F wrl
echo " Done...."
# Making forwardChains
echo "Making FORWARD chains"
# From WAN to other interfaces
iptables -N wantodmz
iptables -F wantodmz
iptables -N wantolan
iptables -F wantolan
iptables -N wantowrl
iptables -F wantowrl
# From LAN to other interfaces
iptables -N lantodmz
iptables -F lantodmz
iptables -N lantowan
iptables -F lantowan
iptables -N lantowrl
iptables -F lantowrl
# From DMZ to other interfaces
iptables -N dmztolan
iptables -F dmztolan
iptables -N dmztowan
iptables -F dmztowan
iptables -N dmztowrl
iptables -F dmztowrl
# From WRL to other interfaces
iptables -N wrltodmz
iptables -F wrltodmz
iptables -N wrltowan
iptables -F wrltowan
iptables -N wrltolan
iptables -F wrltolan
echo " Done...."
# Flusher NAT POSTROUTING PREROUTING
echo "Flushing NAT - POSTROUTING & PREROUTING"
iptables -t nat -F POSTROUTING
iptables -t nat -F PREROUTING
echo " Done.... NAT module finished"
# Securing local communication
echo "Setting up local chain"
iptables -A lo -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
echo " Done.... Local chain is up and running"
# Setting up lan chain
echo "Setting up LAN chain"
# Securing against IP-spoffing
iptables -A lan -s $WAN -j DROP
iptables -A lan -s $LO -j DROP
iptables -A lan -s $DMZ -j DROP
iptables -A lan -s $WRL -j DROP
iptables -A lan -s $LAN -j DROP
# Accept all other trafic
iptables -A lan -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A lan -j LOG --log-prefix "FW LAN:"
iptables -A lan -j DROP
echo " Done....LAN chain is running"
# Setting up WAN chain
echo "Setting up WAN chain"
# Securing against IP-spoffing
iptables -A wan -s $WAN -j DROP
iptables -A wan -s $DMZ -j DROP
iptables -A wan -s $LAN -j DROP
iptables -A wan -s $LO -j DROP
iptables -A wan -s $WRL -j DROP
# Accept all other trafic
iptables -A wan -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A wan -j LOG --log-prefix "FW WAN:"
iptables -A wan -j DROP
echo " Done....WAN chain is running"
# Setting up DMZ chain
echo "Setting up DMZ chain"
# Securing against IP-spoffing
iptables -A dmz -s $WAN -j DROP
iptables -A dmz -s $LAN -j DROP
iptables -A dmz -s $WRL -j DROP
iptables -A dmz -s $LO -j DROP
iptables -A dmz -s $DMZ -j DROP
# Accept all other trafic
iptables -A dmz -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A dmz -j LOG --log-prefix "FW DMZ:"
iptables -A dmz -j DROP
echo " Done....DMZ chain is running"
# Setting up WRL chain
echo "Setting up WRL chain"
# Securing against IP-spoffing
iptables -A wrl -s $WAN -j DROP
iptables -A wrl -s $LO -j DROP
iptables -A wrl -s $LAN -j DROP
iptables -A wrl -s $DMZ -j DROP
iptables -A wrl -s $WRL -j DROP
# Accept all other trafic
iptables -A wrl -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A wrl -j LOG --log-prefix "FW WRL:"
iptables -A wrl -j DROP
echo " Done....WRL chain is running"
##############################################################################
# Firewall rules
##############################################################################
echo "Setting up DMZ portfarwarding"
# SSH
iptables -t nat -A PREROUTING -i $ETH_WAN -d $WAN -p tcp --dport 22 -j DNAT
--to-destination $ATANLTIS:22
iptables -A wantodmz -d $ATLANTIS -p tcp --dport 22 -j ACCEPT
# SMTP
iptables -t nat -A PREROUTING -i $ETH_WAN -d $WAN -p tcp --dport 25 -j DNAT
--to-destination $ATLANTIS:25
iptables -A wantodmz -d $ATLANTIS -p tcp --dport 25 -j ACCEPT
# HTTP
iptables -t nat -A PREROUTING -i $ETH_WAN -d $WAN -p tcp --dport 80 -j DNAT
--to-destination $ATLANTIS:80
iptables -A wantodmz -d $ATLANTIS -p tcp --dport 80 -j ACCEPT
# IMAP
iptables -t nat -A PREROUTING -i $ETH_WAN -d $WAN -p tcp --dport 143 -j DNAT
--to-destination $ATALNTIS:143
iptables -A wantodmz -d $ATLANTIS -p tcp --dport 143 -j ACCEPT
echo " Done.... DMZ portforwarding is up and running"
# Setting up hide NAT
echo "Setting up masquerading - NAT chains"
# NAT from LAN to WAN
iptables -t nat -A POSTROUTING -s $LAN -o $ETH_WAN -j SNAT --to-source $WAN
iptables -t nat -A POSTROUTING -s $DMZ -o $ETH_WAN -j SNAT --to-source $WAN
iptables -t nat -A POSTROUTING -s $WRL -o $ETH_WAN -j SNAT --to-source $WAN
echo " Done....NAT chains are up and running
echo "Setting up the rules"
# Packets from DMZ to WAN
iptables -A dmztowan --source $ATLANTIS -p tcp --dport 25 -j ACCEPT
iptables -A dmztowan -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A dmztowan -j LOG --log-prefix "FW DMZTOWAN:"
iptables -A dmztowan -j DROP
# Packets from WAN to DMZ
iptables -A wantodmz -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A wantodmz -j LOG --log-prefix "FW WANTODMZ:"
iptables -A wantodmz -j DROP
# packets from DMZ to LAN
iptables -A dmztolan --source $WAN -d $LAN -p tcp --dport 25 -j ACCEPT
iptables -A dmztolan -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A dmztolan -j LOG --log-prefix "FW DMZTOLAN:"
iptables -A dmztolan -j DROP
# packets from LAN to DMZ
iptables -A lantodmz -s $LAN -d $DMZ -p tcp --dport 80 -j ACCEPT
iptables -A lantodmz -s $LAN -d $DMZ -p tcp --dport 22 -j ACCEPT
iptables -A lantodmz -s $LAN -d $DMZ -p tcp --dport 25 -j ACCEPT
iptables -A lantodmz -s $LAN -d $DMZ -p tcp --dport 143 -j ACCEPT
# Logning af trafik
iptables -A lantodmz -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A lantodmz -j LOG --log-prefix "FW LANTODMZ:"
iptables -A lantodmz -j DROP
# Packets FROM WRL to DMZ
iptables -A wrltodmz -s $WRL -d $DMZ -p tcp --dport 80 -j ACCEPT
iptables -A wrltodmz -s $WRL -d $DMZ -p tcp --dport 22 -j ACCEPT
iptables -A wrltodmz -s $WRL -d $DMZ -p tcp --dport 25 -j ACCEPT
iptables -A wrltodmz -s $WRL -d $DMZ -p tcp --dport 143 -j ACCEPT
# Logning af trafik
iptables -A wrltodmz -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A wrltodmz -j LOG --log-prefix "FW WRLTODMZ:"
iptables -A wrltodmz -j DROP
# Packets from LAN to WAN
iptables -A lantowan -s $LAN -p tcp --dport 80 -j ACCEPT
iptables -A lantowan -s $LAN -p tcp --dport 443 -j ACCEPT
iptables -A lantowan -s $LAN -p tcp --dport 21 -j ACCEPT
iptables -A lantowan -s $LAN -p tcp --dport 22 -j ACCEPT
# Allowing connection to Alladin from LAN
#iptables -A lantowan -s $LAN -d $ALADIN -p tcp --dport 22 -j ACCEPT
iptables -A lantowan -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A lantowan -j LOG --log-prefix "FW LANTOWAN:"
iptables -A lantowan -j DROP
# Packets from WAN to LAN
iptables -A wantolan -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A wantolan -j LOG --log-prefix "FW WANTOLAN PORTFWD:"
iptables -A wantolan -j DROP
# Packets from WRL to WAN
iptables -A wrltowan -s $WRL -p tcp --dport 80 -j ACCEPT
iptables -A wrltowan -s $WRL -p tcp --dport 443 -j ACCEPT
iptables -A wrltowan -s $WRL -p tcp --dport 21 -j ACCEPT
iptables -A wrltowan -s $WRL -p tcp --dport 22 -j ACCEPT
# Allowing connection to Alladin from LAN
#iptables -A wrltowan -s $WRL -d $ALADIN -p tcp --dport 22 -j ACCEPT
iptables -A wrltowan -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A wrltowan -j LOG --log-prefix "FW WRLTOWAN:"
iptables -A wrltowan -j DROP
# Packets from WAN to WRL
iptables -A wantowrl -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A wantowrl -j LOG --log-prefix "FW WANTOWRL PORTFWD:"
iptables -A wantowrl -j DROP
echo " Done....Firewall rules is up and running"
# Loading the different modules
echo "Loading the modules"
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_conntrack_ftp
echo " Done...."
# Activating the chains
echo "Activating the chains"
iptables -A INPUT -i $ETH_LAN -j lan
iptables -A INPUT -i $ETH_WAN -j wan
iptables -A INPUT -i $ETH_DMZ -j dmz
iptables -A INPUT -i $ETH_WRL -j wrl
iptables -A INPUT -i $ETH_LO -j lo
iptables -A FORWARD -i $ETH_WAN -o $ETH_DMZ -j wantodmz
iptables -A FORWARD -i $ETH_WAN -o $ETH_LAN -j wantolan
iptables -A FORWARD -i $ETH_WAN -o $ETH_WRL -j wantowrl
iptables -A FORWARD -i $ETH_LAN -o $ETH_DMZ -j lantodmz
iptables -A FORWARD -i $ETH_LAN -o $ETH_WAN -j lantowan
iptables -A FORWARD -i $ETH_LAN -o $ETH_WRL -j lantowrl
iptables -A FORWARD -i $ETH_DMZ -o $ETH_WAN -j dmztowan
iptables -A FORWARD -i $ETH_DMZ -o $ETH_LAN -j dmztolan
iptables -A FORWARD -i $ETH_DMZ -o $ETH_WRL -j dmztowrl
iptables -A FORWARD -i $ETH_WRL -o $ETH_WAN -j wrltowan
iptables -A FORWARD -i $ETH_WRL -o $ETH_LAN -j wrltolan
iptables -A FORWARD -i $ETH_WRL -o $ETH_DMZ -j wrltodmz
I can access the services in the DMZ zone from the WAN but I can't
access the DMZ when Iam sitting on the local network.
My conf:
Flushing rules and policies
Making the new chains
Done....
Making FORWARD chains
Done....
Flushing NAT - POSTROUTING & PREROUTING
Done.... NAT module finished
Setting up local chain
Done.... Local chain is up and running
Setting up LAN chain
Done....LAN chain is running
Setting up WAN chain
Done....WAN chain is running
Setting up DMZ chain
Done....DMZ chain is running
Setting up WRL chain
Done....WRL chain is running
Setting up DMZ portfarwarding
Done.... DMZ portforwarding is up and running
Setting up masquerading - NAT chains
Done....NAT chains are up and running
Setting up the rules
Done....Firewall rules is up and running
Loading the modules
Done....
Activating the chains
Done.... Firewall is now up and running!!!
My running conf:
Chain INPUT (policy DROP)
target prot opt source destination
lan all -- anywhere anywhere
wan all -- anywhere anywhere
dmz all -- anywhere anywhere
wrl all -- anywhere anywhere
lo all -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
wantodmz all -- anywhere anywhere
wantolan all -- anywhere anywhere
wantowrl all -- anywhere anywhere
lantodmz all -- anywhere anywhere
lantowan all -- anywhere anywhere
lantowrl all -- anywhere anywhere
dmztowan all -- anywhere anywhere
dmztolan all -- anywhere anywhere
dmztowrl all -- anywhere anywhere
wrltowan all -- anywhere anywhere
wrltolan all -- anywhere anywhere
wrltodmz all -- anywhere anywhere
Chain OUTPUT (policy DROP)
target prot opt source destination
Chain SSH_WHITELIST (0 references)
target prot opt source destination
Chain dmz (1 references)
target prot opt source destination
DROP all -- 87.51.67.140 anywhere
DROP all -- 172.16.0.0/24 anywhere
DROP all -- 172.16.1.0/24 anywhere
DROP all -- 127.0.0.0/8 anywhere
DROP all -- 172.16.10.0/24 anywhere
ACCEPT all -- anywhere anywhere state
NEW,RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW DMZ:'
DROP all -- anywhere anywhere
Chain dmztolan (1 references)
target prot opt source destination
ACCEPT tcp -- 87.51.67.140 172.16.0.0/24 tcp dpt:smtp
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW DMZTOLAN:'
DROP all -- anywhere anywhere
Chain dmztowan (1 references)
target prot opt source destination
ACCEPT tcp -- 172.16.10.10 anywhere tcp dpt:smtp
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW DMZTOWAN:'
DROP all -- anywhere anywhere
Chain dmztowrl (1 references)
target prot opt source destination
Chain lan (1 references)
target prot opt source destination
DROP all -- 87.51.67.140 anywhere
DROP all -- 127.0.0.0/8 anywhere
DROP all -- 172.16.10.0/24 anywhere
DROP all -- 172.16.1.0/24 anywhere
DROP all -- 172.16.0.0/24 anywhere
ACCEPT all -- anywhere anywhere state
NEW,RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW LAN:'
DROP all -- anywhere anywhere
Chain lantodmz (1 references)
target prot opt source destination
ACCEPT tcp -- 172.16.0.0/24 172.16.10.0/24 tcp dpt:www
ACCEPT tcp -- 172.16.0.0/24 172.16.10.0/24 tcp dpt:ssh
ACCEPT tcp -- 172.16.0.0/24 172.16.10.0/24 tcp dpt:smtp
ACCEPT tcp -- 172.16.0.0/24 172.16.10.0/24 tcp dpt:imap2
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW LANTODMZ:'
DROP all -- anywhere anywhere
Chain lantowan (1 references)
target prot opt source destination
ACCEPT tcp -- 172.16.0.0/24 anywhere tcp dpt:www
ACCEPT tcp -- 172.16.0.0/24 anywhere tcp dpt:https
ACCEPT tcp -- 172.16.0.0/24 anywhere tcp dpt:ftp
ACCEPT tcp -- 172.16.0.0/24 anywhere tcp dpt:ssh
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW LANTOWAN:'
DROP all -- anywhere anywhere
Chain lantowrl (1 references)
target prot opt source destination
Chain lo (1 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere state
NEW,RELATED,ESTABLISHED
Chain wan (1 references)
target prot opt source destination
DROP all -- 87.51.67.140 anywhere
DROP all -- 172.16.10.0/24 anywhere
DROP all -- 172.16.0.0/24 anywhere
DROP all -- 127.0.0.0/8 anywhere
DROP all -- 172.16.1.0/24 anywhere
ACCEPT all -- anywhere anywhere state
NEW,RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW WAN:'
DROP all -- anywhere anywhere
Chain wantodmz (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.16.10.10 tcp dpt:ssh
ACCEPT tcp -- anywhere 172.16.10.10 tcp dpt:smtp
ACCEPT tcp -- anywhere 172.16.10.10 tcp dpt:www
ACCEPT tcp -- anywhere 172.16.10.10 tcp dpt:imap2
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW WANTODMZ:'
DROP all -- anywhere anywhere
Chain wantolan (1 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW WANTOLAN PORTFWD:'
DROP all -- anywhere anywhere
Chain wantowrl (1 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW WANTOWRL PORTFWD:'
DROP all -- anywhere anywhere
Chain wrl (1 references)
target prot opt source destination
DROP all -- 87.51.67.140 anywhere
DROP all -- 127.0.0.0/8 anywhere
DROP all -- 172.16.0.0/24 anywhere
DROP all -- 172.16.10.0/24 anywhere
DROP all -- 172.16.1.0/24 anywhere
ACCEPT all -- anywhere anywhere state
NEW,RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW WRL:'
DROP all -- anywhere anywhere
Chain wrltodmz (1 references)
target prot opt source destination
ACCEPT tcp -- 172.16.1.0/24 172.16.10.0/24 tcp dpt:www
ACCEPT tcp -- 172.16.1.0/24 172.16.10.0/24 tcp dpt:ssh
ACCEPT tcp -- 172.16.1.0/24 172.16.10.0/24 tcp dpt:smtp
ACCEPT tcp -- 172.16.1.0/24 172.16.10.0/24 tcp dpt:imap2
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW WRLTODMZ:'
DROP all -- anywhere anywhere
Chain wrltolan (1 references)
target prot opt source destination
Chain wrltowan (1 references)
target prot opt source destination
ACCEPT tcp -- 172.16.1.0/24 anywhere tcp dpt:www
ACCEPT tcp -- 172.16.1.0/24 anywhere tcp dpt:https
ACCEPT tcp -- 172.16.1.0/24 anywhere tcp dpt:ftp
ACCEPT tcp -- 172.16.1.0/24 anywhere tcp dpt:ssh
ACCEPT all -- anywhere anywhere state
RELATED,ESTABLISHED
LOG all -- anywhere anywhere LOG level
warning prefix `FW WRLTOWAN:'
DROP all -- anywhere anywhere
Jeg håber der er nogen der kan hjælpe mig med scriptet, og ja jeg har
prøvet at søge på google og jeg har prøvet at fjerne drop samt indsætte
new på alle forbindelserne men lige lidt hjælper det.
--
Mvh
Mathias Mejborn
mathias@mejborn.dk
http://mejborn.dk