Search code examples
sshproxyportforwardinghttp-proxyssh-tunnel

How to setup a forward proxy without VPN?


I have a laravel application which is country restricted based on IP address. To get access to certain pages I need to bypass that restriction. So here comes the proxy server. There are plenty of free and paid proxy sites are available but I want setup my own. I do have a server running in the country from which I can gain access to that certain pages. Please suggest me some way to setup the proxy so I can originate request through the server from that specific country? Anything on forward proxy or squid will help me. I'm trying to avoid the VPN setup and all because It's too complex and time consuming. Any help would be appreciated? Just point me to the right direction. Thanks in advance.


Solution

  • I managed to do that in following manner. I'm posting here if someone needs it. You need a SSH enabled server or machine from the country you want to browse from.

    Steps to follow:

    1] Open the terminal

    2] Enter the following command

    ssh -D 8123 -f -C -q -N root@ip
    

    (If you have sshpass then sshpass -p 'password' ssh -D 8123 -f -C -q -N root@ip)

    3] After that open firefox goto preference->advanced->Network tab->settings and select manual proxy configuration and enter localhost in SOCKS host and 8123 as port. Then select SOCKS v5

    4] Select ok and browse through Firefox. Make sure your ip address is from country you want. http://whatismyipaddress.com/.

    Steps to follow to close the SSH tunnel connection.

    1] Enter ps aux | grep ssh command on your terminal you will see connection like below.

    root       991  0.0  0.0  61364   684 ?        Ss   16:32   0:00 /usr/sbin/sshd -D
    root 15204  0.0  0.0  50164  3256 ?        Ss   19:27   0:00 ssh -D 8123 -f -C -q -N root@ip
    root 15534  0.0  0.0  15940   928 pts/20   S+   19:36   0:00 grep --color=auto ssh
    

    2] Take the pid of SSH tunnel connection and enter the command kill 15204 to terminate the connection.

    3] Reset the Firefox settings.

    For easier access you can create an alias for that. (Optional)

    1] On terminal enter sudo gedit ~/.bashrc

    2] Copy paste the following command at end of the file.

      alias SOCKS5='sshpass -p 'password' ssh -D 8123 -f -C -q -N root@ip'
      alias DISPLAY='ps aux | grep ssh'
    

    3] Save the file.

    4] Execute . ~/.bashrc

    5] You can use SOCKS5 and DISPLAY command directly from your terminal.