简体   繁体   English

TCP服务器的GCP计算引擎防火墙规则

[英]GCP Compute Engine Firewall Rules for TCP Server

I have created a GCP compute engine instance with a static external ip address. 我创建了一个带有静态外部ip地址的GCP计算引擎实例。 Machine type: n1-standard-2 (2 vCPUs, 7.5 GB memory). 机器类型:n1-standard-2(2个vCPU,7.5 GB内存)。 OS is Linux/Debian. 操作系统是Linux / Debian。

在此输入图像描述

My intention is to create a plain Node.js TCP server on the machine. 我的目的是在机器上创建一个普通的Node.js TCP服务器。 The code is as follows: 代码如下:

var net = require('net');

var HOST = '0.0.0.0';
var PORT = 110;

net.createServer(function(sock) {
        console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort);
        sock.on('data', function(data) {
        console.log('DATA ' + sock.remoteAddress + ': ' + data);
        sock.write('You said "' + data + '"');

    });


}).listen(PORT, HOST);
console.log('Server listening on ' + HOST +':'+ PORT);

The client is: 客户是:

var net = require('net');

var HOST = '104.197.23.132';
var PORT = 110;

var client = new net.Socket();
client.connect(PORT, HOST, function() {
    console.log('CONNECTED TO: ' + HOST + ':' + PORT);
    client.write('I am Chuck Norris!');

});
client.on('data', function(data) {
    console.log('DATA: ' + data);
    client.destroy();

});
client.on('close', function() {
    console.log('Connection closed');
});

My firewall rules are as follows: 我的防火墙规则如下:

在此输入图像描述

PLEASE NOTE: I am listening on port 110, and the client is trying to connect to the static external ip address. 请注意:我正在侦听端口110,客户端正在尝试连接到静态外部IP地址。 Itt appears that I am enabling TCP traffic over 110 according to firewall rules. 根据防火墙规则,我似乎正在启用超过110的TCP流量。 The error I see is 我看到的错误是

Error: connect ETIMEDOUT 104.197.23.132:110

When I ssh into the instance, and run tcp client, I connect successfully. 当我进入实例并运行tcp客户端时,我成功连接。 So the final question is, why can't local tcp client (my computer) connect to compute instance? 所以最后一个问题是,为什么本地tcp客户端(我的电脑)不能连接到计算实例? Is there something wrong with my firewall rules / source filters / IP forwarding? 我的防火墙规则/源过滤器/ IP转发有问题吗?

在此输入图像描述 I just solved this problem. 我刚刚解决了这个问题。

You have the wrong targets. 你有错误的目标。 Go to the edit page and click the select menu of "Targets", and then you can select the first option "Apply to all instance" that is the easiest way. 转到编辑页面并单击“目标”的选择菜单,然后您可以选择第一个选项“应用于所有实例”,这是最简单的方法。

You need to first add firewall rule according to your host's IP, as internal traffic needs to be received from that particular host (your machine) Then you should be able to ping to GCP Compute Instance. 您需要首先根据主机的IP添加防火墙规则,因为需要从该特定主机(您的计算机)接收内部流量然后您应该能够ping到GCP计算实例。 You should also be able to telnet at the particular port which you configured in your program. 您还应该能够在程序中配置的特定端口上进行telnet。

This should be okay. 这应该没问题。 Also - the customized rule should be added in the Network Tags of instance, to make the rule associated to that instance, after this the instance uses that particular rule. 此外 - 应在实例的网络标记中添加自定义规则,以使规则与该实例关联,然后实例使用该特定规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改 GCP 计算引擎? - Making changes GCP compute engine? 使用防火墙和 IAP 从 App Engine 或 CLoud Run 连接到 Compute Engine - Connect to Compute Engine From App Engine or CLoud Run with firewall and IAP GCP计算引擎-无法在端口80上侦听? - GCP Compute Engine - cannot listen on port 80? 需要外部防火墙的 NodeJS TLS/TCP 服务器 - NodeJS TLS/TCP server in need of an external firewall VM防火墙规则更新 - VM firewall rules update GCP - 使用自定义Auth系统计算每组/用户访问ACL的存储 - GCP - Compute Engine to Storage per group/user access ACL with custom Auth system 部署到 GCP App Engine,但不提供服务器端呈现的页面 - Deployment to GCP App Engine, but not serving Server Side Rendered pages 是否有gcloud API可以检测Compute Engine服务器何时完全启动? - Is there a gcloud API to detect when a Compute Engine server is completely up? 在Google Compute Engine Debian服务器上运行Node.js - Run Node.js on a Google Compute Engine Debian server 从Google Compute Engine外部访问Node.js服务器 - Reaching Node.js server externally from Google Compute Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM