• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 741
  • Last Modified:

Two Networks With Single Gateway

Hi, I am beginner to Linux need experts advise. I have two networks

CentoS 5

LAN A 192.168.1.0
LAN B 192.168.2.0

eth0: ISP IP Address
eth1: 192.168.2.254

Linux is setup with transparent squid and squidGuard

I want both the LANs to communicate with each other and also i need the internet through Linux on 192.168.1.0 LAN A Network

What do i need to do in order to ping both the networks and use 192.168.2.254 Linux Box as a gateway on both the networks?
0
Cherukuri30
Asked:
Cherukuri30
1 Solution
 
Cherukuri30Author Commented:
Current iptables script

# squid server IP
SQUID_SERVER="192.168.2.254"
# Interface connected to Internet
INTERNET="eth0"
# Interface connected to LAN
LAN_IN="eth1"
# Squid port
SQUID_PORT="3128"

# DO NOT MODIFY BELOW
# Clean old firewall
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
# Load IPTABLES modules for NAT and IP conntrack support
modprobe ip_conntrack
modprobe ip_conntrack_ftp
# For win xp ftp client
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT
# set this system as a router for Rest of LAN
iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables --append FORWARD --in-interface $LAN_IN -j ACCEPT
# unlimited access to LAN
iptables -A INPUT -i $LAN_IN -j ACCEPT
iptables -A OUTPUT -o $LAN_IN -j ACCEPT
# DNAT port 80 request comming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT
# if it is same system
iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT
0
 
Cyclops3590Commented:
first off you want to create an alias on the eth1 interface so that your server can be a gateway on the .1.x lan.

in the /etc/sysconifg/network-scripts directory copy the ifcfg-eth1 and make a ifcfg-eth1:1 file
then edit that file with the IP information needed to be in the 1.x lan

next you'll need to update your iptables script.

you'll need to add I the following (granted the interface IP you use is 192.168.1.254 for the eth1:1 alias interface.  

LAN_IN2="eth1:1"
SQUID_SERVER2="192.168.1.254"
iptables --append FORWARD --in-interface $LAN_IN2 -j ACCEPT
iptables -A INPUT -i $LAN_IN2 -j ACCEPT
iptables -A OUTPUT -o $LAN_IN2 -j ACCEPT
iptables -t nat -A PREROUTING -i $LAN_IN2 -p tcp --dport 80 -j DNAT --to $SQUID_SERVER2:$SQUID_PORT

Also, this doesn't allow traffic between the two lans so if you want that you'll need to add the appropriate FORWARD chain entries
iptables -A FORWARD -i $LAN_IN2 -o $LAN_IN -j ACCEPT
iptables -A FORWARD -i $LAN_IN -o $LAN_IN2 -j ACCEPT
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now