Step and syntax of squid transparent proxy-Linux Enterprise Application-Linux server application information. The following is a detailed description. Steps and syntax of squid transparent proxy
[Root@CentOS5.1] # fuqin Liquor
1) edit the squid configuration file and add
Httpd_accel_host virtual // because there are many Internet hosts to be accessed, virtual is the virtual host. virtual specifies the virtual host mode. In this mode, squid is used to cancel the cache and ICP functions.
Httpd_accel_port 80 // port of the accelerated host
Httpd_accel_with_proxy on // After the option is defined as on, squid is both a Web Request accelerator and a cache Proxy Server
Httpd_accel_uses_host_header // After the option is defined as on, the host header is used for the host to be accessed, that is, the host header is used to distinguish different hosts. This is also required for transparent generation configuration.
2) use iptables to configure port redirection on the Proxy Server
# Echo "1">/proc/sys/net/ipv4/ip_forward // Let the traffic flow between different NICs
3) The client gateway must be configured with the Intranet IP address of the squid server. The DNS configuration is correct. In addition, the DNS can also be set to intelligent DNS by iptables to reduce the workload of the client.
TIPS:
1. Squid does not support enabling user identity authentication in transparent proxy Mode
2. transparent proxy is the perfect combination of NAT and proxy. It is worth noting that transparent proxy is used because the browser does not make any settings. When a client accesses a foreign website through a domain name, first, you can use the DNS server to query the IP address corresponding to the abnormal name before sending a web service request to the linux host. Therefore, the client must correctly set the DNS server.
3. If you only need to configure a simple forward proxy service, the client only needs to configure the gateway to access the Internet through the squid proxy. This is different from transparent proxy.
Appendix:
Squid transparent proxy instance (Ubuntu8.04, from the Ubuntu Forum)
This is a simple instance configuration, mainly to record the process of learning squid by yourself, hope to help new users!
Squid is a well-known Agent service software in linux. It is mainly used to block Intranet machines, proxy surfing, and control Intranet access rules.
I use the long-term support version of The ubuntu8.04 server and the dial-up ppp0.
Bytes ------------------------------------------------------------------------------------
W3m, zhcon, pppoe, sysv-rc-conf, nmap, and vim tools
W3m)
Zhcon: However, the plug-in is installed when it finds that Chinese characters are not supported and all characters are garbled. Zhcon
Sudo apt-get install zhcon Chinese plug-ins support terminal character installation interface (if a black screen crashes, check the network, it is easy to solve)
After starting zhcon, enter w3m http://www.baidu.com to see the Baidu interface, (the premise is to connect to the network)
Pppoe: If you use adsl, you can use the pppoeconf command to configure the dial-up Internet function (note that usrname is your dial-up user name)
Sysv-rc-conf: apt can be installed for software related to services and will be used later.
Nmap: Port viewing software. You can view the ports enabled by the NIC, and apt can install
Vim: comes with text editing software. It is best to use vim in ubuntu8.04, instead of vi, at least on my machine.
Note: The w3m encoding in 8.04 is incorrect. You can modify it in the last two sentences of/etc/w3m. conf. Otherwise, the network industry is still garbled.
-------------------------------------------------------------------------------
Start to install squid. You can download and compile it yourself, or use the source to install it.
Sudo apt-get install squid
Bytes ---------------------------------------------------------------------------------------
After installation, configure your Nic first.
My Nic configuration: Dual Nic, eth0 is external Nic, eth1 is internal Nic ip: 192.168.0.1/255.255.255.0
Add sudo vi/etc/network/interfaces (eth0 is not required for dynamic adsl configuration)
Eth1
Iface eth1 inet static
Address 192.168.0.1
Netmask 255.255.255.0
Network 192.168.0.1
Broadcast 192.168.0.255
(Restart is required to take effect)
After configuring the NIC, run ifconfig | more to view all Nic configurations.
Bytes ------------------------------------------------------------------------------------------------
Configure squid below:
The ubuntu version after apt is installed is 2.06, which is very different from the previous version.
After the squid is installed, You need to configure it. By default, no user proxy is allowed.
You need to modify the configuration file/etc/squid. conf.
Run sudo vi/etc/squid. conf to open the file.
The main configuration is:
1: Listener port configuration at the beginning
Use the/http_port/command in vi to find
You can use either a single port or an ip address or port. If you need to configure a transparent proxy, you need to add transparent.
For example, my: http_port 192.168.0.1: 3128 transparent. For example and introduction, E is easy to understand!
2: log and cache configuration,
Use/cache_dir/in vi to find
Cache_dir ufs/home/xyz/squid/cache 100 16 256 (this is my configuration)
Indicates the location of the cache directory. Size. Number of first-level directories. Number of second-level directories.
The directory size can be set as needed. The number of directories is 100 MB, 16 level-1 directories, and 100 level-2 directories.
Note that the local file directory you set must exist and must be created by yourself if it does not exist.
For example, you need to first create the squid directory in/home/xyz/, and then create the cache directory.
Main Commands include cd and mkdir (create directory) and rm (delete)
After the file is created, run the ls-l (lower-case L, not 1) command to view the file permissions,
Permission setting must enable the user group set in squid to rwx (read, write, and execute)
We recommend that you specify directories for these caches, for example,/home/xyz/squid.
(Cache. log, access. log, and store. log are all log files, which are useful in cache. log debugging.
Access. log stores user access records. store. log is useless and can be disabled)
3: Access Control Configuration:
Use the/cal/command to find
Cal network src 192.168.0.0/24 (the member with the name of network defined as 192.168.0.1-192.168.0.254)
Http_access allow network (allow access by network members)
It should be noted that there must be no sequential error between defining members and allowing access by members. It must be defined first and under control,
Http_access allow network must be written in the front of http_access deny All.
For specific access control, you can check the information.
4: Access Control of cache
Use the command:/cache_effective/to find
Cache_inclutive_user xyz (accessible user)
Cache_inclutive_group xyz (group to be accessed)
Here is why the cache directory permission needs to be set. Here is my settings. For more information, see
Xyz is a common user who replaces root. It belongs to the xyz group and sets the cache directory owner and group to xyz.
Sudo chown-R xyz. xyz/home/xyz/squid/cache, and then grant the owner and group rwx Permissions
Chmod ug + rwx/home/xyz/squid/cache.
5: visiable hostname (the spelling may be wrong. I wrote it under win, but I cannot remember it clearly)
Also use the command:/visiable hostname/to find
Define a name by yourself!
6: For dns, If you do not configure a transparent proxy, find the dns parameters in the configuration file.
Basically, the squid configuration is complete. Let's test it.
Run the following command: squid-z (create cache file directory architecture: level-1 cache directory and level-2 cache directory, which must be executed)
Squid-NCd1 (start squid in debug mode, debugging error)
You can also use: squid-k parse (this command proves that there is no configuration file and no syntax error if no message is prompted)
After debugging, you can use the command squid-s to change to the service daemon process. That is to say, it is automatically started upon startup, or you can use the sysv-rc-conf tool (download required)
The following figure shows whether the agent is feasible during client debugging. the ip address of the client is 192.168.0.xx, The subnet mask is 255.255.255.0, And the gateway is 192.168.0.1.
Dns.
Set the proxy 192.168.0.1: 3128 in the browser, and then test. If you can, configure the transparent proxy.
Bytes -----------------------------------------------------------------------------------------------------
Iptable settings:
Create a file named firewall under/etc/
Command: sudo touch/etc/firewall
Add the x permission to the root user of firewall.
Sudo chmod u + x/etc/firewall
Then enter the sudo vi/etc/rc. local file and add the/etc/firewall statement before the last sentence,
Start the firewall File Script
Firewall file content:
# Add required modules
Modprobe ip_tables
Modprobe iptable_nat
Modprobe iptable_filter
Modprobe ip_conntrack_ftp
Modprobe ip_nat_ftp
# Enable ip forwarding to allow data packets to flow between NICs
Echo "1">/proc/sys/net/ipv4/ip_forward
# Forward all udp and tcp requests destined for port 53 to the Internet DNS server address. Here is my DNS address: 61.232.202.158. Change it to yours.
Iptables-t nat-a prerouting-p udp -- dport 53-j DNAT -- to 61.232.202.158
Iptables-t nat-a prerouting-p tcp -- dport 53-j DNAT -- to 61.232.202.158
# Forward all requests destined for port 80 to port 3128 for squid to process
Iptables-t nat-a prerouting-I eth1-p tcp-m tcp -- dport 80-j REDIRECT -- to-port 3128
# Spoofing eth0. If it is ppp0, it will be replaced by-o ppp0
Iptables-t nat-a postrouting-o eth0-j MASQUERADE
I wish you a successful conclusion !!!
From http://hi.baidu.com/yuhongchun027/blog/category/squid%C6%AA
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