Install a simple proxy on your Linux dedicated server
For one of our clients, our team needed a static IP address to access private ressources.
Since we work remotely, each one has its own connexion, OS, so of course the simplest solution is a proxy. We didn’t need a VPN so I checked for a simple solution.
We have a Debian Server exposed, so we decided to use it as proxy.
First (and unique !) step
Let’s install Squid ! Squid is a caching and forwarding HTTP web proxy, and it’s a free software released under the GNU General Public License.
sudo apt-get install squid
I got an error during installation (on Debian 9), resolved by creating manualy the log folder :
sudo mkdir /var/log/squid3/
After installation finished, let’s edit the conf, first we will backup original conf file (still a good practice !) :
sudo cp /etc/squid/squid.conf{,.orginal}
In this case, the conf file contains 300ko of comments… So I decided to have a clear file, let’s remove comments from original and copy to main conf file (maybe you need to upgrade files Chmod) :
sudo grep -v ^# squid.conf.orginal | grep -v ^$ > squid.conf
Then you should configure your own IPs to access the proxy :
acl TeamMember1 src IP_PERSONNAL_MEMBER1
http_access allow TeamMember1
http_access deny all
# or allow everyone ... never do this of course !
#http_access allow all
Then let’s add a rule to your firewall to allow the 3128’s port :
sudo iptables -A INPUT -p tcp -m tcp --dport 3128 -j ACCEPT
And don’t forget to restart Squid to accept the new conf :
sudo service squid restart
Test it !
Let’s open Firefox for example, and configure the network to use a proxy, here is the result (more informations here) :
Then let’s create a simple PHP file to be sure it works, I created a sample testIP.php file on my server (you can create a local one) :
<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
echo $ip;
Then access it, on Firefox you should see the IP of your Dedicated server, and on Chrome the IP of your computer.
Here it is ! A simple proxy to provide a static IP easily.