From: Subject: Re: NAT and test ip's for link Date: Tue, 18 Feb 2003 13:46:39 +0200 Sender: netfilter-admin@lists.netfilter.org Message-ID: <005e01c2d743$68265b00$01000001@mfa.ee> References: <001001c2d68a$0fc736a0$01000001@mfa.ee> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_005B_01C2D754.29DEB0C0" Return-path: Errors-To: netfilter-admin@lists.netfilter.org List-Help: List-Post: List-Subscribe: , List-Id: List-Unsubscribe: , List-Archive: To: netfilter@lists.netfilter.org This is a multi-part message in MIME format. ------=_NextPart_000_005B_01C2D754.29DEB0C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I figured it out. =20 $IPTABLES -t nat -A POSTROUTING -o $EXTIF -s $INTLAN -j SNAT --to = $EXTIP =20 postrouting chain should just look like this: =20 $IPTABLES -t nat -A POSTROUTING -o $LINKIF -s $INTLAN -j SNAT --to = $EXTIP =20 Outgoing interface must be changed. ----- Original Message -----=20 From: vmtesting@hot.ee=20 To: netfilter@lists.netfilter.org=20 Sent: Monday, February 17, 2003 3:39 PM Subject: NAT and test ip's for link hi, I have firewall box with Redhat 8.0 (kernel 2.4.18-24.8.0) and = iptables v1.2.6a installed and 8 public ip addresses ,let's say 195.12.1.0/29. My firewall box has 3 NIC's. eth1(195.12.1.1)----FW-----eth2 (192.168.1.2)-----Cisco ---INTERNET | | eth0(10.3.1.1) Behind eth0 I have planned internal network of 10.3.1.0/24 Behind eth1 will be connected some public computers with no access to = internal LAN. Eth2 has a link with Cisco C1601 having test class ip's for link (192.168.1.0/24 , 192.168.1.2 at fw side and 192.168.1.1 at cisco's = side) The reason why I have test ip's for link is that I haven't got enough = public ip's to complete my plan.I have 2 servers in internal LAN. Both MUST have = separate ip's. When I divide 195.12.1.0/29 into 2 different networks = 195.12.1.0/30(eth2) and 195.12.1.4/30 I have no ip's left for internal servers. But in that case I have no trouble translating internal LAN behind = eth0 to eth2. My problem is that I don't know how to translate internal LAN to eth1 = when I have test ip's for link at eth2.Being more specific I have no idea how = accomplish it with Linux. For Cisco IOS following should work: interface Ethernet1 ip address 195.12.1.1 255.255.255.248 no ip directed-broadcast ip nat outside ! interface Serial0 ip address 192.168.1.1 255.255.255.0 no ip directed-broadcast ip nat outside ! ip nat inside source list 1 interface Ethernet1 overload ip classless ! access-list 1 permit 10.3.1.0 0.0.0.255 Has anyone implemented similar solution and know's how to translate = LAN to public ip at eth1 (195.12.1.1) while eth2 with test class ip's is connected to Internet ? Thanks, vmtesting FW box routing table: Kernel IP routing table Destination Gateway Genmask Flags Metric Ref = Use Iface 195.12.1.0 0.0.0.0 255.255.255.248 U 0 0 = 0 eth1 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 = 0 eth2 10.3.0.0 0.0.0.0 255.255.255.0 U 0 0 = 0 eth0 127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 = 0 lo 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 = 0 eth2 IPtables truncated script for NAT: #!/bin/sh # This is the location of the iptables command IPTABLES=3D"/sbin/iptables" case "$1" in stop) echo "Shutting down firewall..." $IPTABLES -F $IPTABLES -F -t mangle $IPTABLES -F -t nat $IPTABLES -X $IPTABLES -X -t mangle $IPTABLES -X -t nat =20 $IPTABLES -P INPUT ACCEPT $IPTABLES -P OUTPUT ACCEPT $IPTABLES -P FORWARD ACCEPT echo "...done" ;; status) echo $"Table: filter" iptables --list echo $"Table: nat" iptables -t nat --list echo $"Table: mangle" iptables -t mangle --list ;; restart|reload) $0 stop $0 start ;; start) echo "Starting Firewall..." echo "" ##--------------------------Begin = Firewall---------------------------------## #----Default-Interfaces-----# LINKIF=3D"eth2" EXTIF=3D"eth1" INTIF=3D"eth0" INTLAN=3D"10.3.1.0/255.255.255.0" INTIP=3D"10.3.1.1" INTMASK=3D"255.255.255.0" EXTIP=3D"195.12.1.1" $IPTABLES -F $IPTABLES -F -t nat $IPTABLES -X $IPTABLES -X -t mangle $IPTABLES -X -t nat $IPTABLES -P INPUT ACCEPT $IPTABLES -P OUTPUT ACCEPT $IPTABLES -P FORWARD ACCEPT ################### ## POSTROUTING ## ################### #Masquerade from Internal Net to External Net =20 $IPTABLES -t nat -A POSTROUTING -o $EXTIF -s $INTLAN -j SNAT --to = $EXTIP =20 =20 #------End Ruleset------# echo "...done" echo "" echo "{>o-< IPTABLES firewall activated :-))" ##--------------------------------End = Firewall---------------------------------## ;; *) echo "Usage: firewall (start|stop|restart|status) EXTIF INTIF" exit 1 esac exit 0 ------=_NextPart_000_005B_01C2D754.29DEB0C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I figured it out.
  
  $IPTABLES -t nat = -A=20 POSTROUTING -o $EXTIF -s $INTLAN  -j SNAT --to=20 $EXTIP
 
postrouting chain should just look like = this:

  
  $IPTABLES -t nat -A POSTROUTING -o = $LINKIF -s=20 $INTLAN  -j SNAT --to $EXTIP
 
Outgoing=20 interface must be changed.
 
----- Original Message -----
From:=20 vmtesting@hot.ee=20
To: netfilter@lists.netfilter.o= rg=20
Sent: Monday, February 17, 2003 = 3:39=20 PM
Subject: NAT and test ip's for = link

hi,
 
I have firewall box with  Redhat 8.0 (kernel 2.4.18-24.8.0) = and=20 iptables v1.2.6a
installed and 8 public ip addresses ,let's say=20 195.12.1.0/29.
 
My firewall box has 3 NIC's.
 

eth1(195.12.1.1)----FW-----eth2 (192.168.1.2)-----Cisco=20 ---INTERNET
           =             =    =20    |
         =20             =    =20     |
      =20             =20 eth0(10.3.1.1)
 

Behind eth0 I have planned internal network of = 10.3.1.0/24
Behind=20 eth1 will be connected some public computers with no access to = internal=20 LAN.
Eth2 has a link with Cisco C1601 having test class ip's for=20 link
(192.168.1.0/24 , 192.168.1.2 at fw side and 192.168.1.1 at = cisco's=20 side)
 
The reason why I have test ip's for link is that I haven't got = enough=20 public ip's to
complete my plan.I have 2 servers in internal LAN. = Both MUST=20 have separate ip's.
 
When I divide 195.12.1.0/29 into 2 different networks=20 195.12.1.0/30(eth2)
and 195.12.1.4/30 I have no ip's left for = internal=20 servers.
But in that case  I have no trouble translating = internal LAN=20 behind eth0 to eth2.
 
My problem is that I don't know how to translate internal LAN to = eth1=20 when I have
test ip's for link at eth2.Being more specific I have = no idea=20 how accomplish it with
Linux. For Cisco IOS following should = work:
 
interface Ethernet1
 ip address 195.12.1.1=20 255.255.255.248
 no ip directed-broadcast
 ip nat=20 outside
!
interface Serial0
 ip address 192.168.1.1=20 255.255.255.0
 no ip directed-broadcast
 ip nat=20 outside
!
ip nat inside source list 1 interface Ethernet1 = overload
ip=20 classless
!
access-list 1 permit 10.3.1.0 0.0.0.255
 
Has anyone implemented similar solution and know's how to = translate=20 LAN
to public ip at eth1 (195.12.1.1) while eth2 with test class = ip's
is=20 connected to Internet ?
 
Thanks,
vmtesting
 
FW box routing table:
 
Kernel IP routing table
Destination    =20 Gateway        =20 Genmask         Flags Metric=20 Ref    Use = Iface
195.12.1.0     =20 0.0.0.0         = 255.255.255.248=20 U     0     =20 0        0=20 eth1
192.168.1.0    =20 0.0.0.0        =20 255.255.255.0   U    =20 0      = 0        0=20 eth2
10.3.0.0       =20 0.0.0.0        =20 255.255.255.0   U    =20 0      = 0        0=20 eth0
127.0.0.0      =20 0.0.0.0        =20 255.0.0.0       = U    =20 0      = 0        0=20 lo
0.0.0.0        =20 192.168.1.1    =20 0.0.0.0         = UG   =20 0      = 0        0=20 eth2
 
IPtables truncated script for NAT:
 
#!/bin/sh
 
# This is the location of the iptables=20 command
IPTABLES=3D"/sbin/iptables"
 

case "$1" in
   = stop)
     =20 echo "Shutting down firewall..."
      = $IPTABLES=20 -F
      $IPTABLES -F -t=20 mangle
      $IPTABLES -F -t=20 nat
      $IPTABLES=20 -X
      $IPTABLES -X -t=20 mangle
      $IPTABLES -X -t=20 nat
      =
     =20 $IPTABLES -P INPUT ACCEPT
      $IPTABLES = -P=20 OUTPUT ACCEPT
      $IPTABLES -P FORWARD=20 ACCEPT
      echo=20 "...done"
      ;;
  =20 status)
      echo $"Table:=20 filter"
      iptables=20 --list
      echo $"Table:=20 nat"
      iptables -t nat=20 --list
      echo $"Table:=20 mangle"
      iptables -t mangle=20 --list
      ;;
  =20 restart|reload)
      $0=20 stop
      $0=20 start
      ;;
  =20 start)
    echo "Starting = Firewall..."
   =20 echo ""
 

##--------------------------Begin=20 Firewall---------------------------------##
 

#----Default-Interfaces-----#
 

LINKIF=3D"eth2"
 

EXTIF=3D"eth1"
 

INTIF=3D"eth0"
 
=
INTLAN=3D"10.3.1.0/255.255.255.0"
INTIP=3D"10.3.1.1"
INTMASK=3D= "255.255.255.0"
EXTIP=3D"195.12.1.1"
 
$IPTABLES -F
$IPTABLES -F -t nat
$IPTABLES -X
$IPTABLES = -X -t=20 mangle
$IPTABLES -X -t nat
 
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT = ACCEPT
$IPTABLES -P=20 FORWARD ACCEPT
 
###################
##  POSTROUTING =20 ##
###################
 
  #Masquerade from Internal Net to External Net
  =
 =20 $IPTABLES -t nat -A POSTROUTING -o $EXTIF -s $INTLAN  -j SNAT = --to=20 $EXTIP
 
 
#------End Ruleset------#
 
echo "...done"
echo ""
 

echo "{>o-< IPTABLES firewall activated :-))"
 

##--------------------------------End=20 Firewall---------------------------------##
 
 
 
   ;;
   = *)
      echo=20 "Usage: firewall (start|stop|restart|status) EXTIF=20 INTIF"
      exit 1
esac
 
exit 0
 
 
------=_NextPart_000_005B_01C2D754.29DEB0C0--