Networking Forums

Networking Forums > Computer Networking > Linux Networking > Forwarding through iptables, with 3 NICs

Reply
Thread Tools Display Modes

Forwarding through iptables, with 3 NICs

 
 
Jim Bowen
Guest
Posts: n/a

 
      09-19-2003, 12:18 PM
Hello all,

I am attempting to route traffic from eth0 port 443 to our IIS server
(this is working), while routing eth2 port 443 traffic to the CSG
server. I see traffic coming into eth2, but according to tcpdump,
nothing is exiting to eth1. There is only a single Internet
connection in my setup, with two external IP addys. BTW, I have some
other Citrix-based routing going on as well to other boxes. Summary
listing is below, and iptables script included.

What am I missing here...it must be something simple? Thanks in
advance.

Cheers,
Jim

________________
/--|static IP (eth0)| -- IIS Server
/----/ | | /
Internet------Switch--------|LAN IP (eth1)---------DMZ
\----\ | | \
\--|static IP (eth2)| -- CSG Server
|________________|
LINUX BOX


<begin summary>

iptables -t nat -L -vn
Chain PREROUTING (policy ACCEPT 550 packets, 79691 bytes)
pkts bytes target prot opt in out source
destination
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:1494 to:157.208.75.49
2 96 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:443 to:157.208.75.128
0 0 DNAT udp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx udp dpt:1604 to:157.208.75.49
2 96 DNAT tcp -- eth2 * 0.0.0.0/0
64.xxx.xxx.xxx tcp dpt:443 to:157.208.75.64
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:1494 to:157.208.75.49
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:443 to:157.208.75.128
0 0 DNAT udp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx udp dpt:1604 to:157.208.75.49
0 0 DNAT tcp -- eth2 * 0.0.0.0/0
64.xxx.xxx.xxx tcp dpt:443 to:157.208.75.64
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:1494 to:157.208.75.49
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:443 to:157.208.75.128
0 0 DNAT udp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx udp dpt:1604 to:157.208.75.49
0 0 DNAT tcp -- eth2 * 0.0.0.0/0
64.xxx.xxx.xxx tcp dpt:443 to:157.208.75.64
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:1494 to:157.208.75.49
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:443 to:157.208.75.128
0 0 DNAT udp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx udp dpt:1604 to:157.208.75.49
0 0 DNAT tcp -- eth2 * 0.0.0.0/0
64.xxx.xxx.xxx tcp dpt:443 to:157.208.75.64
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:1494 to:157.208.75.49
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:443 to:157.208.75.128
0 0 DNAT udp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx udp dpt:1604 to:157.208.75.49
0 0 DNAT tcp -- eth2 * 0.0.0.0/0
64.xxx.xxx.xxx tcp dpt:443 to:157.208.75.64
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:1494 to:157.208.75.49
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:443 to:157.208.75.128
0 0 DNAT udp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx udp dpt:1604 to:157.208.75.49
0 0 DNAT tcp -- eth2 * 0.0.0.0/0
64.xxx.xxx.xxx tcp dpt:443 to:157.208.75.64
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:1494 to:157.208.75.49
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:443 to:157.208.75.128
0 0 DNAT udp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx udp dpt:1604 to:157.208.75.49
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:1494 to:157.208.75.49
0 0 DNAT tcp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx tcp dpt:443 to:157.208.75.128
0 0 DNAT udp -- eth0 * 0.0.0.0/0
207.xxx.xxx.xxx udp dpt:1604 to:157.208.75.49
0 0 DNAT tcp -- eth2 * 0.0.0.0/0
64.xxx.xxx.xxx tcp dpt:443 to:157.208.75.64

Chain POSTROUTING (policy ACCEPT 53 packets, 4380 bytes)
pkts bytes target prot opt in out source
destination
37 2626 SNAT all -- * eth0 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth2 0.0.0.0/0
0.0.0.0/0 to:64.xxx.xxx.xxx
0 0 SNAT all -- * eth0 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth2 0.0.0.0/0
0.0.0.0/0 to:64.xxx.xxx.xxx
0 0 SNAT all -- * eth0 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth2 0.0.0.0/0
0.0.0.0/0 to:64.xxx.xxx.xxx
0 0 SNAT all -- * eth0 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth2 0.0.0.0/0
0.0.0.0/0 to:64.xxx.xxx.xxx
0 0 SNAT all -- * eth0 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth2 0.0.0.0/0
0.0.0.0/0 to:64.xxx.xxx.xxx
0 0 SNAT all -- * eth0 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth2 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth0 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth2 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth0 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx
0 0 SNAT all -- * eth2 0.0.0.0/0
0.0.0.0/0 to:207.xxx.xxx.xxx

Chain OUTPUT (policy ACCEPT 76 packets, 6171 bytes)
pkts bytes target prot opt in out source
destination





<begin firewall script>

#!/bin/sh
#
################################################## #########################
#
# 1. Configuration options.
#

################################################## #########################
#
# Local Area Network configuration.
#
# LAN's IP range and localhost IP. /24 means to only use the first 24
# bits of the 32 bit IP adress. the same as netmask 255.255.255.0
#

LAN_IP="157.208.75.48"
LAN_IP_RANGE="157.208.75.0/24"
LAN_BCAST_ADRESS="157.208.75.48"
LAN_IFACE="eth1"


################################################## #########################
#
# Localhost Configuration.
#

LO_IFACE="lo"
LO_IP="127.0.0.1"

################################################## #########################
#
# Internet Configuration.
#

INET_IP="207.xxx.xxx.xxx"
INET_IFACE="eth0"

INET_IP2="64.xxx.xxx.xxx"
INET_IFACE2="eth2"


################################################## #########################
#
# IPTables Configuration.
#

IPTABLES="/sbin/iptables"

################################################## #########################
#
# Port Forwarding Configuration.
#

CITRIX_SERVER="157.208.75.49"
IIS_SERVER="157.208.75.128"
CSG_SERVER="157.208.75.64"



################################################## #########################
#
# 2. Module loading.
#

echo "Loading kernel modules..."

#
# Needed to initially load modules
#
/sbin/depmod -a

#
# Adds some iptables targets like LOG, REJECT and MASQUARADE.
#
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_mangle
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_LOG
#/sbin/modprobe ipt_REJECT
#/sbin/modprobe ipt_MASQUERADE

#
# Support for owner matching
#
#/sbin/modprobe ipt_owner

#
# Support for connection tracking of FTP and IRC.
#
#/sbin/modprobe ip_conntrack_ftp
#/sbin/modprobe ip_conntrack_irc


################################################## #########################
#
# 3. /proc set up.
#
# Enable ip_forward if you have two or more networks, including the
# Internet, that needs forwarding of packets through this box. This is
# critical since it is turned off as default in Linux.
#

echo "Enabling IP forwarding..."

echo "1" > /proc/sys/net/ipv4/ip_forward

#
# Dynamic IP users:
#
#echo "1" > /proc/sys/net/ipv4/ip_dynaddr

################################################## #########################
#
# 4. IPTables rules set up.
#
# Clean old rules
#
echo "Flushing old rules"

$IPTABLES -F
$IPTABLES -X
$IPTABLES -Z


# Set default policies for the INPUT, FORWARD and OUTPUT chains.
# (Block all requests)

echo "Setting default policies..."


$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP

#
# bad_tcp_packets chain
#
# Take care of bad TCP packets that we don't want.
#

$IPTABLES -N bad_tcp_packets
$IPTABLES -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j
LOG \
--log-prefix "New not syn:"
$IPTABLES -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j
DROP

#
# Do some checks for obviously spoofed IP's
#

$IPTABLES -A bad_tcp_packets -i $INET_IFACE -s 192.168.0.0/16 -j DROP
$IPTABLES -A bad_tcp_packets -i $INET_IFACE -s 10.0.0.0/8 -j DROP
$IPTABLES -A bad_tcp_packets -i $INET_IFACE -s 172.16.0.0/12 -j DROP
$IPTABLES -A bad_tcp_packets -i $INET_IFACE2 -s 192.168.0.0/16 -j DROP
$IPTABLES -A bad_tcp_packets -i $INET_IFACE2 -s 10.0.0.0/8 -j DROP
$IPTABLES -A bad_tcp_packets -i $INET_IFACE2 -s 172.16.0.0/12 -j DROP

#
# Enable simple IP Forwarding and Network Address Translation
#

$IPTABLES -t nat -A POSTROUTING -o $INET_IFACE -j SNAT --to-source
$INET_IP
$IPTABLES -t nat -A POSTROUTING -o $INET_IFACE2 -j SNAT --to-source
$INET_IP


#
# Bad TCP packets we don't want
#

$IPTABLES -A FORWARD -p tcp -j bad_tcp_packets


#
# Create separate chains for ICMP, TCP and UDP to traverse
#

$IPTABLES -N icmp_packets
$IPTABLES -N tcp_packets
$IPTABLES -N udpincoming_packets

#
# The allowed chain for TCP connections
#

$IPTABLES -N allowed
$IPTABLES -A allowed -p TCP --syn -j ACCEPT
$IPTABLES -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j
ACCEPT
$IPTABLES -A allowed -p TCP -j DROP

echo "Setting ICMP and TCP rules..."

#
# ICMP rules
#

# Changed rules totally
$IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT
$IPTABLES -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT

#
# TCP rules
#

$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 21 -j allowed
$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 22 -j allowed
$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 25 -j allowed
$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 80 -j allowed
$IPTABLES -A tcp_packets -p TCP -s 0/0 --dport 443 -j allowed

#
# UDP ports
#

# nondocumented commenting out of these rules
$IPTABLES -A udpincoming_packets -p UDP -s 0/0 --source-port 2074 -j
ACCEPT
$IPTABLES -A udpincoming_packets -p UDP -s 0/0 --source-port 4000 -j
ACCEPT


##########################
# INPUT chain
#
# Bad TCP packets we don't want.
#

$IPTABLES -A INPUT -p tcp -j bad_tcp_packets

#
# Rules for incoming packets from the internet.
#

$IPTABLES -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets
$IPTABLES -A INPUT -p TCP -i $INET_IFACE -j tcp_packets
$IPTABLES -A INPUT -p UDP -i $INET_IFACE -j udpincoming_packets
$IPTABLES -A INPUT -p ICMP -i $INET_IFACE2 -j icmp_packets
$IPTABLES -A INPUT -p TCP -i $INET_IFACE2 -j tcp_packets
$IPTABLES -A INPUT -p UDP -i $INET_IFACE2 -j udpincoming_packets

#
# Rules for special networks not part of the Internet
#

$IPTABLES -A INPUT -p ALL -i $LAN_IFACE -d $LAN_BCAST_ADRESS -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LO_IFACE -s $LO_IP -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LO_IFACE -s $LAN_IP -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LO_IFACE -s $INET_IP -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LO_IFACE -s $INET_IP2 -j ACCEPT
$IPTABLES -A INPUT -p ALL -i $LAN_IFACE -s $LAN_IP_RANGE -j ACCEPT
$IPTABLES -A INPUT -p ALL -d $INET_IP -m state --state
ESTABLISHED,RELATED \
-j ACCEPT
$IPTABLES -A INPUT -p ALL -d $INET_IP2 -m state --state
ESTABLISHED,RELATED \
-j ACCEPT
$IPTABLES -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
--log-level DEBUG --log-prefix "IPT INPUT packet died: "

###############################
# OUTPUT chain
#
#
# Bad TCP packets we don't want.
#

$IPTABLES -A OUTPUT -p tcp -j bad_tcp_packets

#
# Special OUTPUT rules to decide which IP's to allow.
#

$IPTABLES -A OUTPUT -p ALL -s $LO_IP -j ACCEPT
$IPTABLES -A OUTPUT -p ALL -s $LAN_IP -j ACCEPT
$IPTABLES -A OUTPUT -p ALL -s $INET_IP -j ACCEPT
$IPTABLES -A OUTPUT -p ALL -s $INET_IP2 -j ACCEPT

#
# Log weird packets that don't match the above.
#

$IPTABLES -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
--log-level DEBUG --log-prefix "IPT OUTPUT packet died: "

#
# Accept the packets we actually want to forward
#

echo "Setting new forward rules..."


$IPTABLES -A FORWARD -i $LAN_IFACE -j ACCEPT
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

#Permit forward in firewall
$IPTABLES -A FORWARD -i eth0 -o eth1 -p tcp -d $CITRIX_SERVER --dport
1494 -j ACCEPT
$IPTABLES -A FORWARD -i eth0 -o eth1 -p tcp -d $IIS_SERVER --dport 443
-j ACCEPT
$IPTABLES -A FORWARD -i eth0 -o eth1 -p udp -d $CITRIX_SERVER --dport
1604 -j ACCEPT
$IPTABLES -A FORWARD -i eth2 -o eth1 -p tcp -d $CSG_SERVER --dport 443
-j ACCEPT



#$IPTABLES -A FORWARD -i eth0 -o eth2 -j ACCEPT
#$IPTABLES -A FORWARD -i eth2 -o eth0 -j ACCEPT



#DNAT
$IPTABLES -t nat -A PREROUTING -i eth0 -p tcp -d $INET_IP --dport 1494
-j DNAT --to $CITRIX_SERVER
$IPTABLES -t nat -A PREROUTING -i eth0 -p tcp -d $INET_IP --dport 443
-j DNAT --to $IIS_SERVER
$IPTABLES -t nat -A PREROUTING -i eth0 -p udp -d $INET_IP --dport 1604
-j DNAT --to $CITRIX_SERVER
$IPTABLES -t nat -A PREROUTING -i eth2 -p tcp -d $INET_IP2 --dport 443
-j DNAT --to $CSG_SERVER

# Logging
$IPTABLES -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG
--log-level DEBUG --log-prefix "IPT FORWARD packet died: "

echo "FIREWALL loaded!"
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ip forwarding and iptables Angel Tsankov Linux Networking 1 05-17-2006 01:01 AM
IPtables logging failure (multiple NICs) 3strands@gmail.com Linux Networking 2 03-14-2006 03:23 AM
Forwarding with iptables crancran@gmail.com Linux Networking 0 02-18-2006 03:56 PM
3 nics in linux box (iptables) Jeremy Linux Networking 6 05-05-2005 02:50 PM
Forwarding of multicast packets between two subnets with two NICS - Does not work smshahriar@gmail.com Linux Networking 1 04-26-2005 10:54 AM



1 2 3 4 5 6 7 8 9 10 11