The company that I work for had got more public IPs and wishes to publish a few of our servers into the web. I've setup iptables previously but only to share the internet connection and map (DNAT) a few services in. I did some studies and came across this tutorial site -
After reading through I've comup with this script. However nothing or no connections seem to getting through. When I run the script, I get a warning "no chain/target/match by that name" although doing an iptables -L -v shows that the chain does exist.
--== Start Script ==--
#!/bin/sh
# Set Environment Variables
EXT="eth1"
INT="eth0"
EXT_IP="10.0.0.1"
MAILSRV="192.168.0.1"
WEBSRV="192.168.0.2"
DBSRV="192.168.0.2"
FTPSRV="192.168.0.2"
CITRIX_INT="192.168.0.3"
CITRIX_EXT="10.0.0.2"
# Setup Tracking Modules
/sbin/insmod ip_tables
/sbin/insmod ip_conntrack
/sbin/insmod ip_conntrack_ftp
/sbin/insmod iptable_nat
/sbin/insmod ip_nat_ftp
#/sbin/insmod ip_conntrack_irc
#/sbin/insmod ip_nat_irc
# Set default policies to DROP
iptables -P INPUT ACCEPT
iptables -F INPUT
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT
iptables -P FORWARD DROP
iptables -F FORWARD
iptables -t nat -F
# Creating User Defined Chains
iptables -N tcp_packets
iptables -N udp_packets
iptables -N icmp_packets
# Starting Ruleset
iptables -A FORWARD -p icmp -j icmp_packets
iptables -A FORWARD -p tcp -j tcp_packets
iptables -A FORWARD -p udp -j udp_packets
iptables -A FORWARD -j LOG
# ICMP Ruleset START
iptables -A icmp_packets -j LOG
# ICMP Ruleset END
# TCP Ruleset START
iptables -A tcp_packets -p tcp --dport 137:139 -j DROP
iptables -A tcp_packets -p tcp -m multiport --dports 21,25,53,80,3000,3306 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A tcp_packets -i $INT -p tcp -s 192.168.0.1 -o $EXT -j ACCEPT
iptables -A tcp_packets -i $INT -p tcp -s 192.168.0.2 -o $EXT -j ACCEPT
iptables -A tcp_packets -i $INT -p tcp -s 192.168.0.3 -o $EXT -j ACCEPT
iptables -A tcp_packets -j LOG
# TCP Ruleset END
# UDP Ruleset SART
iptables -A udp_packets -p udp --dport 53 -j ACCEPT
iptables -A udp_packets -j LOG
# UDP Ruleset END
iptables -A PREROUTING -i $EXT -p tcp --dport 21 -d $EXT_IP -j DNAT --to-destination $FTPSRV:21
iptables -A PREROUTING -i $EXT -p tcp --dport 25 -d $EXT_IP -j DNAT --to-destination $MAILSRV:25
iptables -A PREROUTING -i $EXT -p tcp --dport 80 -d $EXT_IP -j DNAT --to-destination $WEBSRV:80
iptables -A PREROUTING -i $EXT -p tcp --dport 3000 -d $EXT_IP -j DNAT --to-destination $MAILSRV:3000
iptables -A PREROUTING -i $EXT -p tcp --dport 3306 -d $EXT_IP -j DNAT --to-destination $DBSRV:3306
iptables -A PREROUTING -i $EXT -d $CITRIX_EXT -j DNAT --to-destination $CITRIX_INT
# Spoof Prevention
iptables -A PREROUTING -i $EXT -s ! 192.168.1.0/24 -j DROP
iptables -A PREROUTING -i $INT -s 192.168.1.0/24 -j DROP
iptables -A POSTROUTING -o $EXT -s ! $CITRIX_INT -j SNAT --to-source $EXT_IP
iptables -A POSTROUTING -o $EXT -s $CITRIX_INT -j SNAT --to-source $CITRIX_EXT
--== End Script ==-
After reading through I've comup with this script. However nothing or no connections seem to getting through. When I run the script, I get a warning "no chain/target/match by that name" although doing an iptables -L -v shows that the chain does exist.
--== Start Script ==--
#!/bin/sh
# Set Environment Variables
EXT="eth1"
INT="eth0"
EXT_IP="10.0.0.1"
MAILSRV="192.168.0.1"
WEBSRV="192.168.0.2"
DBSRV="192.168.0.2"
FTPSRV="192.168.0.2"
CITRIX_INT="192.168.0.3"
CITRIX_EXT="10.0.0.2"
# Setup Tracking Modules
/sbin/insmod ip_tables
/sbin/insmod ip_conntrack
/sbin/insmod ip_conntrack_ftp
/sbin/insmod iptable_nat
/sbin/insmod ip_nat_ftp
#/sbin/insmod ip_conntrack_irc
#/sbin/insmod ip_nat_irc
# Set default policies to DROP
iptables -P INPUT ACCEPT
iptables -F INPUT
iptables -P OUTPUT ACCEPT
iptables -F OUTPUT
iptables -P FORWARD DROP
iptables -F FORWARD
iptables -t nat -F
# Creating User Defined Chains
iptables -N tcp_packets
iptables -N udp_packets
iptables -N icmp_packets
# Starting Ruleset
iptables -A FORWARD -p icmp -j icmp_packets
iptables -A FORWARD -p tcp -j tcp_packets
iptables -A FORWARD -p udp -j udp_packets
iptables -A FORWARD -j LOG
# ICMP Ruleset START
iptables -A icmp_packets -j LOG
# ICMP Ruleset END
# TCP Ruleset START
iptables -A tcp_packets -p tcp --dport 137:139 -j DROP
iptables -A tcp_packets -p tcp -m multiport --dports 21,25,53,80,3000,3306 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A tcp_packets -i $INT -p tcp -s 192.168.0.1 -o $EXT -j ACCEPT
iptables -A tcp_packets -i $INT -p tcp -s 192.168.0.2 -o $EXT -j ACCEPT
iptables -A tcp_packets -i $INT -p tcp -s 192.168.0.3 -o $EXT -j ACCEPT
iptables -A tcp_packets -j LOG
# TCP Ruleset END
# UDP Ruleset SART
iptables -A udp_packets -p udp --dport 53 -j ACCEPT
iptables -A udp_packets -j LOG
# UDP Ruleset END
iptables -A PREROUTING -i $EXT -p tcp --dport 21 -d $EXT_IP -j DNAT --to-destination $FTPSRV:21
iptables -A PREROUTING -i $EXT -p tcp --dport 25 -d $EXT_IP -j DNAT --to-destination $MAILSRV:25
iptables -A PREROUTING -i $EXT -p tcp --dport 80 -d $EXT_IP -j DNAT --to-destination $WEBSRV:80
iptables -A PREROUTING -i $EXT -p tcp --dport 3000 -d $EXT_IP -j DNAT --to-destination $MAILSRV:3000
iptables -A PREROUTING -i $EXT -p tcp --dport 3306 -d $EXT_IP -j DNAT --to-destination $DBSRV:3306
iptables -A PREROUTING -i $EXT -d $CITRIX_EXT -j DNAT --to-destination $CITRIX_INT
# Spoof Prevention
iptables -A PREROUTING -i $EXT -s ! 192.168.1.0/24 -j DROP
iptables -A PREROUTING -i $INT -s 192.168.1.0/24 -j DROP
iptables -A POSTROUTING -o $EXT -s ! $CITRIX_INT -j SNAT --to-source $EXT_IP
iptables -A POSTROUTING -o $EXT -s $CITRIX_INT -j SNAT --to-source $CITRIX_EXT
--== End Script ==-