{"id":1852,"date":"2012-01-31T22:14:21","date_gmt":"2012-01-31T14:14:21","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=1852"},"modified":"2023-07-04T13:00:33","modified_gmt":"2023-07-04T13:00:33","slug":"how-to-restrict-web-access-by-time-using-squid-proxy-server-on-centos-6-2","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-restrict-web-access-by-time-using-squid-proxy-server-on-centos-6-2\/","title":{"rendered":"How to Restrict Web Access By Time Using Squid Proxy Server on CentOS 6.2"},"content":{"rendered":"<p>In web server administration, controlling internet access by time is a crucial task. This can be achieved using the <a href=\"https:\/\/webhostinggeeks.com\/blog\/squid-proxy-server-features-functions-benefits\/\">Squid proxy server<\/a> on CentOS 6.2.<\/p>\n<p>In this tutorial, we will be focusing on restricting web access by time. This is particularly useful in a corporate setting where you might want to limit internet access during certain hours. For instance, you might want to restrict access to non-work related websites during working hours to ensure productivity.<\/p>\n<h2>Step 1: Open the squid.conf Configuration File<\/h2>\n<p>The first step in this process is to open the squid.conf configuration file. This can be done using the following command:<\/p>\n<pre>\r\n[root@centos62 ~]# vi \/etc\/squid\/squid.conf\r\n<\/pre>\n<h2>Step 2: Define Your Internal Network<\/h2>\n<p>Next, you need to define your internal network. In this example, we will be allowing access from the webhostinggeeks-dev4.com network, while always restricting access to the webhostinggeeks-dev4.com network outside of the specified surfing hours.<\/p>\n<pre>\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 webhostinggeeks-dev4.com src 192.168.1.0\/24    # Your webhostinggeeks-dev4.com internal network\r\n<\/pre>\n<h2>Step 3: Define Surfing Hours<\/h2>\n<p>Now, you need to define the surfing hours. This is the time period during which you want to allow internet access. In this example, we are allowing access from Monday to Friday between 08:00 and 17:00.<\/p>\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\n#\r\n<\/pre>\n<h2>Step 4: Set Access Restrictions<\/h2>\n<p>The next step is to set the access restrictions. In this case, we are always restricting access to the webhostinggeeks-dev4.com network, but allowing access during the specified surfing hours.<\/p>\n<pre>\r\n# Only allow cachemgr access from webhostinggeeks-dev4.com\r\nhttp_access allow webhostinggeeks-dev4.com surfing_hours\r\nhttp_access deny webhostinggeeks-dev4.com\r\n<\/pre>\n<h2>Step 5: Restart Squid Proxy Server<\/h2>\n<p>Finally, you need to restart the Squid proxy server for the changes to take effect. This can be done using the following command:<\/p>\n<pre>\r\n[root@centos62 ~]# service squid restart\r\nStopping squid: ................                           [  OK  ]\r\nStarting squid: .                                          [  OK  ]\r\n<\/pre>\n<p>Squid Cache Proxy Full Configuration:<\/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-dev4.com src 192.168.1.0\/24    # Your webhostinggeeks-dev4.com 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\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-dev4.com\r\nhttp_access allow webhostinggeeks-dev4.com surfing_hours\r\nhttp_access deny webhostinggeeks-dev4.com\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\nhttp_access allow webhostinggeeks-dev4.com\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<\/li>\n<li><span class=\"fw-bold\">service squid restart<\/span> \u2013 Restarts the Squid proxy server<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Controlling internet access by time using the Squid proxy on CentOS 6.2 is a powerful tool for web server administrators. It allows you to maintain productivity in a corporate setting by restricting access to non-work related websites during working hours.<\/p>\n<p>This tutorial has provided a step-by-step guide on how to set up this feature. Remember, the key to successfully implementing this is to have a properly configured Squid proxy server. If you haven&#8217;t set it up yet, you can follow this guide on <a href=\"https:\/\/webhostinggeeks.com\/howto\/how-to-install-and-configure-squid-proxy-server-on-centos-6-2\/\">how to install and configure Squid Proxy Server on CentOS 6.2<\/a>.<\/p>\n<p>By following these steps, you can ensure a more controlled and productive internet usage environment in your organization. As always, if you have any questions or run into any issues, don&#8217;t hesitate to reach out for help. Happy surfing!<\/p>\n<h2>FAQ Section<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the purpose of the Squid Proxy?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">TSquid Proxy server is a widely-used caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the significance of the &#8216;acl&#8217; command in Squid?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">&#8216;acl&#8217; stands for Access Control List. It is used in Squid to define and control user access to the internet. It can be used to restrict access based on several factors like IP address, time, and more.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What does the &#8216;http_access&#8217; command do in Squid?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">&#8216;http_access&#8217; is a command in Squid that either allows or denies HTTP requests based on the specified criteria. It works in conjunction with &#8216;acl&#8217; to control user access to the internet.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How can I check if my Squid Proxy server is running correctly?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">You can check the status of your Squid Proxy server by using the command &#8216;service squid status&#8217;. If the server is running correctly, it will display &#8216;squid is running&#8217;.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Can I set different surfing hours for different days in Squid?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Yes, you can set different surfing hours for different days in Squid. You just need to define the &#8216;acl&#8217; for each time period separately. For example, &#8216;acl surfing_hours1 time M T W H F 08:00-12:00&#8217; and &#8216;acl surfing_hours2 time M T W H F 13:00-17:00&#8217;.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In web server administration, controlling internet access by time is a crucial task. This can be achieved using the Squid proxy server on CentOS 6.2. In this tutorial, we will&#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":[1253,1536,1744,1793],"class_list":["post-1852","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-squid-server","tag-centos-6-2","tag-linux","tag-security","tag-squid"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1852","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=1852"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/1852\/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=1852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=1852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=1852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}