Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Feb 2001 00:55:27 -0500
From:      Kelly Hendrix <kelly@compuage.com>
To:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Redirect port to internal address
Message-ID:  <20010209005527.E8297@hnet04.kellyhendrix.com>

next in thread | raw e-mail | index | archive | help
Greetings,

I'm trying to redirect all incoming traffic on port 80 of my external ip
to an address on my internal lan, same port.  This is what I have in my
/etc/natd.conf on my firewall/lan box:

	use_sockets yes
	same_ports  yes
	unregistered_only yes
	redirect_port tcp 192.168.0.4:80 80 

Here are the relevant items in rc.conf:

	firewall_enable="YES"
	firewall_script="/root/rc.firewall"
	firewall_quiet="NO"
	natd_program="/sbin/natd"
	natd_enable="YES"
	natd_interface="dc0"
	natd_flags="-f /etc/natd.conf"

Yes, I know my rc.firewall is in a nonstandard place.  Basically, it's
just a set of rules, similar to client without all the tests for
firewall type, hence no need to declare a specific type in rc.conf.  My
guess is that it's my firewall rules causing the redirect problems here.
A couple of things I've tried.  From my /root/rc.firewall:

	${fwcmd} add pass tcp from any to any 80 setup
	${fwcmd} add divert natd all from any to any via dc0 

When I do this, none of my internal browsers work.  No go on redirection
either.  And when I do this:

	${fwcmd} add divert natd all from any to any via dc0 
	${fwcmd} add pass tcp from any to any 80 setup

my browsers work, but again, no redirection.  I will post my complete
firewall rules at the end, in case someone needs to look at them.  Also,
the server is in place and working because when I go to my other
machines and type in the IP, I get the generic apache screen.  Can
anyone give me any suggestions on how to make this work?  TIA.

Kelly Hendrix

