LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-21-2005, 01:21 PM   #1
scjvsTP
LQ Newbie
 
Registered: Sep 2005
Distribution: SuSE 10, Fedora Core 4
Posts: 15

Rep: Reputation: 0
IPTABLES trouble


I can't seem to allow computers in my internal network (on NAT eth1) to access the web server on the DMZ (NAT eth2). The NAT can access the web server fine. There isn't a firewall running on the web server. Can anyone help me out here? Here is my script so far.

Code:
#!/bin/bash
#
#
#############    IPTABLES firewall		#############
#############    By David Pack			#############
#############    Information Technology SCJVS	#############

echo "IPTABLES Firewall"
echo "----------------"

############# Variables
	echo "	Creating Variables"

	###Path to executables
	IPTABLES=/usr/sbin/iptables
	MODPROBE=/sbin/modprobe

	###Network Interfaces
	IFACE_EXT=eth0	# Internet
	IFACE_INT=eth1	# Internal Network
	IFACE_DMZ=eth2	# DMZ

	###IP Addresses
	IPADDR_EXT=192.168.138.1
	IPADDR_INT=192.168.20.1
	IPADDR_DMZ=192.168.50.1

	IPADDR_GATEWAY=192.168.128.1
	IPADDR_SAMBA=192.168.20.2

	IPADDR_INT_DNS=192.168.20.1
	IPADDR_EXT_DNS=10.0.0.101

	IPADDR_WEBSERVER=192.168.50.2

	###Subnet Masks
	SUBNET_EXT=255.255.240.0
	SUBNET_INT=255.255.255.0
	SUBNET_DMZ=255.255.255.0

########### End Variables

########### Firewall

	###Stop forwarding while setting up
	echo "	Disabling IP Forwarding"
	echo "0" > /proc/sys/net/ipv4/ip_forward

	###Modules
	echo "	Loading Modules"
	${MODPROBE} ip_conntrack_ftp
	${MODPROBE} ip_conntrack_irc

	###Flush tables
	echo "	Flushing Tables"
	${IPTABLES} -F					#flush chains
	${IPTABLES} -X					#delete user chains
	${IPTABLES} -Z					#set counters to zero
	for t in `cat /proc/net/ip_tables_names`
	do
		${IPTABLES} -F -t $t
		${IPTABLES} -X -t $t
		${IPTABLES} -Z -t $t
	done

	###Setup policy
	echo "	Setting up policy"
	${IPTABLES} -P INPUT   DROP			# Drop all packets that
	${IPTABLES} -P OUTPUT  ACCEPT			# aren't specified to be
	${IPTABLES} -P FORWARD ACCEPT			# accepted in the script.

	###Accept local interface
	echo "	Accept local interface"
	${IPTABLES} -A INPUT  -i lo -j ACCEPT
	${IPTABLES} -A OUTPUT -o lo -j ACCEPT

	###Accept anything from the inside network.
	echo "	Accept anything from the inside network."
	${IPTABLES} -A INPUT -i ${IFACE_INT} -j ACCEPT
	${IPTABLES} -A OUTPUT -o ${IFACE_INT} -j ACCEPT

	${IPTABLES} -A INPUT -i ${IFACE_DMZ} -j ACCEPT
	${IPTABLES} -A OUTPUT -o ${IFACE_DMZ} -j ACCEPT

	###Allow our firewall to connect.
	echo "	Allow our firewall to connect."
	${IPTABLES} -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
	${IPTABLES} -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

	###Allow ping
	echo "	Allow ping"
	${IPTABLES} -A INPUT  -p icmp -j ACCEPT
	${IPTABLES} -A OUTPUT -p icmp -j ACCEPT

	##Allow access to webserver
	echo "	Allow access to webserver."
	${IPTABLES} -A INPUT -i ${IFACE_DMZ} -p tcp -s 0.0.0.0 --sport 1024:65535 --dport 80 -j ACCEPT
	${IPTABLES} -A OUTPUT -o ${IFACE_DMZ} -p tcp --sport 80 -d 0.0.0.0 --dport 1024:65535 -j ACCEPT

	###Share internet connection w/ internal network.
	echo "	Share internet connection with internal network."
	${IPTABLES} -t nat -A POSTROUTING -o ${IFACE_EXT} -j MASQUERADE

	###Allow connections to the internet from the internal network.
	${IPTABLES} -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
	${IPTABLES} -A FORWARD -m state --state NEW -i ${IFACE_INT} -j ACCEPT

	###Enable dynamic IP address following
	echo 2 > /proc/sys/net/ipv4/ip_dynaddr

	# Syncookies
	echo "1" > /proc/sys/net/ipv4/tcp_syncookies

	###Enabling IP forwarding.
	echo "	Enabling IP forwarding"
	echo "1" > /proc/sys/net/ipv4/ip_forward

	echo "----------------"
	echo "Complete!"
########### End Firewall
 
Old 10-21-2005, 10:32 PM   #2
SirGertrude
Member
 
Registered: May 2004
Location: Missouri
Distribution: Gentoo
Posts: 59

Rep: Reputation: 15
I don't see any problems in your iptables script that would prevent you from seeing the web server. I do see some redundant lines that could be removed to clean things up.

The following lines are not needed as they are repetitive (Already defined by default policy "-P OUTPUT ACCEPT" and "-P FORWARD ACCEPT"):
Quote:
${IPTABLES} -A OUTPUT -o lo -j ACCEPT
${IPTABLES} -A OUTPUT -o ${IFACE_INT} -j ACCEPT
${IPTABLES} -A OUTPUT -o ${IFACE_DMZ} -j ACCEPT
${IPTABLES} -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
${IPTABLES} -A OUTPUT -p icmp -j ACCEPT
${IPTABLES} -A OUTPUT -o ${IFACE_DMZ} -p tcp --sport 80 -d 0.0.0.0 --dport 1024:65535 -j ACCEPT
${IPTABLES} -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
This line is not needed:
Quote:
${IPTABLES} -A INPUT -i ${IFACE_DMZ} -p tcp -s 0.0.0.0 --sport 1024:65535 --dport 80 -j ACCEPT
because it is already defined by this rule:
Quote:
${IPTABLES} -A INPUT -i ${IFACE_DMZ} -j ACCEPT
You will need a DNAT rule if you want public internet traffic to hit the DMZ IP address:
Code:
${IPTABLES} -t nat -A PREROUTING -i ${IFACE_EXT} -m state --state NEW -j DNAT --to 192.168.50.2
In the end your script should look like this:

Code:
#!/bin/bash
#
#
#############    IPTABLES firewall		#############
#############    By David Pack			#############
#############    Information Technology SCJVS	#############

echo "IPTABLES Firewall"
echo "----------------"

############# Variables
	echo "	Creating Variables"

	###Path to executables
	IPTABLES=/usr/sbin/iptables
	MODPROBE=/sbin/modprobe

	###Network Interfaces
	IFACE_EXT=eth0	# Internet
	IFACE_INT=eth1	# Internal Network
	IFACE_DMZ=eth2	# DMZ

	###IP Addresses
	IPADDR_EXT=192.168.138.1
	IPADDR_INT=192.168.20.1
	IPADDR_DMZ=192.168.50.1

	IPADDR_GATEWAY=192.168.128.1
	IPADDR_SAMBA=192.168.20.2

	IPADDR_INT_DNS=192.168.20.1
	IPADDR_EXT_DNS=10.0.0.101

	IPADDR_WEBSERVER=192.168.50.2

	###Subnet Masks
	SUBNET_EXT=255.255.240.0
	SUBNET_INT=255.255.255.0
	SUBNET_DMZ=255.255.255.0

########### End Variables

########### Firewall

	###Stop forwarding while setting up
	echo "	Disabling IP Forwarding"
	echo "0" > /proc/sys/net/ipv4/ip_forward

	###Modules
	echo "	Loading Modules"
	${MODPROBE} ip_conntrack_ftp
	${MODPROBE} ip_conntrack_irc

	###Flush tables
	echo "	Flushing Tables"
	${IPTABLES} -F					#flush chains
	${IPTABLES} -X					#delete user chains
	${IPTABLES} -Z					#set counters to zero
	for t in `cat /proc/net/ip_tables_names`
	do
		${IPTABLES} -F -t $t
		${IPTABLES} -X -t $t
		${IPTABLES} -Z -t $t
	done

	###Setup policy
	echo "	Setting up policy"
	${IPTABLES} -P INPUT   DROP			# Drop all packets that
	${IPTABLES} -P OUTPUT  ACCEPT			# aren't specified to be
	${IPTABLES} -P FORWARD ACCEPT			# accepted in the script.

	###Accept local interface
	echo "	Accept local interface"
	${IPTABLES} -A INPUT  -i lo -j ACCEPT

	###Accept anything from the inside network.
	echo "	Accept anything from the inside network."
	${IPTABLES} -A INPUT -i ${IFACE_INT} -j ACCEPT

	${IPTABLES} -A INPUT -i ${IFACE_DMZ} -j ACCEPT

	###Allow our firewall to connect.
	echo "	Enable stateful firewall."
	${IPTABLES} -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

	###Allow ping
	echo "	Allow ping"
	${IPTABLES} -A INPUT  -p icmp -j ACCEPT

	###Share internet connection w/ internal network.
	echo "	Share internet connection with internal network."
	${IPTABLES} -t nat -A POSTROUTING -o ${IFACE_EXT} -j MASQUERADE

	###Forward new connections destined for the external interface to the DMZ server
	echo "	Enable DMZ."
	${IPTABLES} -t nat -A PREROUTING -i ${IFACE_EXT} -m state --state NEW -j DNAT --to 192.168.50.2

	###Enable dynamic IP address following
	echo 1 > /proc/sys/net/ipv4/ip_dynaddr

	# Syncookies
	echo "1" > /proc/sys/net/ipv4/tcp_syncookies

	###Enabling IP forwarding.
	echo "	Enabling IP forwarding"
	echo "1" > /proc/sys/net/ipv4/ip_forward

	echo "----------------"
	echo "Complete!"
########### End Firewall
Unfortunately this does not solve your problem. Make sure that you are connecting to the web server using its private IP (192.168.50.2) rather than its public IP (192.168.138.1) when you connect from computers on the internal network (eth1). If you still can’t get in it could be a routing issue, in that case look over the routing table and make sure the proper routes are configured.

Let us know if this works for you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
trouble with iptables module wazilian Linux - Networking 0 09-24-2004 02:55 PM
trouble with iptables module wazilian Linux - Networking 0 09-24-2004 02:55 PM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
trouble ahead, trouble behind....trouble with mplayer Goonie Linux - Software 3 07-02-2003 02:29 AM
iptables trouble, LAN to MySQL on Firewall dwynter Linux - Security 3 11-01-2002 06:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration