{"id":1857,"date":"2012-01-31T23:18:13","date_gmt":"2012-01-31T15:18:13","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=1857"},"modified":"2023-07-24T14:56:57","modified_gmt":"2023-07-24T14:56:57","slug":"how-to-restrict-the-access-to-specific-web-sites-using-squid-proxy-server-on-centos-6-2","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-restrict-the-access-to-specific-web-sites-using-squid-proxy-server-on-centos-6-2\/","title":{"rendered":"How to Restrict Access to Specific Websites using Squid Proxy Server on CentOS 6.2"},"content":{"rendered":"<p>Managing access to specific websites is a common requirement for many organizations. This can be for a variety of reasons, such as enhancing network security, improving productivity, or complying with regulatory requirements.<\/p>\n<p>The solution to this problem lies in the use of a <a href=\"https:\/\/webhostinggeeks.com\/best\/proxy-servers\/\">proxy server<\/a>, specifically, the <a href=\"https:\/\/webhostinggeeks.com\/blog\/squid-proxy-server-features-functions-benefits\/\">Squid Proxy server<\/a>.<\/p>\n<p>Squid is a highly flexible and widely used proxy server that caches and delivers web content, optimizes bandwidth, improves response times, and restricts access to specific websites. This tutorial will guide you on how to restrict access to specific websites using Squid Proxy server on CentOS 6.2.<\/p>\n<p>By following this tutorial, you will learn how to configure Squid to restrict access to specific websites during certain hours, thereby giving you greater control over your network&#8217;s internet usage. This can be particularly useful for businesses that want to ensure their network resources are used effectively.<\/p>\n<h2>Step 1: Open the squid.conf configuration file<\/h2>\n<pre>\r\n[root@centos62 ~]# vi \/etc\/squid\/squid.conf\r\n<\/pre>\n<h2>Step 2: Create a web folder under \/etc\/squid<\/h2>\n<p>This is to store any anonymous files such as Bad_Websites.squid.<\/p>\n<pre>\r\n[root@centos62 ~]# mkdir \/etc\/squid\/web\r\n<\/pre>\n<h2>Step 3: Create Bad_Websites.squid and add the bad websites list<\/h2>\n<pre>\r\n[root@centos62 ~]# vi \/etc\/squid\/web\/Bad_Websites.squid\r\n<\/pre>\n<p>Example Bad website list:<\/p>\n<pre>\r\n#List in \/etc\/squid\/web\/Bad_Websites.squid\r\nwww.porn.com\r\nwww.badwebsites.com\r\n<\/pre>\n<h2>Step 4: Define surfing_hour group\u2019s name, surfing time and restricted websites file list<\/h2>\n<pre>\r\n#Add this at the bottom of the ACL Section\r\n#\r\nacl surfing_hours time M T W H F 08:00-17:00\r\nacl Bad_Websites dstdomain \"\/etc\/squid\/web\/Bad_Websites.squid\"\r\n#\r\n<\/pre>\n<h2>Step 5: Always restrict access to webhostinggeeks.com network and Bad_Websites<\/h2>\n<p>But allow surfing during surfing_hours group\u2019s only if the sites does not in Bad_Websites (other than Bad_Websites).<\/p>\n<pre>\r\n# Only allow cachemgr access from webhostinggeeks.com\r\nhttp_access allow webhostinggeeks.com surfing_hours !Bad_Websites\r\nhttp_access deny Bad_Websites\r\nhttp_access deny webhostinggeeks.com\r\n<\/pre>\n<h2>Step 6: Restart Squid proxy server to take effect<\/h2>\n<pre>\r\n[root@centos62 ~]# service squid restart\r\nStopping squid: ................                           [  OK  ]\r\nStarting squid: .                                          [  OK  ]\r\n<\/pre>\n<p>Full configuration example:<\/p>\n<pre>\r\n#\r\n# Recommended minimum configuration:\r\n#\r\nacl manager proto cache_object\r\nacl localhost src 127.0.0.1\/32 ::1\r\nacl to_localhost dst 127.0.0.0\/8 0.0.0.0\/32 ::1\r\n\r\n# Example rule allowing access from your local networks.\r\n# Adapt to list your (internal) IP networks from where browsing\r\n# should be allowed\r\nacl localnet src 10.0.0.0\/8\t# RFC1918 possible internal network\r\nacl localnet src 172.16.0.0\/12\t# RFC1918 possible internal network\r\nacl localnet src 192.168.0.0\/16\t# RFC1918 possible internal network\r\nacl localnet src fc00::\/7       # RFC 4193 local private network range\r\nacl localnet src fe80::\/10      # RFC 4291 link-local (directly plugged) machines\r\nacl webhostinggeeks.com src 192.168.1.0\/24    # Your internal network\r\n\r\nacl SSL_ports port 443\r\nacl Safe_ports port 80\t\t# http\r\nacl Safe_ports port 21\t\t# ftp\r\nacl Safe_ports port 443\t\t# https\r\nacl Safe_ports port 70\t\t# gopher\r\nacl Safe_ports port 210\t\t# wais\r\nacl Safe_ports port 1025-65535\t# unregistered ports\r\nacl Safe_ports port 280\t\t# http-mgmt\r\nacl Safe_ports port 488\t\t# gss-http\r\nacl Safe_ports port 591\t\t# filemaker\r\nacl Safe_ports port 777\t\t# multiling http\r\nacl CONNECT method CONNECT\r\n\r\n#Add this at the bottom of the ACL Section\r\n#\r\nacl surfing_hours time M T W H F 08:00-17:00\r\nacl Bad_Websites  dstdomain \"\/etc\/squid\/web\/Bad_Websites.squid\"\r\n\r\n#\r\n# Recommended minimum Access Permission configuration:\r\n#\r\n# Only allow cachemgr access from localhost\r\nhttp_access allow manager localhost\r\nhttp_access deny manager\r\n\r\n# Only allow cachemgr access from webhostinggeeks.com\r\nhttp_access allow webhostinggeeks.com surfing_hours !Bad_Websites\r\nhttp_access deny Bad_Websites\r\nhttp_access deny webhostinggeeks.com\r\n\r\n\r\n\r\n# Deny requests to certain unsafe ports\r\nhttp_access deny !Safe_ports\r\n\r\n# Deny CONNECT to other than secure SSL ports\r\nhttp_access deny CONNECT !SSL_ports\r\n\r\n# We strongly recommend the following be uncommented to protect innocent\r\n# web applications running on the proxy server who think the only\r\n# one who can access services on \"localhost\" is a local user\r\n#http_access deny to_localhost\r\n\r\n#\r\n# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS\r\n#\r\n\r\n# Example rule allowing access from your local networks.\r\n# Adapt localnet in the ACL section to list your (internal) IP networks\r\n# from where browsing should be allowed\r\n#http_access allow localnet\r\nhttp_access allow localhost\r\n\r\n# And finally deny all other access to this proxy\r\nhttp_access deny all\r\n\r\n# Squid normally listens to port 3128\r\nhttp_port 3128\r\n\r\n# We recommend you to use at least the following line.\r\nhierarchy_stoplist cgi-bin ?\r\n\r\n# Uncomment and adjust the following to add a disk cache directory.\r\n#cache_dir ufs \/var\/spool\/squid 100 16 256\r\n\r\n# Leave coredumps in the first cache dir\r\ncoredump_dir \/var\/spool\/squid\r\n\r\n# Add any of your own refresh_pattern entries above these.\r\nrefresh_pattern ^ftp:\t\t1440\t20%\t10080\r\nrefresh_pattern ^gopher:\t1440\t0%\t1440\r\nrefresh_pattern -i (\/cgi-bin\/|\\?) 0\t0%\t0\r\nrefresh_pattern .\t\t0\t20%\t4320\r\n<\/pre>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">vi \/etc\/squid\/squid.conf<\/span> \u2013 Opens the squid.conf configuration file in the vi text editor.<\/li>\n<li><span class=\"fw-bold\">mkdir \/etc\/squid\/web<\/span> \u2013 Creates a new directory named &#8216;web&#8217; under \/etc\/squid.<\/li>\n<li><span class=\"fw-bold\">vi \/etc\/squid\/web\/Bad_Websites.squid<\/span> \u2013 Opens the Bad_Websites.squid file in the vi text editor. If the file does not exist, it creates a new one.<\/li>\n<li><span class=\"fw-bold\">acl surfing_hours time M T W H F 08:00-17:00<\/span> \u2013 Defines the &#8216;surfing_hours&#8217; access control list (ACL) in Squid, setting the allowed surfing time from Monday to Friday, 08:00 to 17:00.<\/li>\n<li><span class=\"fw-bold\">acl Bad_Websites dstdomain &#8220;\/etc\/squid\/web\/Bad_Websites.squid&#8221;<\/span> \u2013 Defines the &#8216;Bad_Websites&#8217; ACL, setting the list of restricted websites as those listed in the Bad_Websites.squid file.<\/li>\n<li><span class=\"fw-bold\">http_access allow webhostinggeeks.com surfing_hours !Bad_Websites<\/span> \u2013 Allows access to webhostinggeeks.com during the defined &#8216;surfing_hours&#8217; as long as the sites are not listed in &#8216;Bad_Websites&#8217;.<\/li>\n<li><span class=\"fw-bold\">http_access deny Bad_Websites<\/span> \u2013 Denies access to the websites listed in &#8216;Bad_Websites&#8217;.<\/li>\n<li><span class=\"fw-bold\">http_access deny webhostinggeeks.com<\/span> \u2013 Denies access to webhostinggeeks.com.<\/li>\n<li><span class=\"fw-bold\">service squid restart<\/span> \u2013 Restarts the Squid proxy server to apply the changes made in the configuration.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we have walked through the process of restricting access to specific websites using Squid Proxy server on CentOS 6.2. By defining specific <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-access-control-list-acl\/\">access control lists (ACLs)<\/a> and setting up a list of restricted websites, we can effectively control the internet usage within our network. This can be particularly beneficial for organizations that need to manage their network resources effectively or comply with certain regulatory requirements.<\/p>\n<p>Remember, Squid is a flexible and powerful tool that can be configured to meet a wide range of needs. Whether you&#8217;re looking to improve network performance, enhance security, or control access to specific websites, Squid offers a solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Managing access to specific websites is a common requirement for many organizations. This can be for a variety of reasons, such as enhancing network security, improving productivity, or complying with&#8230;<\/p>\n","protected":false},"author":6,"featured_media":1554,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055,1057],"tags":[1244,1253,1536,1744,1793],"class_list":["post-1857","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-squid-server","tag-centos","tag-centos-6-2","tag-linux","tag-security","tag-squid"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=1857"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1857\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/1554"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=1857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=1857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=1857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}