{"id":32,"date":"2007-04-27T19:49:08","date_gmt":"2007-04-27T19:49:08","guid":{"rendered":"http:\/\/patchlog.com\/patches\/squid-outgoing-ip-patch\/"},"modified":"2010-05-16T12:10:51","modified_gmt":"2010-05-16T10:10:51","slug":"squid-outgoing-ip-patch","status":"publish","type":"post","link":"https:\/\/patchlog.com\/patches\/squid-outgoing-ip-patch\/","title":{"rendered":"squid outgoing ip patch"},"content":{"rendered":"<p>Some time ago a client of mine was running squid on a system with multiple interfaces and ips. He wanted a setup where squid would use the same ip on which it received the connection  to create the connection to the destination server for fetching the content.<\/p>\n<p>Let's say we have 3 ips  1.1.1.1, 1.1.1.2 and squid listens on both interfaces. Now if a client would connect to the proxy server on ip 1.1.1.1 and request google.com, squid will use 1.1.1.1 to make the connection to google. If the client will connect to 1.1.1.2 squid will use 1.1.1.2 to connect to the destination server.<\/p>\n<p><!--more--><br \/>\nOne way to do this would be using acls and tcp_outgoing_address<\/p>\n<p>acl acl_ip1 src  1.1.1.1<br \/>\nacl acl_ip2 src 1.1.1.2<br \/>\ntcp_outgoing_address 1.1.1.1 acl_ip1<br \/>\ntcp_outgoing_address 1.1.1.2 acl_ip2<\/p>\n<p>This is easy to do if you have just a few ips, but if you have a few hundred ips you get tired of writing those rules, and even if you generate them with a script I don't think squid would really like that many configuration options. It will probably take a lot of time to parse them and  probably the performance will suffer on high traffic servers.So I came up with a patch to squid's source code that  does this automatically without any need for setting up acls and tcp_outgoing_address. You are still able to use tcp_outgoing_address after applying this patch, because the patch is active only for those connections where the acl of tcp_outgoing_address does not match.<\/p>\n<p>The patch was created for squid 2.5, but I think it can be adapted for 2.6<\/p>\n<p>And here is the actual patch ( gziped ) : <a title=\"squid outgoing ip patch\" href=\"http:\/\/patchlog.com\/wp-content\/uploads\/2007\/04\/squid_outgoing_ippatch.gz\">squid outgoing ip patch<\/a><\/p>\n<p>download it, go to squid source folder and then:<\/p>\n<pre><ol><li style=\"font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;\"><div style=\"font-family: 'Courier New', Courier, monospace; font-weight: normal;\">&nbsp;<\/div><\/li><\/ol><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Some time ago a client of mine was running squid on a system with multiple interfaces and ips. He wanted a setup where squid would use the same ip on which it received the connection to create the connection to the destination server for fetching the content. Let&#8217;s say we have 3 ips 1.1.1.1, 1.1.1.2 &hellip; <a href=\"https:\/\/patchlog.com\/patches\/squid-outgoing-ip-patch\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">squid outgoing ip patch<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[360,32],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-patches","tag-patches","tag-squid"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pofPh-w","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":1,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":672,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/posts\/32\/revisions\/672"}],"wp:attachment":[{"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/patchlog.com\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}