To run this demo, you'll need an account on IBM SmartCloud Enterprise (SCE). If you don't have one, you can sign up online (as an organization). The principles in this presentation apply to any other "Internet as a Service" (IaaS) cloud that supports Linux virtual machines and VLANs, or even traditional networks. SCE has a command-line interface. We provide detailed steps using the command-line interface for all the cloud provisioning actions. You can execute these steps equally well by using the web portal.
Complete these steps to try the exercise yourself:
- Download and install PuTTY and PuTTYgen.
- Install Java 6. You'll need it for the SmartCloud Enterprise command-line toolkit.
- Find the link to the SmartCloud Enterprise command-line toolkit on the Support tab in the web portal. Set up the command-line tool as shown in the command-line toolkit's Reference Guide, and set up a password file as described in the guide. If you prefer not to use the command line, similar steps are available in the web portal.
- Create an SSH key in the SCE web portal and convert it to PuTTY format using PuTTYgen.
This scenario uses SOCKS to connect to a web server running on the same server as the SOCKS proxy, but blocked to the outside. The Linux virtual machine is protected by a firewall running on the machine itself. OpenSSH is running on the virtual machine and acts as the SOCKS proxy. To provide something to test network access with another protocol, we use an Apache web server, which is provided on most standard Linux distributions, and runs on port 80 by default. Figure 1 shows the setup for the basic scenario.
Figure 1 Setup for a basic scenario using SOCKS.
Step 1: Create a Virtual Machine to Act as a SOCKS Proxy
We'll use Red Hat Enterprise Linux (RHEL) 6.2 with a primary IP on the public Internet. Following is the command to create a Linux virtual machine on SCE:
> ic-create-instance.cmd -u <user id> -w <passphrase> -g <key file> -t "BRZ64.2/4096/60*500*350" -n SOCKSProxy -k 20025211 -c <my key> -L 141 Executing action: CreateInstance ... The request has been submitted successfully. 1 instances! ---------------------------------- ID: 266635 Name: SOCKSProxy Hostname: vhost0677 InstanceType: BRZ64.2/4096/60*500*350 IP: 126.96.36.199 KeyName: <my key> . . .
In all the SCE client commands, the -u argument is the user ID, -w is the passphrase to unlock the password file, and -g is the path and filename of the password file. In this command, the -t argument is the server size, -n is the instance name, -k is the image ID, -c is the key name, and -L is the data center. After submitting the request to create a new virtual machine instance, wait for the instance status to be provisioned. To do that, you can use the describe-instances command:
>ic-describe-instances.cmd -u <user id> -w <passphrase> -g <key file> Executing action: DescribeInstances ... ID: 266635 Name: SOCKSProxy Image ID: 20025211 Hostname: vhost0677 InstanceType: BRZ64.2/4096/60*500*350 IP: 188.8.131.52 . . . Status: ACTIVE . . .
Note the IP address or host name for use in the following steps.
After the machine has been provisioned and booted, you can connect to it with an SSH client. We'll use PuTTY. In PuTTY, you configure SOCKS with the dynamic tunneling feature (see Figure 2). Expand Connection > Auth, enter port 5020 (any port will do), select Dynamic for the destination, and click the Add button. Save the session and click Open.
Figure 2 PuTTY for SOCKS use.
For convenience, you can enter a username in the Auto-login Username box in the Connection > Data panel, to avoid having to type the username every time you begin a session. We used idcuser as the username, which is the predefined user ID for accessing virtual machines on IBM SmartCloud Enterprise. (This step is convenient but not essential.) Figure 3 shows the configuration at this point.
Figure 3 Set the user ID in PuTTY.
An alternative to using the PuTTY user interface is to use the command line. It works with almost exactly the same command-line options as the Linux OpenSSH client (ssh). Use the Windows command line with the -D option:
> "C:\Program Files (x86)\PuTTY\putty.exe" -i <private key> -D 5020 idcuser@<ip address>
In this command, the -i argument is the path and filename of the SSH private key, and the -D option is the port for SOCKS. You'll be able to see the connection created with the netstat command:
>netstat -an Proto Local Address Foreign Address State . . . TCP 127.0.0.1:5020 0.0.0.0:0 LISTENING . . .
Step 3a: Start the Web Server and Configure the Firewall
In this step, we start the web server on the Linux virtual machine and make sure that the firewall will not allow direct access. Only port 22 should be open on the firewall from outside. However, we also need to add a rule for any port when the source is the local machine. Use the IP of the local machine. From the Bash shell in the SSH session, type the following command:
$ sudo /usr/sbin/apachectl start $ sudo /sbin/ifup eth1 $ sudo vi /etc/sysconfig/iptables # Add line allowing any port if accessed from the local machine. . . . -A INPUT -p tcp -m tcp -s 184.108.40.206 -j ACCEPT . . . $ sudo /sbin/service iptables restart
After making the changes to the iptables firewall configuration file, the last command above restarts the firewall service. Try to access the web server by typing the IP address of the virtual machine in the web browser on your Windows workstation. The server should not be found. You need to set the web browser to act as a SOCKS client before you can access the web server.
Step 3b: Configure Firefox to Act as a SOCKS Client
To set the SOCKS proxy in Firefox 10, open the Connection Settings dialog (Tools > Options > Advanced > Network). In other browsers and other versions of Firefox, the menu options will differ. Enter the address of the proxy and 127.0.0.1, since PuTTY is our entry point to the tunnel and it's running locally. Open the IP address of the server in your web browser (see Figure 4).
Figure 4 SOCKS client settings in Firefox 10.
Step 3c: Access the Web Server Over SOCKS
Now we can access a web server running on the other virtual machine using the private IP in the VLAN. You should see the Apache test page, as shown in Figure 5.
Figure 5 Apache test page.