≡ Menu

Accessing Internet from cloud VM when you have only private network enabled

We have a couple of virtual servers hosted with Softlayer for processing data and backup purpose. The public interface is completely turned off i.e. no Internet access. We can only access VMs using a VPN. It resulted in decreased costs and many security problems for backend servers. However, when you order “Private Network Only” cloud VM, you cannot route outgoing traffic to the Internet using your VM.

This is how we order the server for our company:

Fig.01: Private only network at Softlayer cloud. No direct  outgoing or incoming access from the Internet

Fig.01: Private only network at Softlayer cloud. No direct outgoing or incoming access from the Internet

You can’t access the Internet or download or upload files to the internet:
Fig.02: Look ma no internets

Fig.02: Look ma no internets

Use proxy server

I did setup a squid 3 proxy server one of our public VM. This VM can access both private cloud and public internet on the same VLAN. Sample squid3.conf:

acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
## private vm ##
acl zfsbackup src
http_access allow zfsbackup
http_access allow localhost
http_access deny all
## this server with eth0 connected to VLAN ##
cache_dir ufs /var/spool/squid 100 16 256
coredump_dir /var/spool/squid
refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0
refresh_pattern (Release|Packages(.gz)*)$      0       20%     2880
refresh_pattern .		0	20%	4320
## this server with eth1 connected to the Internt ##
tcp_outgoing_address 75.zzz.xxx.yyy
forwarded_for delete 
via off
forwarded_for off
follow_x_forwarded_for deny all
request_header_access X-Forwarded-For deny all
cache_mem 1024 MB

Now, all you have to do is setup http_proxy variables on private VM to download files from the internet or git repos:

# set http_proxy, do not forget to set ftp_proxy, https_proxy, socks_proxy etc
export http_proxy=""
export HTTP_PROXY=""
# Now we have access to the internet ##
wget http://some-url/file.foo.gz
curl -I google.com
lynx google.com
# special case 
git config --global http.proxy $http_proxy
git commands here
# Use proxy sever with user and password
export http_proxy=http://USERNAME:PASSOWRD@"
wget ..
curl ..

Make sure you read man pages of commands that need http_proxy access. Don’t forget to add http_proxy in your shell startup file i.e. ~/.bash_profile.

Share this on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 4 comments… add one }
  • wafflefactor December 5, 2016, 10:08 pm

    Neat tip, the idea that popped into my head was trying a vpn like zerotier but this may be easier

  • Andrew Wippler August 27, 2016, 5:59 pm

    Most cloud providers suggest using a NAT server (basically an iptables firewall) to get outbound internet access. With this approach not only do you get internet access, but files are cached – thus reducing bandwidth costs. Great idea!

  • Alex August 23, 2016, 1:46 am

    Why wouldn’t you setup this proxy VM as a router with iptables? I am not very familiar with this cloud but It is really easy to make with fwbuilder. In this case this VM would be a full featured firewall/router. It is kind of standard virtual private cloud setup.
    BTW, thank you for your blog. I really appreciate your posts.

  • Ramu August 20, 2016, 8:57 am

    Okay, I just tried this with my SL vps. It worked.

Security: Are you a robot or human?

Leave a Comment