1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Draft//EN">
<HTML>
<HEAD>
<TITLE>SQUID Frequently Asked Questions: Transparent Caching/Proxying</TITLE>
</HEAD>
<BODY>
<A HREF="FAQ-18.html">Next</A>
<A HREF="FAQ-16.html">Previous</A>
<A HREF="FAQ.html#toc17">Contents</A>
<HR>
<H2><A NAME="trans-caching"></A> <A NAME="s17">17. Transparent Caching/Proxying</A></H2>
<P><I>How can I make my users' browsers use my cache without configuring
the browsers for proxying?</I>
<P>First, it is <EM>critical</EM> to read the full comments in the squid.conf
file! That is the only authoritative source for configuration
information. However, the following instructions are correct as of
this writing (July 1999.)
<P>
<P>Getting transparent caching to work requires four distinct steps:
<OL>
<LI>
<B>Get the packets to your cache server</B>. There are several
ways to do this. First, if your proxy machine is already in
the path of the packets (i.e. it is routing between your proxy
users and the Internet) then you don't have to worry about this
step. This would be true if you install Squid on a firewall
machine, or on a UNIX-based router. If the cache is not in the
natural path of the connections, then you have to divert the
packets from the normal path to your cache host using a router
or switch. You may be able to do this with a Cisco router using
their "route maps" feature, depending on your IOS version. You
might also use a so-called layer-4 switch, such as the Alteon
ACE-director or the Foundry Networks ServerIron. Finally, you
might be able to use a stand-alone router/load-balancer type
product, or routing capabilities of an access server.
</LI>
<LI>
<B>Get your cache server to accept the packets</B>. You have to
configure your cache host to accept the redirected packets -
any IP address, on port 80 - and deliver them to your cache
application. This is typically done with IP
filtering/forwarding features built into the kernel. On linux
they call this <EM>ipfwadm</EM>. On FreeBSD and other
*BSD systems they call it <EM>ip filter</EM> or <EM>ipnat</EM>; on many
systems, it may require rebuilding the kernel or adding a new
loadable kernel module.
</LI>
<LI>
<B>Compile and run a version of Squid which accepts
connections for other addresses</B>. For some operating systems,
you need to have configured and built a version of Squid which
can recognize the hijacked connections and discern the
destination addresses. For Linux this seems to work
automatically. For *BSD-based systems, you probably have to
configure squid with the <EM>--enable-ipf-transparent</EM> option.
(Do a <EM>make clean</EM> if you previously configured without that
option, or the correct settings may not be present.)
</LI>
<LI>
<B>Configure Squid to accept and process the connections</B>.
Finally, you have to change the Squid configuration settings to
recognize the hijacked connections and discern the destination
addresses. Here are the important settings in <EM>squid.conf</EM>:
<PRE>
http_port 8080
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
</PRE>
</LI>
</OL>
<P><B>Notes</B>:
<UL>
<LI>The <EM>http_port 8080</EM> in this example assumes you will redirect
incoming port 80 packets to port 8080 on your cache machine. If you
are running Squid on port 3128 (for example) you can leave it there via
<EM>http_port 3128</EM>, and redirect to that port via your IP filtering or
forwarding commands.
</LI>
<LI>In the <EM>httpd_accel_host</EM> option, <EM>virtual</EM> is the magic word!
</LI>
<LI>The <EM>httpd_accel_with_proxy on</EM> is required to enable transparent
proxy mode; essentially in transparent proxy mode Squid thinks it is acting
both as an accelerator (hence accepting packets for other IPs on port 80) and
a caching proxy (hence serving files out of cache.)
</LI>
<LI> You <B>must</B> use <EM>httpd_accel_uses_host_header on</EM> to get
the cache to work properly in transparent mode. This enables the cache
to index its stored objects under the true hostname, as is done in a
normal proxy, rather than under the IP address. This is especially
important if you want to use a parent cache hierarchy, or to share
cache data between transparent proxy users and non-transparent proxy
users, which you can do with Squid in this configuration.
</LI>
</UL>
<P>
<H2><A NAME="ss17.1">17.1 Transparent caching for Solaris, SunOS, and BSD systems</A>
</H2>
<H3>Install IP Filter</H3>
<P>First, get and install the
<A HREF="ftp://coombs.anu.edu.au/pub/net/ip-filter/">IP Filter package</A>.
<P>
<H3>Configure ipnat</H3>
<P>Put these lines in <EM>/etc/ipnat.rules</EM>:
<PRE>
# Redirect direct web traffic to local web server.
rdr de0 1.2.3.4/32 port 80 -> 1.2.3.4 port 80 tcp
# Redirect everything else to squid on port 8080
rdr de0 0.0.0.0/0 port 80 -> 1.2.3.4 port 8080 tcp
</PRE>
<P>
<P>Modify your startup scripts to enable ipnat. For example, on FreeBSD it
looks something like this:
<PRE>
/sbin/modload /lkm/if_ipl.o
/sbin/ipnat -f /etc/ipnat.rules
chgrp nobody /dev/ipnat
chmod 644 /dev/ipnat
</PRE>
<P>
<H3>Configure Squid</H3>
<H3>Squid-2</H3>
<P>Squid-2 (after version beta25) has IP filter support built in.
Simple enable it when you run <EM>configure</EM>:
<PRE>
./configure --enable-ipf-transparent
</PRE>
Add these lines to your <EM>squid.conf</EM> file:
<PRE>
http_port 8080
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
</PRE>
Note, you don't have to use port 8080, but it must match whatever you
used in the <EM>/etc/ipnat.rules</EM> file.
<H3>Squid-1.1</H3>
<P>Patches for Squid-1.X are available from
<A HREF="http://www.fan.net.au/~q/squid/">Quinton Dolan's Squid page</A>.
Add these lines to <EM>squid.conf</EM>:
<PRE>
http_port 8080
httpd_accel virtual 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
</PRE>
<P>
<P>Thanks to
<A HREF="mailto:q@fan.net.au">Quinton Dolan</A>.
<P>
<H2><A NAME="trans-linux-1"></A> <A NAME="ss17.2">17.2 Transparent caching with Linux</A>
</H2>
<P>by
<A HREF="mailto:Rodney.van.den.Oever@tip.nl">Rodney van den Oever</A><P>
<P><B>Note:</B> Transparent proxying does NOT work with Linux 2.0.30!
Linux 2.0.29 is known to work well. If you're using a more recent
kernel, like 2.2.X, then you should probably use an ipchains configuration,
<A HREF="#trans-linux-2">as described below</A>.
<P>
<P><B>Warning:</B> this technique has some shortcomings.
<OL>
<LI><B>This method only supports the HTTP protocol, not gopher or FTP</B></LI>
<LI>Since the browser wasn't set up to use a proxy server, it uses
the FTP protocol (with destination port 21) and not the required
HTTP protocol. You can't setup a redirection-rule to the proxy
server since the browser is speaking the wrong protocol. A similar
problem occurs with gopher. Normally all proxy requests are
translated by the client into the HTTP protocol, but since the
client isn't aware of the redirection, this never happens.</LI>
</OL>
<P>
<P>If you can live with the side-effects, go ahead and compile your
kernel with firewalling and redirection support. Here are the
important parameters from <EM>/usr/src/linux/.config</EM>:
<P>
<PRE>
#
# Code maturity level options
#
CONFIG_EXPERIMENTAL=y
#
# Networking options
#
CONFIG_FIREWALL=y
# CONFIG_NET_ALIAS is not set
CONFIG_INET=y
CONFIG_IP_FORWARD=y
# CONFIG_IP_MULTICAST is not set
CONFIG_IP_FIREWALL=y
# CONFIG_IP_FIREWALL_VERBOSE is not set
CONFIG_IP_MASQUERADE=y
CONFIG_IP_TRANSPARENT_PROXY=y
CONFIG_IP_ALWAYS_DEFRAG=y
# CONFIG_IP_ACCT is not set
CONFIG_IP_ROUTER=y
</PRE>
<P>
<P>You may also need to enable <B>IP Forwarding</B>. One way to do it
is to add this line to your startup scripts:
<PRE>
echo 1 > /proc/sys/net/ipv4/ip_forward
</PRE>
<P>
<P>Go to the
<A HREF="http://www.xos.nl/linux/ipfwadm/">Linux IP Firewall and Accounting</A> page,
obtain the source distribution to <EM>ipfwadm</EM> and install it.
Older versions of <EM>ipfwadm</EM> may not work. You might need
at least version <B>2.3.0</B>.
You'll use <EM>ipfwadm</EM> to setup the redirection rules. I
added this rule to the script that runs from <EM>/etc/rc.d/rc.inet1</EM>
(Slackware) which sets up the interfaces at boot-time. The redirection
should be done before any other Input-accept rule. To really make
sure it worked I disabled the forwarding (masquerading) I normally
do.
<P><EM>/etc/rc.d/rc.firewall</EM>:
<P>
<PRE>
#!/bin/sh
# rc.firewall Linux kernel firewalling rules
FW=/sbin/ipfwadm
# Flush rules, for testing purposes
for i in I O F # A # If we enabled accounting too
do
${FW} -$i -f
done
# Default policies:
${FW} -I -p rej # Incoming policy: reject (quick error)
${FW} -O -p acc # Output policy: accept
${FW} -F -p den # Forwarding policy: deny
# Input Rules:
# Loopback-interface (local access, eg, to local nameserver):
${FW} -I -a acc -S localhost/32 -D localhost/32
# Local Ethernet-interface:
# Redirect to Squid proxy server:
${FW} -I -a acc -P tcp -D default/0 80 -r 8080
# Accept packets from local network:
${FW} -I -a acc -P all -S localnet/8 -D default/0 -W eth0
# Only required for other types of traffic (FTP, Telnet):
# Forward localnet with masquerading (udp and tcp, no icmp!):
${FW} -F -a m -P tcp -S localnet/8 -D default/0
${FW} -F -a m -P udp -S localnet/8 -D default/0
</PRE>
<P>
<P>Here all traffic from the local LAN with any destination gets redirected to
the local port 8080. Rules can be viewed like this:
<PRE>
IP firewall input rules, default policy: reject
type prot source destination ports
acc all 127.0.0.1 127.0.0.1 n/a
acc/r tcp 10.0.0.0/8 0.0.0.0/0 * -> 80 => 8080
acc all 10.0.0.0/8 0.0.0.0/0 n/a
acc tcp 0.0.0.0/0 0.0.0.0/0 * -> *
</PRE>
<P>
<P>I did some testing on Windows 95 with both Microsoft Internet
Explorer 3.01 and Netscape Communicator pre-release and it worked
with both browsers with the proxy-settings disabled.
<P>
<P>At one time <EM>squid</EM> seemed to get in a loop when I pointed the
browser to the local port 80. But this could be avoided by adding a
reject rule for client to this address:
<PRE>
${FW} -I -a rej -P tcp -S localnet/8 -D hostname/32 80
IP firewall input rules, default policy: reject
type prot source destination ports
acc all 127.0.0.1 127.0.0.1 n/a
rej tcp 10.0.0.0/8 10.0.0.1 * -> 80
acc/r tcp 10.0.0.0/8 0.0.0.0/0 * -> 80 => 8080
acc all 10.0.0.0/8 0.0.0.0/0 n/a
acc tcp 0.0.0.0/0 0.0.0.0/0 * -> *
</PRE>
<P>
<P><EM>NOTE on resolving names</EM>: Instead of just
passing the URLs to the proxy server, the browser itself has to
resolve the URLs. Make sure the workstations are setup to query
a local nameserver, to minimize outgoing traffic.
<P>If you're already running a nameserver at the firewall or proxy server
(which is a good idea anyway IMHO) let the workstations use this
nameserver.
<P>
<P>Additional notes from
<A HREF="mailto:RichardA@noho.co.uk">Richard Ayres</A><P>
<BLOCKQUOTE>
<P>I'm using such a setup. The only issues so far have been that:
<P>
<OL>
<LI>It's fairly useless to use my service providers parent caches
(cache-?.www.demon.net) because by proxying squid only sees IP addresses,
not host names and demon aren't generally asked for IP addresses by other
users;
</LI>
<LI>Linux kernel 2.0.30 is a no-no as transparent proxying is broken (I use
2.0.29);
</LI>
<LI>Client browsers must do host name lookups themselves, as they don't know
they're using a proxy;
</LI>
<LI>The Microsoft Network won't authorize its users through a proxy, so I
have to specifically *not* redirect those packets (my company is a MSN
content provider).</LI>
</OL>
<P>Aside from this, I get a 30-40% hit rate on a 50MB cache for 30-40 users and
am quite pleased with the results.
</BLOCKQUOTE>
<P>
<P>See also
<A HREF="http://www.unxsoft.com/transproxy.html">Daniel Kiracofe's page</A>.
<P>
<P>
<H2><A NAME="ss17.3">17.3 Transparent caching with Cisco routers</A>
</H2>
<P>by
<A HREF="mailto:John.Saunders@scitec.com.au">John Saunders</A><P>
<P>This works with at least IOS 11.1 and later I guess. Possibly earlier,
as I'm no CISCO expert I can't say for sure. If your router is doing
anything more complicated that shuffling packets between an ethernet
interface and either a serial port or BRI port, then you should work
through if this will work for you.
<P>
<P>First define a route map with a name of proxy-redirect (name doesn't
matter) and specify the next hop to be the machine Squid runs on.
<PRE>
!
route-map proxy-redirect permit 10
match ip address 110
set ip next-hop 203.24.133.2
!
</PRE>
Define an access list to trap HTTP requests. The second line allows
the Squid host direct access so an routing loop is not formed.
By carefully writing your access list as show below, common
cases are found quickly and this can greatly reduce the load on your
router's processor.
<PRE>
!
access-list 110 deny tcp any any neq www
access-list 110 deny tcp host 203.24.133.2 any
access-list 110 permit tcp any any
!
</PRE>
Apply the route map to the ethernet interface.
<PRE>
!
interface Ethernet0
ip policy route-map proxy-redirect
!
</PRE>
<P>
<H3>possible bugs</H3>
<P>
<A HREF="mailto:morgan@curtin.net">Bruce Morgan</A> notes that
there is a Cisco bug relating to transparent proxying using IP
policy route maps, that causes NFS and other applications to break.
Apparently there are two bug reports raised in Cisco, but they are
not available for public dissemination.
<P>
<P>The problem occurs with o/s packets with more than 1472 data bytes. If you try
to ping a host with more than 1472 data bytes across a Cisco interface with the
access-lists and ip policy route map, the icmp request will fail. The
packet will be fragmented, and the first fragment is checked against the
access-list and rejected - it goes the "normal path" as it is an icmp
packet - however when the second fragment is checked against the
access-list it is accepted (it isn't regarded as an icmp packet), and
goes to the action determined by the policy route map!
<P>
<P>
<A HREF="mailto:John.Saunders@scitec.com.au">John</A> notes that you
may be able to get around this bug by carefully writing your access lists.
If the last/default rule is to permit then this bug
would be a problem, but if the last/default rule was to deny then
it won't be a problem. I guess fragments, other than the first,
don't have the information available to properly policy route them.
Normally TCP packets should not be fragmented, at least my network
runs an MTU of 1500 everywhere to avoid fragmentation. So this would
affect UDP and ICMP traffic only.
<P>
<P>Basically, you will have to pick between living with the bug or better
performance. This set has better performance, but suffers from the
bug:
<PRE>
access-list 110 deny tcp any any neq www
access-list 110 deny tcp host 10.1.2.3 any
access-list 110 permit tcp any any
</PRE>
Conversely, this set has worse performance, but works for all protocols:
<PRE>
access-list 110 deny tcp host 10.1.2.3 any
access-list 110 permit tcp any any eq www
access-list 110 deny tcp any any
</PRE>
<P>
<H2><A NAME="ss17.4">17.4 Transparent caching with LINUX 2.0.29 and CISCO IOS 11.1</A>
</H2>
<P>Just for kicks, here's an email message posted to squid-users
on how to make transparent proxying work with a Cisco router
and Squid running on Linux.
<P>
<P>by
<A HREF="mailto:signal@shreve.net">Brian Feeny</A><P>
<P>Here is how I have Transparent proxying working for me, in an environment
where my router is a Cisco 2501 running IOS 11.1, and Squid machine is
running Linux 2.0.33.
<P>
<P>Many thanks to the following individuals and the squid-users list for
helping me get redirection and transparent proxying working on my
Cisco/Linux box.
<P>
<UL>
<LI>Lincoln Dale</LI>
<LI>Riccardo Vratogna</LI>
<LI>Mark White</LI>
<LI>Henrik Nordstrom</LI>
</UL>
<P>
<P>First, here is what I added to my Cisco, which is running IOS 11.1. In
IOS 11.1 the route-map command is "process switched" as opposed to the
faster "fast-switched" route-map which is found in IOS 11.2 and later.
You may wish to be running IOS 11.2. I am running 11.1, and have had no
problems with my current load of about 150 simultaneous connections to
squid.:
<PRE>
!
interface Ethernet0
description To Office Ethernet
ip address 208.206.76.1 255.255.255.0
no ip directed-broadcast
no ip mroute-cache
ip policy route-map proxy-redir
!
access-list 110 deny tcp host 208.206.76.44 any eq www
access-list 110 permit tcp any any eq www
route-map proxy-redir permit 10
match ip address 110
set ip next-hop 208.206.76.44
</PRE>
<P>
<P>So basically from above you can see I added the "route-map" declaration,
and an access-list, and then turned the route-map on under int e0 "ip
policy route-map proxy-redir"
<P>
<P>ok, so the Cisco is taken care of at this point. The host above:
208.206.76.44, is the ip number of my squid host.
<P>
<P>My squid box runs Linux, so I had to do the following on it:
<P>
<P>my kernel (2.0.33) config looks like this:
<PRE>
#
# Networking options
#
CONFIG_FIREWALL=y
# CONFIG_NET_ALIAS is not set
CONFIG_INET=y
CONFIG_IP_FORWARD=y
CONFIG_IP_MULTICAST=y
CONFIG_SYN_COOKIES=y
# CONFIG_RST_COOKIES is not set
CONFIG_IP_FIREWALL=y
# CONFIG_IP_FIREWALL_VERBOSE is not set
CONFIG_IP_MASQUERADE=y
# CONFIG_IP_MASQUERADE_IPAUTOFW is not set
CONFIG_IP_MASQUERADE_ICMP=y
CONFIG_IP_TRANSPARENT_PROXY=y
CONFIG_IP_ALWAYS_DEFRAG=y
# CONFIG_IP_ACCT is not set
CONFIG_IP_ROUTER=y
</PRE>
<P>
<P>You will need Firewalling and Transparent Proxy turned on at a minimum.
<P>
<P>Then some ipfwadm stuff:
<PRE>
# Accept all on loopback
ipfwadm -I -a accept -W lo
# Accept my own IP, to prevent loops (repeat for each interface/alias)
ipfwadm -I -a accept -P tcp -D 208.206.76.44 80
# Send all traffic destined to port 80 to Squid on port 3128
ipfwadm -I -a accept -P tcp -D 0/0 80 -r 3128
</PRE>
<P>it accepts packets on port 80 (redirected from the Cisco), and redirects
them to 3128 which is the port my squid process is sitting on. I put all
this in /etc/rc.d/rc.local
<P>
<P>I am using
<A HREF="/Versions/1.1/1.1.20/">v1.1.20 of Squid</A> with
<A HREF="http://hem.passagen.se/hno/squid/squid-1.1.20.host_and_virtual.patch">Henrik's patch</A>
installed. You will want to install this patch if using a setup similar
to mine.
<P>
<H2><A NAME="ss17.5">17.5 The cache is trying to connect to itself...</A>
</H2>
<P>by
<A HREF="mailto:hno@hem.passagen.se">Henrik Nordstrom</A><P>I think almost everyone who have tried to build a transparent proxy
setup have been bitten by this one.
<P>
<P>Measures you can take:
<UL>
<LI>Deny Squid from fetching objects from itself (using ACL lists).</LI>
<LI>Apply a small patch that prevents Squid from looping infinitely
(available from
<A HREF="http://hem.passagen.se/hno/squid/">Henrik's Squid Patches</A>)</LI>
<LI>Don't run Squid on port 80, and redirect port 80 not destined for
the local machine to Squid (redirection == ipfilter/ipfw/ipfadm). This
avoids the most common loops.</LI>
<LI>If you are using ipfilter then you should also use transproxyd in
front of Squid. Squid does not yet know how to interface to ipfilter
(patches are welcome: squid-bugs@ircache.net).</LI>
</UL>
<P>
<H2><A NAME="trans-freebsd"></A> <A NAME="ss17.6">17.6 Transparent caching with FreeBSD</A>
</H2>
<P>by Duane Wessels
<P>I set out yesterday to make transparent caching work with Squid and
FreeBSD. It was, uh, fun.
<P>It was relatively easy to configure a cisco to divert port 80
packets to my FreeBSD box. Configuration goes something like this:
<PRE>
access-list 110 deny tcp host 10.0.3.22 any eq www
access-list 110 permit tcp any any eq www
route-map proxy-redirect permit 10
match ip address 110
set ip next-hop 10.0.3.22
int eth2/0
ip policy route-map proxy-redirect
</PRE>
Here, 10.0.3.22 is the IP address of the FreeBSD cache machine.
<P>
<P>Once I have packets going to the FreeBSD box, I need to get the
kernel to deliver them to Squid.
I started on FreeBSD-2.2.7, and then downloaded
<A HREF="ftp://coombs.anu.edu.au/pub/net/ip-filter/">IPFilter</A>. This was a dead end for me. The IPFilter distribution
includes patches to the FreeBSD kernel sources, but many of these had
conflicts. Then I noticed that the IPFilter page says
``It comes as a part of [FreeBSD-2.2 and later].'' Fair enough. Unfortunately,
you can't hijack connections with the FreeBSD-2.2.X IPFIREWALL code (<EM>ipfw</EM>), and
you can't (or at least I couldn't) do it with <EM>natd</EM> either.
<P>
<P>FreeBSD-3.0 has much better support for connection hijacking, so I suggest
you start with that. You need to build a kernel with the following options:
<PRE>
options IPFIREWALL
options IPFIREWALL_FORWARD
</PRE>
<P>
<P>Next, its time to configure the IP firewall rules with <EM>ipfw</EM>.
By default, there are no "allow" rules and all packets are denied.
I added these commands to <EM>/etc/rc.local</EM>
just to be able to use the machine on my network:
<PRE>
ipfw add 60000 allow all from any to any
</PRE>
But we're still not hijacking connections. To accomplish that,
add these rules:
<PRE>
ipfw add 49 allow tcp from 10.0.3.22 to any
ipfw add 50 fwd 127.0.0.1 tcp from any to any 80
</PRE>
The second line (rule 50) is the one which hijacks the connection.
The first line makes sure we never hit rule 50 for traffic originated
by the local machine. This prevents forwarding loops.
<P>
<P>Note that I am not changing the port number here. That is,
port 80 packets are simply diverted to Squid on port 80.
My Squid configuration is:
<PRE>
http_port 80
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
</PRE>
<P>
<P>If you don't want Squid to listen on port 80 (because that
requires root privileges) then you can use another port.
In that case your ipfw redirect rule looks like:
<PRE>
ipfw add 50 fwd 127.0.0.1,3128 tcp from any to any 80
</PRE>
and the <EM>squid.conf</EM> lines are:
<PRE>
http_port 3128
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
</PRE>
<P>
<H2><A NAME="trans-linux-2"></A> <A NAME="ss17.7">17.7 Transparent caching with Linux and ipchains</A>
</H2>
<P>by
<A HREF="mailto:Support@dnet.co.uk">Martin Lyons</A><P>You need to configure your kernel for ipchains.
Configuring Linux kernels is beyond the scope of
this FAQ. One way to do it is:
<PRE>
# cd /usr/src/linux
# make menuconfig
</PRE>
<P>The following shows important kernel features to include:
<PRE>
[*] Network firewalls
[ ] Socket Filtering
[*] Unix domain sockets
[*] TCP/IP networking
[ ] IP: multicasting
[ ] IP: advanced router
[ ] IP: kernel level autoconfiguration
[*] IP: firewalling
[ ] IP: firewall packet netlink device
[*] IP: always defragment (required for masquerading)
[*] IP: transparent proxy support
</PRE>
<P>You must include the <EM>IP: always defragment</EM>, otherwise it prevents
you from using the REDIRECT chain.
<P>
<P>The following script is used to configure ipchains:
<PRE>
#Send all traffic destined to port 80 to squid on port 8081
/sbin/ipchains -A input -p tcp -s 10.0.3.22/16 -d 0/0 80 -j REDIRECT 8081
</PRE>
<P>
<P>Also,
<A HREF="mailto:andrew@careless.net">Andrew Shipton</A>
notes that with 2.0.x kernels you don't need to enable packet forwarding,
but with the 2.1.x and 2.2.x kernels using ipchains you do. Packet
forwarding is enabled with the following command:
<PRE>
echo 1 > /proc/sys/net/ipv4/ip_forward
</PRE>
<P>
<H2><A NAME="ss17.8">17.8 Transparent caching with ACC Tigris digital access server</A>
</H2>
<P>by
<A HREF="mailto:John.Saunders@scitec.com.au">John Saunders</A><P>This is to do with configuring transparent proxy
for an ACC Tigris digital access server (like a CISCO 5200/5300
or an Ascend MAX 4000). I've found that doing this in the NAS
reduces traffic on the LAN and reduces processing load on the
CISCO. The Tigris has ample CPU for filtering.
<P>
<P>Step 1 is to create filters that allow local traffic to pass.
Add as many as needed for all of your address ranges.
<PRE>
ADD PROFILE IP FILTER ENTRY local1 INPUT 10.0.3.0 255.255.255.0 0.0.0.0 0.0.0.0 NORMAL
ADD PROFILE IP FILTER ENTRY local2 INPUT 10.0.4.0 255.255.255.0 0.0.0.0 0.0.0.0 NORMAL
</PRE>
<P>
<P>Step 2 is to create a filter to trap port 80 traffic.
<PRE>
ADD PROFILE IP FILTER ENTRY http INPUT 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 = 0x6 D= 80 NORMAL
</PRE>
<P>
<P>Step 3 is to set the "APPLICATION_ID" on port 80 traffic to 80.
This causes all packets matching this filter to have ID 80
instead of the default ID of 0.
<PRE>
SET PROFILE IP FILTER APPLICATION_ID http 80
</PRE>
<P>
<P>Step 4 is to create a special route that is used for
packets with "APPLICATION_ID" set to 80. The routing
engine uses the ID to select which routes to use.
<PRE>
ADD IP ROUTE ENTRY 0.0.0.0 0.0.0.0 PROXY-IP 1
SET IP ROUTE APPLICATION_ID 0.0.0.0 0.0.0.0 PROXY-IP 80
</PRE>
<P>
<P>Step 5 is to bind everything to a filter ID called transproxy.
List all local filters first and the http one last.
<PRE>
ADD PROFILE ENTRY transproxy local1 local2 http
</PRE>
<P>
<P>With this in place use your RADIUS server to send back the
``Framed-Filter-Id = transproxy'' key/value pair to the NAS.
<P>
<P>You can check if the filter is being assigned to logins with
the following command:
<PRE>
display profile port table
</PRE>
<P>
<H2><A NAME="ss17.9">17.9 ``Connection reset by peer'' and Cisco policy routing</A>
</H2>
<P>
<A HREF="mailto:fygrave at tigerteam dot net">Fyodor</A>
has tracked down the cause of unusual ``connection reset by peer'' messages
when using Cisco policy routing to hijack HTTP requests.
<P>When the network link between router and the cache goes down for just a
moment, the packets that are supposed to be redirected are instead sent
out the default route. If this happens, a TCP ACK from the client host
may be sent to the origin server, instead of being diverted to the
cache. The origin server, upon receiving an unexpected ACK packet,
sends a TCP RESET back to the client, which aborts the client's request.
<P>To work around this problem, you can install a static route to the
<EM>null0</EM> interface for the cache address with a higher metric (lower
precedence), such as 250. Then, when the link goes down, packets from the client
just get dropped instead of sent out the default route. For example, if
1.2.3.4 is the IP address of your Squid cache, you may add:
<PRE>
ip route 1.2.3.4 255.255.255.255 Null0 250
</PRE>
This appears to cause the correct behaviour.
<P>
<P>
<H2><A NAME="ss17.10">17.10 WCCP - Web Cache Coordination Protocol</A>
</H2>
<P>Contributors:
<A HREF="mailto:glenn@ircache.net">Glenn Chisholm</A> and
<A HREF="mailto:ltd@cisco.com">Lincoln Dale</A>.
<P>
<H3>Does Squid support WCCP?</H3>
<P>CISCO's Web Cache Coordination Protocol V1.0 is supported in squid
2.3 and later. Due to licencing requirements squid is not able to
support WCCP V2.0. If CISCO chooses to open WCCP V2 and relax the
licensing terms, Squid may be able to support it in the future.
<P>
<H3>Configuring your Router</H3>
<P>There are two different methods of configuring WCCP on CISCO routers.
The first method is for routers that only support V1.0 of the
protocol. The second is for routers that support both.
<P>
<H3>IOS Version 11.x</H3>
<P>It is possible that later versions of IOS 11.x will support V2.0 of the
protocol. If that is the case follow the 12.x instructions. Several
people have reported that the squid implimentation of WCCP does not
work with their 11.x routers. If you experience this please mail the
debug output from your router to <EM>squid-bugs</EM>.
<P>
<PRE>
conf t
wccp enable
!
interface [Interface Carrying Outgoing Traffic]x/x
!
ip wccp web-cache redirect
!
CTRL Z
write mem
</PRE>
<P>
<H3>IOS Version 12.x</H3>
<P>Some of the early versions of 12.x do not have the 'ip wccp version'
command. You will need to upgrade your IOS version to use V1.0.
<P>
<P>You will need to be running at least IOS Software Release <EM>12.0(5)T</EM>
if you're running the 12.0 T-train. IOS Software Releases <EM>12.0(3)T</EM>
and <EM>12.0(4)T</EM> do not have WCCPv1, but <EM>12.0(5)T</EM> does.
<P>
<P>
<PRE>
conf t
ip wccp version 1
ip wccp web-cache
!
interface [Interface Carrying Outgoing/Incomming Traffic]x/x
ip wccp web-cache redirect out|in
!
CTRL Z
write mem
</PRE>
<P>
<H3>Configuring FreeBSD</H3>
<P>FreeBSD first needs to be configured to recieve and strip the GRE
encapsulation from the packets from the router. To do this you will
need to patch and recompile your kernel.
<P>
<P>First, a patch needs to be applied to your kernel for GRE
support. Apply the
<A HREF="../../WCCP-support/FreeBSD-3.x/gre.patch">patch for FreeBSD-3.x kernels</A>
or the
<A HREF="../../WCCP-support/FreeBSD-4.x/gre.patch">patch for FreeBSD-4.x kernels</A>
as appropriate.
<P>
<P>Secondly you will need to download
<A HREF="../../WCCP-support/FreeBSD-3.x/gre.c">gre.c for FreeBSD-3.x</A>
or
<A HREF="../../WCCP-support/FreeBSD-4.x/gre.c">gre.c for FreeBSD-4.x</A>
and copy it to <EM>/usr/src/sys/netinet/gre.c</EM>.
<P>
<P>Finally add "OPTION GRE" to your kernel config file and rebuild
your kernel. Note, the <EM>opt_gre.h</EM> file is
created when you run <EM>config</EM>.
Once your kernel is installed you will need to
<A HREF="#trans-freebsd">configure FreeBSD for transparent proxying</A>.
<P>
<H3>Configuring Linux 2.2</H3>
<P>Al Blake has written a
<A HREF="http://www.spc.int/it/TechHead/Wccp-squid.html">Cookbook for setting up transparent WCCP using Squid on RedHat Linux and a cisco access server</A>.
<P>
<P>There are currently two methods for supporting WCCP with Linux 2.2.
A specific purpose module. Or the standard Linux GRE tunneling
driver. People have reported difficulty with the standard GRE
tunneling driver, however it does allow GRE functionality other
than WCCP. You should choose the method that suits your enviroment.
<P>
<H3>Standard Linux GRE Tunnel</H3>
<P>Linux 2.2 kernels already support GRE, as long as the GRE module is
compiled into the kernel.
<P>
<P>You will need to patch the <EM>ip_gre.c</EM> code that comes with your Linux
kernel with this
<A HREF="http://www.vsb.cz/~hal01/cache/wccp/ip_gre.patch">patch</A> supplied by
<A HREF="mailto:Jan.Haluza@vsb.cz">Jan Haluza</A>.
<P>
<P>Ensure that the GRE code is either built as static or as a module by chosing
the appropriate option in your kernel config. Then rebuild your kernel.
If it is a module you will need to:
<PRE>
modprobe ip_gre
</PRE>
<P>The next step is to tell Linux to establish an IP tunnel between the router and
your host. Daniele Orlandi reports
that you have to give the gre1 interface an address, but any old
address seems to work.
<PRE>
iptunnel add gre1 mode gre remote <Router-IP> local <Host-IP> dev <interface>
ifconfig gre1 127.0.0.2 up
</PRE>
<Router-IP> is the IP address of your router that is intercepting the
HTTP packets. <Host-IP> is the IP address of your cache, and
<interface> is the network interface that receives those packets (probably eth0).
<P>
<H3>WCCP Specific Module</H3>
<P>This module is not part of the standard Linux distributon. It needs
to be compiled as a module and loaded on your system to function.
Do not attempt to build this in as a static part of your kernel.
<P>
<P>Download the
<A HREF="../../WCCP-support/Linux/ip_wccp.c">Linux WCCP module</A>
and compile it as you would any Linux network module.
<P>
<P>Copy the module to <EM>/lib/modules/kernel-version/ipv4/ip_wccp.o</EM>. Edit
<EM>/lib/modules/kernel-version/modules.dep</EM> and add:
<P>
<PRE>
/lib/modules/kernel-version/ipv4/ip_wccp.o:
</PRE>
<P>
<P>Finally you will need to load the module:
<P>
<PRE>
modprobe ip_wccp
</PRE>
<P>
<H3>Common Steps</H3>
<P>The machine should now be striping the GRE encapsulation from any packets
recieved and requeuing them. The system will also need to be configured
for transparent proxying, either with
<A HREF="#trans-linux-1">ipfwadm</A>
or with
<A HREF="#trans-linux-2">ipchains</A>.
<P>
<H3>Configuring Others</H3>
<P>If you have managed to configuring your operating system to support WCCP
with Squid
please contact us with the details so we may share them with others.
<P>
<H2><A NAME="ss17.11">17.11 Can someone tell me what version of cisco IOS WCCP is added in?</A>
</H2>
<P>IOS releases:
<UL>
<LI>11.1(19?)CA/CC or later</LI>
<LI>11.2(14)P or later</LI>
<LI>12.0(anything) or later</LI>
</UL>
<P>
<H2><A NAME="ss17.12">17.12 Transparent caching with Foundry L4 switches</A>
</H2>
<P>by
<A HREF="mailto:signal at shreve dot net">Brian Feeny</A>.
<P>First, configure Squid for transparent caching as detailed
at the
<A HREF="#trans-caching">beginning of this section</A>.
<P>Next, configure
the Foundry layer 4 switch to
transparently redirect traffic to your Squid box or boxes. By default,
the Foundry
redirects to port 80 of your squid box. This can
be changed to a different port if needed, but won't be covered
here.
<P>
<P>In addition, the switch does a "health check" of the port to make
sure your squid is answering. If you squid does not answer, the
switch defaults to sending traffic directly thru instead of
redirecting it. When the Squid comes back up, it begins
redirecting once again.
<P>
<P>This example assumes you have two squid caches:
<PRE>
squid1.foo.com 192.168.1.10
squid2.foo.com 192.168.1.11
</PRE>
<P>
<P>We will assume you have various workstations, customers, etc, plugged
into the switch for which you want them to be transparently proxied.
The squid caches themselves should be plugged into the switch as well.
Only the interface that the router is connected to is important. Where you
put the squid caches or other connections does not matter.
<P>
<P>This example assumes your router is plugged into interface <B>17</B>
of the switch. If not, adjust the following commands accordingly.
<P>
<OL>
<LI>Enter configuration mode:
<PRE>
telnet@ServerIron#conf t
</PRE>
</LI>
<LI>Configure each squid on the Foundry:
<PRE>
telnet@ServerIron(config)# server cache-name squid1 192.168.1.10
telnet@ServerIron(config)# server cache-name squid2 192.168.1.11
</PRE>
</LI>
<LI>Add the squids to a cache-group:
<PRE>
telnet@ServerIron(config)#server cache-group 1
telnet@ServerIron(config-tc-1)#cache-name squid1
telnet@ServerIron(config-tc-1)#cache-name squid2
</PRE>
</LI>
<LI>Create a policy for caching http on a local port
<PRE>
telnet@ServerIron(config)# ip policy 1 cache tcp http local
</PRE>
</LI>
<LI>Enable that policy on the port connected to your router
<PRE>
telnet@ServerIron(config)#int e 17
telnet@ServerIron(config-if-17)# ip-policy 1
</PRE>
</LI>
</OL>
<P>
<P>Since all outbound traffic to the Internet goes out interface
<B>17</B> (the router), and interface <B>17</B> has the caching policy applied to
it, HTTP traffic is going to be intercepted and redirected to the
caches you have configured.
<P>
<P>The default port to redirect to can be changed. The load balancing
algorithm used can be changed (Least Used, Round Robin, etc). Ports
can be exempted from caching if needed. Access Lists can be applied
so that only certain source IP Addresses are redirected, etc. This
information was left out of this document since this was just a quick
howto that would apply for most people, not meant to be a comprehensive
manual of how to configure a Foundry switch. I can however revise this
with any information necessary if people feel it should be included.
<P>
<P>
<HR>
<A HREF="FAQ-18.html">Next</A>
<A HREF="FAQ-16.html">Previous</A>
<A HREF="FAQ.html#toc17">Contents</A>
</BODY>
</HTML>
|