LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Portforwarding using JordanH's "firewall for home users" script (https://www.linuxquestions.org/questions/linux-networking-3/portforwarding-using-jordanhs-firewall-for-home-users-script-147921/)

steepcreep 02-19-2004 02:46 AM

Portforwarding using JordanH's "firewall for home users" script
 
I'm trying to modify the script (iptables Firewall for typical home users) that JordanH graciously wrote out to help all the beginners out there (that being me) to forward -NEW connections on port 6714 to my internal network.

BUT, it's not working! :cry:

What I means is all my attempts at modifiying this script to allow forwarding have ended in frustration. Such is life.;) The script itself untouched works great and unbelievably I think I'm actually getting a handle on iptables, especially the special chains that are created in this script, however portforwarding is still eluding me.

Incoming connections on:
Protocol: ftp
Port: 6714

Forwarded to:
Addy: 192.168.0.2

The changes I have made are highlighted in Red.

Thanks for the help.



#!/bin/bash
################################################################################
# omato-firewall.sh v2.0
# The purpose of this script is to act as a template for typical home users
# that want to use linux as a secure firewall/gateway/router but who are not
# current on the iptables technology. It will provide a structured base for
# users to customize.
#
# The resulting firewall is reasonably secure for a home user and flexible
# enough to allow even the most paranoid of firewallers to expand on.
#
# Author: jordan_harkness @ hotmail.com
#
# note 1. You should disable logging when stable.
#
# We make these assumptions...
# 1. All internal machines are trusted.
# 2. All internal machines use private ip addresses and use this machine to
# share the internet. All ports are allowed.
# 3. All external machines are untrusted.
# 4. External connections will only be allowed if initiated from inside the
# network or from the firewall itself.
#
# Change History
# v2.0 Nov.28.2003
# Re-written based on what I learned from my v1.0 customized firewall.
################################################################################

################################################################################
# Default options
# These options configure the below script. It would be a good idea to move
# them to a conf file in /etc and then source it from this script.
################################################################################
echo 1 > /proc/sys/net/ipv4/ip_forward
# location of iptables command
ipt=/sbin/iptables
#
# Interfaces
# Be sure to be accurate when defining these interfaces.
# ext is your external card, likely ppp0 for DSL or eth1 for cable
lo=lo
ext=eth0
int=eth1
#
# Spoofing protection. List all networks and IP addresses that should NOT exist
# in the real world.
#
spoofed="0.0.0.0/8 10.0.0.0/8 127.0.0.0/8 169.254.0.0/16 172.16.0.0/12
192.168.0.0/16 255.255.255.255"
#
# List all ports to open ON your firewall
#
tcp_ports="22 6714"
udp_ports=""
#

# These logging options will be used for all logged packets
#
logops="--log-leve=3 -m limit --limit 1/second --limit-burst=3"
################################################################################

################################################################################
################################################################################
################################################################################
################################################################################
################################################################################

################################################################################
# Set policies and delete, flush and zero chains
################################################################################
$ipt -P INPUT DROP
$ipt -P FORWARD DROP
$ipt -P OUTPUT ACCEPT
for table in filter nat mangle
do
$ipt -t $table -F # flush
$ipt -t $table -X # delete
$ipt -t $table -Z # zero
done
################################################################################

################################################################################
# BAD_IP
# Check and log all spoofed IP's from external hosts.
# !! Only call from external interface !!
################################################################################
$ipt -N BAD_IP
$ipt -A BAD_IP -j LOG --log-prefix "IPT: BAD IP: " $logops
$ipt -A BAD_IP -j DROP
$ipt -N SPOOF
for spf in $spoofed
do
$ipt -A SPOOF -s $spf -j BAD_IP
done
################################################################################

################################################################################
################################################################################
################################################################################
################################################################################
################################################################################

