<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bsd on mwclabs</title><link>https://mwclabs.net/tags/bsd/</link><description>Recent content in Bsd on mwclabs</description><generator>Hugo</generator><language>en</language><copyright>&lt;a href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank" rel="noopener">CC BY-NC 4.0&lt;/a></copyright><lastBuildDate>Fri, 17 Apr 2009 11:05:20 -0300</lastBuildDate><atom:link href="https://mwclabs.net/tags/bsd/index.xml" rel="self" type="application/rss+xml"/><item><title>Transparent proxy using Squid and PF on OpenBSD</title><link>https://mwclabs.net/posts/2009/04/transparent-proxy-using-squid-and-pf-on-openbsd/</link><pubDate>Fri, 17 Apr 2009 11:05:20 -0300</pubDate><guid>https://mwclabs.net/posts/2009/04/transparent-proxy-using-squid-and-pf-on-openbsd/</guid><description>&lt;p>How to install and configure &lt;a href="http://www.squid-cache.org/">Squid&lt;/a> on transparent mode and the necessary (&lt;a href="http://www.openbsd.org/faq/pf/">PF&lt;/a>) rules.&lt;/p>
&lt;p>&lt;strong>1. Install&lt;/strong>&lt;/p>
&lt;p>You can using the pre-compiled packages (pkg_add) or from the source using &lt;a href="http://www.openbsd.org/ports.html">Ports&lt;/a>.&lt;/p>
&lt;p>&lt;strong>Via Package Manager (pkg_add)&lt;/strong>&lt;/p>
&lt;p>Set the repository mirror:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>export PKG_PATH&lt;span style="color:#f92672">=&lt;/span>ftp://ftp.das.ufsc.br/pub/OpenBSD/4.4/packages/i386/
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Install the package:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>pkg_add -i -v squid
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Selected version was: &lt;strong>squid-2.7.STABLE3-ldap&lt;/strong>.&lt;/p>
&lt;p>&lt;strong>Via Ports&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>cd /usr/ports/www/squid
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>env FLAVOR&lt;span style="color:#f92672">=&lt;/span>transparent make install
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>2. Configuration&lt;/strong>&lt;/p>
&lt;p>&lt;strong>2.1. Squid&lt;/strong>&lt;/p>
&lt;p>To make squid start on boot, edit the file &lt;strong>/etc/rc.local&lt;/strong> and append the following files after &lt;code># Add your local startup actions here&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code># Squid
/usr/local/sbin/squid
&lt;/code>&lt;/pre>&lt;p>Now, edit the Squid configuration file &lt;code>/etc/squid/squid.conf&lt;/code>, you can use a configuration like the following:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-squid" data-lang="squid">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_port&lt;/span> &lt;span style="color:#ae81ff">3128&lt;/span> transparent
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">visible_hostname&lt;/span> neatproxy.myorg.corp
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>error_directory /usr/local/share/squid/errors/Portuguese
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Logs&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">cache_access_log&lt;/span> /var/log/squid/access.log
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">cache_log&lt;/span> /var/log/squid/cache.log
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># SVN&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>extension_methods REPORT MERGE MKACTIVITY CHECKOUT PROPFIND
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># ACLs&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> &lt;span style="color:#66d9ef">all&lt;/span> &lt;span style="color:#66d9ef">src&lt;/span> &lt;span style="color:#ae81ff">0.0.0.0/0.0.0.0&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> localnet &lt;span style="color:#66d9ef">src&lt;/span> &lt;span style="color:#ae81ff">192.168.1.0/24&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> SSL_Ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">443&lt;/span> &lt;span style="color:#ae81ff">563&lt;/span> &lt;span style="color:#ae81ff">2096&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">80&lt;/span> &lt;span style="color:#ae81ff">21&lt;/span> &lt;span style="color:#ae81ff">443&lt;/span> &lt;span style="color:#ae81ff">563&lt;/span> &lt;span style="color:#ae81ff">70&lt;/span> &lt;span style="color:#ae81ff">210&lt;/span> &lt;span style="color:#ae81ff">1025-65535&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">280&lt;/span> &lt;span style="color:#75715e"># http-mgmt&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">488&lt;/span> &lt;span style="color:#75715e"># gss-http&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">591&lt;/span> &lt;span style="color:#75715e"># filemaker&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> Safe_ports &lt;span style="color:#66d9ef">port&lt;/span> &lt;span style="color:#ae81ff">777&lt;/span> &lt;span style="color:#75715e"># multiling http&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> CONNECT &lt;span style="color:#66d9ef">method&lt;/span> CONNECT
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Full access users&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> vips arp &amp;#34;/etc/squid/users.vips&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># BlackList&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">acl&lt;/span> blacklist &lt;span style="color:#66d9ef">dstdomain&lt;/span> &amp;#34;/etc/squid/domains.blacklist&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">##&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Allow and deny rules&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">deny&lt;/span> !Safe_ports
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">deny&lt;/span> CONNECT !SSL_ports
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">allow&lt;/span> vips
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">deny&lt;/span> blacklist
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">allow&lt;/span> localnet
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http_access&lt;/span> &lt;span style="color:#66d9ef">deny&lt;/span> &lt;span style="color:#66d9ef">all&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">##&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;em>Create the &lt;code>/etc/squid/users.vips&lt;/code> e &lt;code>/etc/squid/domains.blacklist&lt;/code> if used.&lt;/em>&lt;/p>
&lt;p>Run Squid with the &lt;code>-z&lt;/code> flag in order to init swap directories:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>/usr/local/sbin/squid -z
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Start the Squid service:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>/usr/local/sbin/squid
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>After configuration changes, run the following command to reload rules:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>/usr/local/sbin/squid -k reconfigure
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>2.2. PF&lt;/strong>&lt;/p>
&lt;p>Edit PF configuration file &lt;code>/etc/pf.conf&lt;/code> and use/adapt the following rules:&lt;/p>
&lt;pre tabindex="0">&lt;code class="language-pf" data-lang="pf">rdr on $int_if inet proto tcp from any to any port www -&amp;gt; 127.0.0.1 port 3128

pass in on $int_if inet proto tcp from any to 127.0.0.1 port 3128
pass out on $ext_if inet proto tcp from any to any port www
&lt;/code>&lt;/pre>&lt;p>Permissions for Squid to access &lt;code>/dev/pf&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>chgrp _squid /dev/pf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>chmod g+rw /dev/pf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;hr>
&lt;p>&lt;em>Reference:&lt;/em>&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://www.openbsd-br.org/index.php?q=node/15">http://www.openbsd-br.org/index.php?q=node/15&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>