{"id":12901,"date":"2019-03-29T01:59:02","date_gmt":"2019-03-29T01:59:02","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12901"},"modified":"2019-03-29T01:59:02","modified_gmt":"2019-03-29T01:59:02","slug":"how-to-setup-squid-proxy-server-on-ubuntu-and-debian","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-setup-squid-proxy-server-on-ubuntu-and-debian\/","title":{"rendered":"How to Setup \u201cSquid Proxy\u201d Server on Ubuntu and Debian"},"content":{"rendered":"<p>Squid is a most popular caching and forwarding HTTP web proxy server used my wide range of companies to cache web pages from a web server to improve web server speed, reduce response times and reduce network bandwidth usage.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/install-squid-http-proxy-on-centos-7\/\" target=\"_blank\" rel=\"noopener\">How to Create an HTTP Proxy Using Squid on CentOS 7<\/a><\/p>\n<p>In this article, we will explain how to install a squid proxy server on\u00a0<strong>Ubuntu and Debian<\/strong>\u00a0distributions and use it as an HTTP proxy server.<\/p>\n<h3>How to Install Squid on Ubuntu<\/h3>\n<p>Before we begin, you should know that Squid server doesn\u2019t have any requirements, but the amount of RAM utilization may differ based on the clients browsing the internet via the proxy server.<\/p>\n<p><strong>Squid<\/strong>\u00a0package is available to install from the base Ubuntu repository, but before that make sure to update your packages by running.<\/p>\n<pre>$ sudo apt update\r\n<\/pre>\n<p>Once your packages are up to date, you can proceed further to install squid and start and enable it on system startup using following commands.<\/p>\n<pre>$ sudo apt -y install squid\r\n$ sudo systemctl start squid\r\n$ sudo systemctl enable squid\r\n<\/pre>\n<p>At this point your Squid web proxy should already be running and you can verify the status of the service with.<\/p>\n<pre>$ sudo systemctl status squid\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre><strong>\u25cf squid.service - LSB: Squid HTTP Proxy version 3.x<\/strong>\r\n   Loaded: loaded (\/etc\/init.d\/squid; generated)\r\n   Active: <strong>active (running)<\/strong> since Tue 2018-12-04 06:42:43 UTC; 14min ago\r\n     Docs: man:systemd-sysv-generator(8)\r\n    Tasks: 4 (limit: 1717)\r\n   CGroup: \/system.slice\/squid.service\r\n           \u251c\u25002761 \/usr\/sbin\/squid -YC -f \/etc\/squid\/squid.conf\r\n           \u251c\u25002766 (squid-1) -YC -f \/etc\/squid\/squid.conf\r\n           \u251c\u25002768 (logfile-daemon) \/var\/log\/squid\/access.log\r\n           \u2514\u25002772 (pinger)\r\n\r\nDec 04 06:42:43 tecmint systemd[1]: Starting LSB: Squid HTTP Proxy version 3.x...\r\nDec 04 06:42:43 tecmint squid[2708]:  * Starting Squid HTTP Proxy squid\r\nDec 04 06:42:43 tecmint squid[2708]:    ...done.\r\nDec 04 06:42:43 tecmint systemd[1]: Started LSB: Squid HTTP Proxy version 3.x.\r\nDec 04 06:42:43 tecmint squid[2761]: Squid Parent: will start 1 kids\r\nDec 04 06:42:43 tecmint squid[2761]: Squid Parent: (squid-1) process 2766 started\r\n<\/pre>\n<p>Following are the some important squid file locations you should be aware of:<\/p>\n<ul>\n<li>Squid configuration file:\u00a0<strong>\/etc\/squid\/squid.conf<\/strong><\/li>\n<li>Squid Access log:\u00a0<strong>\/var\/log\/squid\/access.log<\/strong><\/li>\n<li>Squid Cache log:\u00a0<strong>\/var\/log\/squid\/cache.log<\/strong><\/li>\n<\/ul>\n<p>The default configuration file contains some configuration directives that needs to be configured to affect the behavior of the Squid.<\/p>\n<p>Now open this file for editing using Vi editor and make changes as shown below.<\/p>\n<pre>$ sudo vim \/etc\/squid\/squid.conf\r\n<\/pre>\n<p>Now, you may search about the following lines and change them as requested, in the Vi editor, you may search about those lines by hitting the\u00a0<strong>\u2018ESC\u2019<\/strong>\u00a0and typing \u201c<b>\/<\/b>\u201d key to writing the specific lines to look for.<\/p>\n<ul>\n<li><b>http_port<\/b>\u00a0: This is the default port for the HTTP proxy server, by default it is\u00a0<strong>3128<\/strong>, you may change it to any other port that you want, you may also add the\u00a0<strong>\u201ctransparent\u201d<\/strong>\u00a0tag to the end of the line like\u00a0<strong>http_port 8888 transparent<\/strong>\u00a0to make Squid proxy act like a transparent proxy if you want.<\/li>\n<li><b>http_access deny all<\/b>\u00a0: This line won\u2019t let anybody to access the HTTP proxy server, that\u2019s why you need to change it to\u00a0<strong>http_access allow all<\/strong>\u00a0to start using your Squid proxy server.<\/li>\n<li><b>visible_hostname<\/b>\u00a0: This directive is used to set the specific hostname to a squid server. You can give any hostname to squid.<\/li>\n<\/ul>\n<p>After making above changes, you may restart the Squid proxy server using the command.<\/p>\n<pre>$ sudo systemctl restart squid\r\n<\/pre>\n<h3>Configuring Squid as an HTTP Proxy on Ubuntu<\/h3>\n<p>In this squid configuration section, we will explain you how to configure squid as an HTTP proxy using only the client IP address for authentication.<\/p>\n<h4>Add Squid ACLs<\/h4>\n<p>If you wish to allow only one IP address to access the internet through your new proxy server, you will need to define new\u00a0<strong>acl<\/strong>\u00a0(<strong>access control list<\/strong>) in the configuration file.<\/p>\n<pre>$ sudo vim \/etc\/squid\/squid.conf\r\n<\/pre>\n<p>The\u00a0<strong>acl<\/strong>\u00a0rule you should add is:<\/p>\n<pre>acl localnet src XX.XX.XX.XX\r\n<\/pre>\n<p>Where\u00a0<code>XX.XX.XX.XX<\/code>\u00a0is the IP address of client machine. This\u00a0<strong>acl<\/strong>\u00a0should be added in the beginning of the ACL\u2019s section as shown in the following screenshot.<\/p>\n<div id=\"attachment_31164\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Add-Squid-ACL.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31164\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Add-Squid-ACL.png\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Add-Squid-ACL.png 850w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Add-Squid-ACL-768x192.png 768w\" alt=\"Add IP Address to Allow Web\" width=\"850\" height=\"212\" aria-describedby=\"caption-attachment-31164\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31164\" class=\"wp-caption-text\">Add IP Address to Allow Web<\/p>\n<\/div>\n<p>It is always a good practice to define a comment next to\u00a0<strong>ACL<\/strong>\u00a0which will describe who uses this IP address, for example.<\/p>\n<pre>acl localnet src 192.168.0.102  # Boss IP address\r\n<\/pre>\n<p>You will need to restart Squid service to take the new changes into effect.<\/p>\n<pre>$ sudo systemctl restart squid\r\n<\/pre>\n<h4>Open Ports in Squid Proxy<\/h4>\n<p>By default, only certain ports are allowed in the squid configuration, if you wish to add more just define them in the configuration file as shown.<\/p>\n<pre>acl Safe_ports port XXX\r\n<\/pre>\n<p>Where\u00a0<code>XXX<\/code>\u00a0is the port number that you wish to allow. Again it is a good practive to define a comment next to\u00a0<strong>acl<\/strong>\u00a0that will describe what the port is going to be used for.<\/p>\n<div id=\"attachment_31166\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Add-Ports-in-Squid-Proxy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31166\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Add-Ports-in-Squid-Proxy.png\" sizes=\"auto, (max-width: 849px) 100vw, 849px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Add-Ports-in-Squid-Proxy.png 849w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Add-Ports-in-Squid-Proxy-768x208.png 768w\" alt=\"Add Ports in Squid Proxy\" width=\"849\" height=\"230\" aria-describedby=\"caption-attachment-31166\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31166\" class=\"wp-caption-text\">Add Ports in Squid Proxy<\/p>\n<\/div>\n<p>For the changes to take effect, you will need to restart squid once more.<\/p>\n<pre>$ sudo systemctl restart squid\r\n<\/pre>\n<h4>Squid Proxy Client Authentication<\/h4>\n<p>To allow users to authenticate before using the proxy, you need to enable basic http authentication in the configuration file, but before that you need to install\u00a0<strong>apache2-utils<\/strong>\u00a0package using following command.<\/p>\n<pre>$ sudo apt install apache2-utils\r\n<\/pre>\n<p>Now create a file called\u00a0<strong>\u201cpasswd\u201d<\/strong>\u00a0that will later store the username for the authentication. Squid runs with user\u00a0<strong>\u201cproxy\u201d<\/strong>\u00a0so the file should be owned by that user.<\/p>\n<pre>$ sudo touch \/etc\/squid\/passwd\r\n$ sudo chown proxy: \/etc\/squid\/passwd\r\n$ ls -l \/etc\/squid\/passwd\r\n<\/pre>\n<div class=\"google-auto-placed ap_container\">\n<p>Now we will create a new user called \u201ctecmint\u201d and setup its password.<\/p>\n<pre><strong>$ sudo htpasswd \/etc\/squid\/passwd tecmint<\/strong>\r\n\r\nNew password: \r\nRe-type new password: \r\nAdding password for user tecmint\r\n<\/pre>\n<p>Now to enable basic http authentication open the configuration file.<\/p>\n<pre>$ sudo vim \/etc\/squid\/squid.conf\r\n<\/pre>\n<p>After the ports ACLs add the following lines:<\/p>\n<pre>auth_param basic program \/usr\/lib64\/squid\/basic_ncsa_auth \/etc\/squid\/passwd\r\nauth_param basic children 5\r\nauth_param basic realm Squid Basic Authentication\r\nauth_param basic credentialsttl 2 hours\r\nacl auth_users proxy_auth REQUIRED\r\nhttp_access allow auth_users\r\n<\/pre>\n<div id=\"attachment_31167\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Enable-Squid-User-Authentication.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31167\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Enable-Squid-User-Authentication.png\" sizes=\"auto, (max-width: 863px) 100vw, 863px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Enable-Squid-User-Authentication.png 863w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Enable-Squid-User-Authentication-768x319.png 768w\" alt=\"Enable Squid User Authentication\" width=\"863\" height=\"359\" aria-describedby=\"caption-attachment-31167\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31167\" class=\"wp-caption-text\">Enable Squid User Authentication<\/p>\n<\/div>\n<p>Save the file and restart squid so that the new changes can take effect:<\/p>\n<pre>$ sudo systemctl restart squid\r\n<\/pre>\n<h4>Block Websites on Squid Proxy<\/h4>\n<p>To block access to unwanted websites, first create a file called \u201c<strong>blacklisted_sites.acl<\/strong>\u201d that will store the blacklisted sites in it.<\/p>\n<pre>$ sudo touch \/etc\/squid\/blacklisted_sites.acl\r\n<\/pre>\n<p>Now add the websites that you wish to block access, for example.<\/p>\n<pre><strong>.<\/strong>badsite1.com\r\n<strong>.<\/strong>badsite2.com\r\n<\/pre>\n<p>The proceeding\u00a0<strong>dot<\/strong>\u00a0informs squid to block all references to that sites including\u00a0<strong>www.badsite1<\/strong>,\u00a0<strong>subsite.badsite1.com<\/strong>\u00a0etc.<\/p>\n<p>Now open Squid\u2019s configuration file.<\/p>\n<pre>$ sudo vim \/etc\/squid\/squid.conf\r\n<\/pre>\n<p>Just after the above ACLs add the following two lines:<\/p>\n<pre>acl bad_urls dstdomain \"\/etc\/squid\/blacklisted_sites.acl\"\r\nhttp_access deny bad_urls\r\n<\/pre>\n<div id=\"attachment_31168\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Block-Websites-in-Squid.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31168\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Block-Websites-in-Squid.png\" sizes=\"auto, (max-width: 868px) 100vw, 868px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Block-Websites-in-Squid.png 868w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Block-Websites-in-Squid-768x390.png 768w\" alt=\"Block Websites in Squid\" width=\"868\" height=\"441\" aria-describedby=\"caption-attachment-31168\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31168\" class=\"wp-caption-text\">Block Websites in Squid<\/p>\n<\/div>\n<p>Now save the file and restart squid:<\/p>\n<pre>$ sudo systemctl restart squid\r\n<\/pre>\n<h4>Block Specific Keyword with Squid<\/h4>\n<p>To block a list of keywords, first create a file called \u201c<strong>blockkeywords.lst<\/strong>\u201d that will store the blacklisted keywords in it.<\/p>\n<pre>$ sudo touch \/etc\/squid\/blockkeywords.lst\r\n<\/pre>\n<p>Now add the keywords that you wish to block access, for example.<\/p>\n<pre>facebook\r\ninstagram\r\ngmail\r\n<\/pre>\n<p>Now open Squid\u2019s configuration file and add the following rule.<\/p>\n<pre>acl blockkeywordlist url_regex \"\/etc\/squid\/blockkeywords.lst\"\r\nhttp_access deny blockkeywordlist\r\n<\/pre>\n<p>Now save the file and restart squid:<\/p>\n<pre>$ sudo systemctl restart squid\r\n<\/pre>\n<p>Once everything configured accurately, you can now configure your local client web browser or operating system\u2019s network settings to use your newly configured squid HTTP proxy.<\/p>\n<h3>Configure Client to Use Squid Proxy<\/h3>\n<p>Now to test that your proxy server is working or not, you may open\u00a0<strong>Firefox<\/strong>\u00a0and go to\u00a0<strong>Edit \u2013&gt; Preferences \u2013&gt; Advanced \u2013&gt; Network \u2013&gt; Settings<\/strong>\u00a0and select \u201c<strong>Manual proxy configuration<\/strong>\u201d and enter your proxy server IP address and Port to be used for all connection as it follows.<\/p>\n<div id=\"attachment_31172\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Configure-Client-to-Use-Squid-Proxy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-31172\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/12\/Configure-Client-to-Use-Squid-Proxy.png\" alt=\"Configure Client to Use Squid Proxy\" width=\"693\" height=\"761\" aria-describedby=\"caption-attachment-31172\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-31172\" class=\"wp-caption-text\">Configure Client to Use Squid Proxy<\/p>\n<\/div>\n<p>Once you fill all the required proxy details, you will be able to surf the Web using your Squid proxy server, you may do the same thing in any other browser or program you want.<\/p>\n<p>To make sure that you are surfing the web using your proxy server, you may visit\u00a0<strong>http:\/\/www.ipaddresslocation.org\/<\/strong>, in the right top corner you must see the same IP address as your server IP address.<\/p>\n<p>For more additional configuration settings, you may check\u00a0<a href=\"http:\/\/www.squid-cache.org\/Doc\/config\/\" target=\"_blank\" rel=\"nofollow noopener\">official squid documentation<\/a>. If you have any questions or comments, please add them in the comment section below.<\/p>\n<p><a style=\"font-size: 1rem;\" href=\"https:\/\/www.tecmint.com\/install-squid-in-ubuntu\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Squid is a most popular caching and forwarding HTTP web proxy server used my wide range of companies to cache web pages from a web server to improve web server speed, reduce response times and reduce network bandwidth usage. Read Also:\u00a0How to Create an HTTP Proxy Using Squid on CentOS 7 In this article, we &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/29\/how-to-setup-squid-proxy-server-on-ubuntu-and-debian\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Setup \u201cSquid Proxy\u201d Server on Ubuntu and Debian&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12901","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12901","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12901"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12901\/revisions"}],"predecessor-version":[{"id":12902,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12901\/revisions\/12902"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}