My complete /root/rc.firewall:

	#fwcmd="/sbin/ipfw -q"
	fwcmd="/sbin/ipfw"
	${fwcmd} -f flush

	${fwcmd} add 100 pass all from any to any via lo0
	${fwcmd} add 200 deny all from any to 127.0.0.0/8

	oif="dc0"
	onet="208.233.247.37"
	omask="255.255.255.255"
	oip="208.233.247.37"			

	iif="dc1"
	inet="192.168.0.0"
	imask="255.255.255.0"
	iip="192.168.0.1"

	# Stop spoofing
	${fwcmd} add deny all from ${inet}:${imask} to any in via ${oif}
	${fwcmd} add deny all from ${onet}:${omask} to any in via ${iif}

	# Stop RFC1918 nets on the outside interface
	${fwcmd} add deny all from any to 10.0.0.0/8 via ${oif}
	${fwcmd} add deny all from any to 172.16.0.0/12 via ${oif}
	${fwcmd} add deny all from any to 192.168.0.0/16 via ${oif}

	# Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
	# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
	# on the outside interface
	${fwcmd} add deny all from any to 0.0.0.0/8 via ${oif}
	${fwcmd} add deny all from any to 169.254.0.0/16 via ${oif}
	${fwcmd} add deny all from any to 192.0.2.0/24 via ${oif}
	${fwcmd} add deny all from any to 224.0.0.0/4 via ${oif}
	${fwcmd} add deny all from any to 240.0.0.0/4 via ${oif}

	#${fwcmd} add pass tcp from any to any 80 setup

	# Network Address Translation.  This rule is placed here deliberately
	# so that it does not interfere with the surrounding address-checking
	# rules.  If for example one of your internal LAN machines had its IP
	# address set to 192.0.2.1 then an incoming packet for it after being
	# translated by natd(8) would match the `deny' rule above.  Similarly
	# an outgoing packet originated from it before being translated would
	# match the `deny' rule below.

	${fwcmd} add divert natd all from any to any via dc0 

	#Allow all traffic on internal network
	${fwcmd} add allow all from ${inet}:${imask} to ${inet}:${imask}

	#Shutdown NetBIOS to outside world
	${fwcmd} add deny log tcp from any 137-139 to any out via dc0
	${fwcmd} add deny log udp from any 137-139 to any out via dc0
	${fwcmd} add deny log tcp from any to any 137-139 in via dc0
	${fwcmd} add deny log udp from any to any 137-139 in via dc0

	#Shutdown rpc.stat and mountd to outside interface
	${fwcmd} add deny log tcp from any to any 1022-1023 via dc0
	${fwcmd} add deny log udp from any to any 1022-1023 via dc0
	${fwcmd} add deny log tcp from any 1022-1023 to any via dc0
	${fwcmd} add deny log udp from any 1022-1023 to any via dc0

	#abbaccuray?  Port being probed 
	${fwcmd} add deny log tcp from any to any 1546 via dc0
	${fwcmd} add deny log udp from any to any 1546 via dc0
	${fwcmd} add deny log tcp from any 1546 to any via dc0
	${fwcmd} add deny log udp from any 1546 to any via dc0

	#Shutdown Xserver to outside interface
	${fwcmd} add deny log tcp from any to any 6000 via dc0
	${fwcmd} add deny log udp from any to any 6000 via dc0
	${fwcmd} add deny log tcp from any 6000 to any via dc0
	${fwcmd} add deny log udp from any 6000 to any via dc0

	#Shutdown nfs to outside interface
	${fwcmd} add deny log tcp from any to any 2049 via dc0
	${fwcmd} add deny log udp from any to any 2049 via dc0
	${fwcmd} add deny log tcp from any 2049 to any via dc0
	${fwcmd} add deny log udp from any 2049 to any via dc0
	
	#Shutdown portmap to outside interface
	${fwcmd} add deny log tcp from any to any 111 via dc0
	${fwcmd} add deny log udp from any to any 111 via dc0
	${fwcmd} add deny log tcp from any 111 to any via dc0
	${fwcmd} add deny log udp from any 111 to any via dc0
	 
	# Stop RFC1918 nets on the outside interface
	${fwcmd} add deny all from 10.0.0.0/8 to any via ${oif}
	${fwcmd} add deny all from 172.16.0.0/12 to any via ${oif}
	${fwcmd} add deny all from 192.168.0.0/16 to any via ${oif}

	# Stop draft-manning-dsua-03.txt (1 May 2000) nets (includes RESERVED-1,
	# DHCP auto-configuration, NET-TEST, MULTICAST (class D), and class E)
	# on the outside interface
	${fwcmd} add deny all from 0.0.0.0/8 to any via ${oif}
	${fwcmd} add deny all from 169.254.0.0/16 to any via ${oif}
	${fwcmd} add deny all from 192.0.2.0/24 to any via ${oif}
	${fwcmd} add deny all from 224.0.0.0/4 to any via ${oif}
	${fwcmd} add deny all from 240.0.0.0/4 to any via ${oif}

	# Allow TCP through if setup succeeded
	${fwcmd} add pass tcp from any to any established
	

	# Allow IP fragments to pass through
	${fwcmd} add pass all from any to any frag

	# Allow setup of incoming email
	${fwcmd} add pass tcp from any to any 25 setup

	# Allow access to our DNS
	#${fwcmd} add pass tcp from any to ${oip} 53 setup
	#${fwcmd} add pass udp from any to ${oip} 53
	#${fwcmd} add pass udp from ${oip} 53 to any

	# Allow access to our WWW
	${fwcmd} add pass tcp from any to any 80 setup

	# Reject&Log all setup of incoming connections from the outside
	${fwcmd} add deny log tcp from any to any in via ${oif} setup

	# Allow setup of any other TCP connection
        ${fwcmd} add pass tcp from any to any setup

	# Allow DNS queries out in the world
	${fwcmd} add pass udp from any 53 to any
	${fwcmd} add pass udp from any to any 53

	# Allow NTP queries out in the world
	${fwcmd} add pass udp from any 123 to ${oip}
	${fwcmd} add pass udp from ${oip} to any 123

	#Allow all icmp traffic on the inner interface
	${fwcmd} add pass icmp from any to any via ${iif}

	# Allow pings
	${fwcmd} add pass icmp from any to any icmptypes 8 out via ${oif}
	${fwcmd} add pass icmp from any to any icmptypes 0 in via ${oif}

	#Allow some other icmp traffic including traceroute
	${fwcmd} add pass icmp from any to any icmptypes 3,4,11,12 via ${oif}

	#Disallow  what's left
	${fwcmd} add deny icmp from any to any




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010209005527.E8297>