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

ADVERTISEMENTS

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
acl CONNECT method CONNECT
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 10.81.33.4
http_access allow zfsbackup
http_access allow localhost
http_access deny all
## this server with eth0 connected to VLAN ##
http_port 10.86.115.100:3128
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="http://10.86.115.100:3128"
export HTTP_PROXY="http://10.86.115.100:3128"
# 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@10.86.115.100:3128"
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.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
4 comments… add one
  • Ramu Aug 20, 2016 @ 8:57

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

  • Alex Aug 23, 2016 @ 1:46

    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.

  • Andrew Wippler Aug 27, 2016 @ 17:59

    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!

  • wafflefactor Dec 5, 2016 @ 22:08

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.