Skip to content

Instantly share code, notes, and snippets.

@grasses
Forked from cdodd/install-squid.sh
Last active June 9, 2017 06:19
Show Gist options
  • Save grasses/3fa08735e068a75dc8529fe70627a8df to your computer and use it in GitHub Desktop.
Save grasses/3fa08735e068a75dc8529fe70627a8df to your computer and use it in GitHub Desktop.
Install a basic squid proxy with authentication on Centos 6 x64. Just modify the variables at the top and run the script on a clean system.
#!/bin/sh
PROXY_USER=user
PROXY_PASS=password
PROXY_PORT=3128
# Clear the repository index caches
yum clean all
# Update the operating system
yum update -y
# Install httpd-tools to get htpasswd
yum install httpd-tools -y
# Install squid
yum install squid -y
# Create the htpasswd file
htpasswd -c -b /etc/squid/passwords $PROXY_USER $PROXY_PASS
# Backup the original squid config
cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
# Set up the squid config
cat << EOF > /etc/squid/squid.conf
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
forwarded_for delete
http_port 0.0.0.0:$PROXY_PORT
EOF
# Set squid to start on boot
chkconfig squid on
# Start squid
/etc/init.d/squid start
# Set up the iptables config
cat << EOF > /etc/sysconfig/iptables
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
#######################################################
# BEGIN CUSTOM RULES
#######################################################
# Allow SSH from anywhere
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# Allow squid access from anywhere
-A INPUT -m state --state NEW -m tcp -p tcp --dport $PROXY_PORT -j ACCEPT
#######################################################
# END CUSTOM RULES
#######################################################
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
EOF
# Restart iptables
/etc/init.d/iptables restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment