How to open specific port such as 8082 in Google Compute Engine ?
This tutorial guides you on how to open specific port such as 8082 in Google Compute Engine VM instance and test the connectivity on the opened port using Telnet.
Open specific port such as 8082 in Google Compute Engine
Before you begin, make sure that you create a compute engine VM instance and start.
If you don’t have any server application running on the compute engine VM instance which is listening to port 8082, you can use the following instructions to setup simple HTTP server.
First, connect to VM instance using SSH connect option in the Google Cloud Console.
Then copy the following code.
SimpleHTTPServer.java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.ServerSocket; import java.net.Socket; public class SimpleHTTPServer { public static void main(String args[] ) throws IOException { ServerSocket server = new ServerSocket(8082); System.out.println("Listening for connection on port 8082 ..."); while (true) { Socket clientSocket = server.accept(); InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream()); BufferedReader reader = new BufferedReader(isr); String line = reader.readLine(); while (!line.isEmpty()) { System.out.println(line); line = reader.readLine(); } } } }
Use vim editor and paste the code in your working directory
sneppets@instance-1:~/java$ pwd /home/demo/java sneppets@instance-1:~/java$ vi SimpleHTTPServer.java
Then compile the java code.
sneppets@instance-1:~/java$ javac SimpleHTTPServer.java sneppets@instance-1:~/java$ ls SimpleHTTPServer.class SimpleHTTPServer.java
Run the java code. Therefore simple HTTP server will be started and it will listen for connections on port 8082.
sneppets@instance-1:~/java$ java SimpleHTTPServer Listening for connection on port 8082 ....
Firewall Rule to open specific port in GCP
Once you have the Simple HTTP server setup ready up and running, listening for connection on port 8082. Now, let’s see how to create a firewall rule to open specific port such as 8082 in Google Cloud Platform.
To create a firewall rule follow the below steps:
1: Go to Google Cloud Console.
2: Choose Networking -> VPC Networks -> Firewall from side menu.
3: Click “Create Firewall Rule” and specify the firewall rule details as shown in the following screenshot.
4: Click Create.
That’s it firewall rule is created to open specific TCP port.
Test Connection to VM instance for a specific port
Now, let’ see how to test connection to VM instance for a specific port.
You can use Telnet client to test the connection to VM instance for a specific port as shown below.
To test from windows machine make sure that you enable telnet and try testing as shown below.
You can also test from Linux machine as shown below.
$ telnet 35.223.9.136 8082 Trying 35.223.9.136... Connected to 35.223.9.136. Escape character is '^]'.
That’s it. Hope it helped 🙂
- Google cloud shell command to get the default PROJECT_ID – GCP
- Docker EXPOSE Port only to the Host on Google Cloud
- Get Docker Container’s IP Address from the Host
- Copy Files between Host and Docker Container
- What is ImagePullBackOff status on a Kubernetes pod ?
- Set or change root password in Ubuntu Linux
- How to list all Containers running in Kubernetes Pod ?
- How to find which users belongs to a specific group in linux
- Give write permissions for specific user or group for specific folder in linux
- How to remove an image tag from docker hub ?
- Build a Docker Image with a Dockerfile and Cloud Build in GCP?
- How to create GCP project on Google Cloud Platform
- MariaDB – How to set max_connections permanently ?
- Create GCP project on Google Cloud Platform
- Is it possible to change Google Cloud Platform Project ID ?
- Create non-root SSH user account and provide access to specific folders
- Make manual payment or pay early for your Google Cloud Platform charges
- no matches for kind “Deployment” in version “extensions/v1beta1”
- Delete or unset clusters contexts and users entries from kubectl config