################################################################################
# IN_NETWORK
# These packets are entering our network
# 1. Allow related and established connections
# 2. Allow ICMP packets
# 3. Deny everything else.
################################################################################
$ipt -N IN_NETWORK
$ipt -A IN_NETWORK -m state --state INVALID -j DROP
$ipt -A IN_NETWORK -j SPOOF
$ipt -A IN_NETWORK -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A IN_NETWORK -p udp -m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A IN_NETWORK -p icmp -j ACCEPT
$ipt -A IN_NETWORK -j LOG --log-prefix "IPT: IN_NETWORK: " $logops
$ipt -A IN_NETWORK -j DROP
################################################################################

################################################################################
# OUT_NETWORK
# These packets are leaving our network!
# 1. Allow all packets to leave our current network because we trust our users
################################################################################
$ipt -N OUT_NETWORK
$ipt -A OUT_NETWORK -i $int -j ACCEPT
$ipt -A OUT_NETWORK -j LOG --log-prefix "IPT: OUT_NETWORK: " $logops
$ipt -A OUT_NETWORK -j DROP
################################################################################

################################################################################
# EXT_FIREWALL
# Packets entering firewall machine
# 1. Allow established and related connections
# 2. Allow new connections on specified ports
# 3. Log and Drop everything else
################################################################################
$ipt -N EXT_FIREWALL
$ipt -A EXT_FIREWALL -m state --state INVALID -j DROP
$ipt -A EXT_FIREWALL -j SPOOF
$ipt -A EXT_FIREWALL -m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A EXT_FIREWALL -p icmp -j ACCEPT
################################################################################
# Open ports
################################################################################
for tcp_p in $tcp_ports
do
$ipt -A EXT_FIREWALL -p tcp --dport $tcp_p -m state --state NEW -j ACCEPT
done
for udp_p in $udp_ports
do
$ipt -A EXT_FIREWALL -p udp --dport $udp_p -m state --state NEW -j ACCEPT
done
$ipt -A EXT_FIREWALL -j LOG --log-prefix "IPT: EXT_FIREWALL: " $logops
$ipt -A EXT_FIREWALL -j DROP
################################################################################


################################################################################
# INT_FIREWALL
# Connections from internal LAN
# 1. Allow all connections from the internal machines because they are trusted
################################################################################
$ipt -N INT_FIREWALL
$ipt -A INT_FIREWALL -m state --state INVALID -j DROP
$ipt -A INT_FIREWALL -j ACCEPT
################################################################################

################################################################################
################################################################################
################################################################################
################################################################################
################################################################################

################################################################################
# Main Rules
# 1. Allow all loopback traffic. This is safe.
# 2. Send internal connections to INT_FIREWALL chain
# 3. Send external connections to EXT_FIREWALL chain
# 4. Send connections entering LAN to IN_NETWORK
# 5. Send connections leaving LAN to OUT_NETWORK
# 6. Do not modify packets leaving computer to improve performance. It's safe.
################################################################################
$ipt -A INPUT -i lo -j ACCEPT
$ipt -A INPUT -i $int -j INT_FIREWALL
$ipt -A INPUT -i $ext -j EXT_FIREWALL
$ipt -A FORWARD -i $ext -j IN_NETWORK
$ipt -A FORWARD -i $int -j OUT_NETWORK
# $ipt -A OUTPUT -i lo -j ACCEPT
# $ipt -A OUTPUT -i $int -j ACCEPT
# $ipt -A OUTPUT -i $ext -j ACCEPT
################################################################################

################################################################################
# Port forwarding
# 1. to an internal network ftp server running on a non-standard port, 6714.
################################################################################
$ipt -t nat -A PREROUTING -i $ext -p tcp --dport 6714 -j DNAT --to-destination
192.168.0.2
################################################################################


################################################################################
# Masquerading
# Turn on Masquerading and port forwarding
################################################################################
$ipt -t nat -A POSTROUTING -o $ext -j MASQUERADE
################################################################################

tlavigne 07-29-2004 08:15 PM

Did you get this figured out?
 
I'm having the same problem! (With the same script....great script!)


All times are GMT -5. The time now is 08:49 PM.