alpine-wiki

alpine server Proxy browser network

proxy term that is applied to the service as man in the middle!

There are several types of proxy, in this case we will use as gateway for internet browsing, this is that through the proxy server others will navigate no matter are devices or machines.

What is the usage for?

What use was it in the past?

Formerly it was used to simulate a faster internet, this was because the proxy server kept the pages and resources that had already been visited, so every time a machine asks you to navigate the proxy it was the page saved so which simulated higher speed.

Today this is then called “proxy cache” and is only used for limited resources or as a means of performance, but not very optimal becouse nomadays the network is tremendously fast even at slow speeds.

Tinyproxy installation

This tutorial will configure alpine server as a proxy server but without cache.

preparation

hostname venenux &  echo 'hostname="venenux"'> /etc/conf.d/hostname & echo "venenux" > /etc/hostname

cat > /etc/apk/repositories << EOF; $(echo)
http://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d '.' -f1.2)/main
http://dl-cdn.alpinelinux.org/alpine/v$(cat /etc/alpine-release | cut -d '.' -f1.2)/community
EOF

apk update

Tinyproxy service installation

apk add tinyproxy tinyproxy-doc tinyproxy-openrc

rc-update add tinyproxy

** Warning **: the eudev package is very necessary to automatically detect the device, the sed package is necessary because the extended regular expression

After installation:

Configuration - basic operation

The alpine package does not fit anything well configured, it must be adjusted so that can run as service daemon.

This is because in dockers and containers tinyproxy needs to work without being a service that belongs to anyone, that’s why he is not tied to the group or neither to the user in the configuration file.

The most important part is the combination of the filters, this will be addressed in the advanced configuration section. Here it will be configured for a simple service on a pc:

sed -Ei 's|^.?User.*|User tinyproxy|g' /etc/tinyproxy/tinyproxy.conf
sed -Ei 's|^.?Group.*|Group tinyproxy|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?Port.*|Port 8888|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?BindSame.*|BindSame yes|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?MaxClients.*|MaxClients 10|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?Allow[[:space:]]|#Allow |g' /etc/tinyproxy/tinyproxy.conf

mkdir -p /var/run/tinyproxy && chown tinyproxy /var/run/tinyproxy
sed -Ei 's|^.?LogFile.*|LogFile "/var/log/tinyproxy/tinyproxy.log"|g' /etc/tinyproxy/tinyproxy.conf
sed -Ei 's|^.?PidFile.*|PidFile "/var/run/tinyproxy.pid"|g' /etc/tinyproxy/tinyproxy.conf
rc-update add tinyproxy && rc-service tinyproxy restart

After configuring and restarting the service, you can test it by this command line in shell like this:

apk add curl curl-doc

export http_proxy="http://localhost:8888/" && curl -I http://google.com

Advanced configuration

Configure tinyproxy for hidden internet navigation

sed -Ei 's|^.?User.*|User tinyproxy|g' /etc/tinyproxy/tinyproxy.conf
sed -Ei 's|^.?Group.*|Group tinyproxy|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?Port.*|Port 8888|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?BindSame.*|BindSame yes|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?Allow[[:space:]]|#Allow |g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?DisableViaHeader.*|DisableViaHeader Yes|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?XTinyproxy.*|XTinyproxy No|g' /etc/tinyproxy/tinyproxy.conf

viaproxyname=$(head -n1 < <(fold -w10 < <(tr -cd 'a-z0-9' < /dev/urandom)))
sed -Ei "s|^.?ViaProxyName.*|ViaProxyName \"${viaproxyname}\"|g" /etc/tinyproxy/tinyproxy.conf

mkdir -p /var/run/tinyproxy && chown tinyproxy /var/run/tinyproxy
sed -Ei 's|^.?LogFile.*|LogFile "/var/log/tinyproxy/tinyproxy.log"|g' /etc/tinyproxy/tinyproxy.conf
sed -Ei 's|^.?PidFile.*|PidFile "/var/run/tinyproxy/tinyproxy.pid"|g' /etc/tinyproxy/tinyproxy.conf
rc-update add tinyproxy && rc-service tinyproxy restart

Configure tinyproxy to filter what is browsing

touch /etc/tinyproxy/filter && echo "mocosoft" >> /etc/tinyproxy/filter
touch /etc/tinyproxy/filter && echo "*.facebook.com" >> /etc/tinyproxy/filter

sed -Ei 's|^.?Filter[[:space:]].*|Filter \"/etc/tinyproxy/filter\"|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?FilterURLs[[:space:]].*|FilterURLs On|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?Allow[[:space:]]|#Allow |g' /etc/tinyproxy/tinyproxy.conf

mkdir -p /var/run/tinyproxy && chown tinyproxy /var/run/tinyproxy
sed -Ei 's|^.?LogFile.*|LogFile "/var/log/tinyproxy/tinyproxy.log"|g' /etc/tinyproxy/tinyproxy.conf
sed -Ei 's|^.?PidFile.*|PidFile "/var/run/tinyproxy.pid"|g' /etc/tinyproxy/tinyproxy.conf
rc-update add tinyproxy && rc-service tinyproxy restart

Configure tinyproxy to filter who can navigate

default_if=$(ip route list | awk '/^default/ {print $5}')
netmaskip=$(ip -o -f inet addr show ${default_if} | awk '{print $4}')

sed -Ei "s|^.?Allow[[:space:]]127.0.0.1|#Allow ${netmaskip}|g" /etc/tinyproxy/tinyproxy.conf
sed -Ei 's|^.?Allow[[:space:]]127.0.0.1|#Allow 127.0.0.1|g' /etc/tinyproxy/tinyproxy.conf

sed -Ei 's|^.?MaxClients.*|MaxClients 10|g' /etc/tinyproxy/tinyproxy.conf

mkdir -p /var/run/tinyproxy && chown tinyproxy /var/run/tinyproxy
sed -Ei 's|^.?LogFile.*|LogFile "/var/log/tinyproxy/tinyproxy.log"|g' /etc/tinyproxy/tinyproxy.conf
sed -Ei 's|^.?PidFile.*|PidFile "/var/run/tinyproxy.pid"|g' /etc/tinyproxy/tinyproxy.conf
rc-update add tinyproxy && rc-service tinyproxy restart

LICENSE

** CC BY-NC-SA **: The project allows reusers to distribute, remix, adapt and build on the material. in any medium or format only for non-commercial purposes, and only provided that the attribution is provided to the creators involved. If you remix, adapt or build on the material, you must obtain the license of the modified material. material under identical terms includes the following elements: