Iptables + squid implementation of transparent proxy for multiple network segments

Source: Internet
Author: User
The implementation of Iptables + squid multi-network segment transparent proxy-Linux Enterprise Application-Linux server application information. The following is a detailed description. First, let's introduce my test environment:
Proxy Server:
OS: RedHat Enterprise LINUX AS 4.0.
Proxy Server Version: squid-2.5.STABLE6-3.4E.5 (built-in)

Nic settings
Eth0: 192.168.0.133 (connecting to the Internet)
Eth1: 192.168.1.254 (connecting to intranet)
Router: (mainly used to connect the communication between subnets in the Intranet. I use LINUX as a soft route .)
)
OS: RedHat Enterprise LINUX AS 4.0

Nic settings:
Eth0: 192.168.1.1
Eth1: 192.168.2.1
Client:
Client-1:
OS: Windows 2000 Professional

Nic settings:
IP address: 192.168.1.111
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DNS: 61.144.56.100
Client-2
OS: Windows XP Professional
IP address: 192.168.2.120
Netmask: 255.255.255.0
Gateway: 192.168.2.1
DNS: 61.144.56.100

Purpose of this test:
1. implement transparent proxy for multiple network segments
2. You can use the transparent proxy of Squid + Iptables to send and receive emails from the Internet mailbox using OE on the client.
II. Specific settings
Proxy Server Configuration
1. Squid Configuration
Http_port 3128
Hierarchy_stoplist cgi-bin?
Hierarchy_stoplist-I ^ https :\\?
Acl QUERY urlpath_regex-I cgi-bin \? \. Asp \. php \. jsp \. cgi
Acl denyssl urlpath_regex-I ^ https :\\
No_cache deny QUERY
No_cache deny denyssl
Cache_mem 24 MB
Cache_swap_low 90
Cache_swap_high 95
Maximum_object_size 4096 KB
Maximum_object_size_in_memory 8 KB
Ipcache_size 1024
Ipcache_low 90
Ipcache_high 95
Fqdncache_size 1024
Cache_dir aufs/usr/local/squid/var/cache1 100 16 256
Cache_dir aufs/usr/local/squid/var/Cache2 200 16 256
Access_log/usr/local/squid/var/logs/access. log squid
Cache_log/usr/local/squid/var/logs/cache. log
Cache_store_log/usr/local/squid/var/logs/store. log
Pid_filename/usr/local/squid/var/logs/squid. pid
Ftp_user Squid @
Ftp_passive on
Refresh_pattern ^ ftp: 1440 20% 10080

Refresh_pattern ^ gopher: 1440 0% 1440
Refresh_pattern. 0 20% 4320
Connect_timeout 1 minute
Peer_connect_timeout 30 seconds
Request_timeout 2 minutes
Persistent_request_timeout 1 minute
Cache_mgr webmaster @ localhost
Cache_inclutive_user squid
Cache_paitive_group squid
Visible_hostname redhat
* The following four lines are the key to transparent proxy ************* ****\
Httpd_accel_host virtual
Httpd_accel_port 80
Httpd_accel_with_proxy on
Httpd_accel_uses_host_header on

2. iptables configuration
The following is a script I wrote: The Script Name is firewall (you can also set the name according to your preferences, save it with the VI editor compiler, and set the file attributes to executable, use the chmod 777 firewall command (this is just an example and can be changed as needed) to change the file attributes to executable files)
#! /Bin/bash
Echo "enable ip forwarding"
# Enable route forwarding
Echo "1">/proc/sys/net/ipv4/ip_forward
# Modules required to load IPTABLES
Echo "starting iptables rules"
/Sbin/modprobe iptable_fileter
/Sbin/modprobe ip_tables
/Sbin/modprobe iptables_nat
/Sbin/modprobe ip_conntrack_ftp
/Sbin/modprobe ip_nat_ftp
# Refresh the IPTABLES rule chain
/Sbin/iptables? F
/Sbin/iptables? X
/Sbin/iptables? Z
/Sbin/iptables? F? T nat
/Sbin/iptables? X? T nat
/Sbin/iptables? Z? T nat
# All traffic destined for port 80 from eth1 is forwarded to the default port 3128 of the proxy server.
/Sbin/iptables? T nat? A prerouting? I eth1? P tcp? Dport 80? J REDIRECT? To-ports 3128.
# Disguise outbound access IP addresses
/Sbin/iptables? T nat? A postrouting? S 192.168.1.0/24? O eth0? J MASQUERADE
/Sbin/iptables? T nat? A postrouting? S 192.168.2.0/24? O eth0? J MASQUERADE
Route settings of the proxy server
# Add a route entry to the 192.168.2.0 network on the squid server. The Gateway is 192.168.1.1.
Route add? Net 192.168.2.0/24 gw 192.168.1.1

Ii. vro settings
/******************** Enable the route forwarding function ************** ****\
# Echo 1>/proc/sys/net/ipv4/ip_forward
The original default route of the vro is 0.0.0.0 0.0.0.0 192.168.1.1. Delete the route and add another default route:
Route add default gw 192.168.1.254
After some transparent proxy settings for multiple network segments are completed, the client can now perform a test to view the webpage normally and send and receive emails after the customer sets OE, I tested it using sina and 21cn mailboxes. I don't know what's going on in the 163 mailbox. When sending and receiving emails, an authentication box will always pop up, asking me to re-enter the password, however, I still cannot enter the password. I suspect it is the cause of 163 servers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.