TCP服务器的GCP计算引擎防火墙规则 [英] GCP Compute Engine Firewall Rules for TCP Server

查看:414
本文介绍了TCP服务器的GCP计算引擎防火墙规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个具有静态外部IP地址的GCP计算引擎实例。机器类型:n1-standard-2(2个vCPU,7.5 GB内存)。 OS是Linux / Debian。





请注意:我正在侦听端口110,并且客户端正尝试连接到静态外部IP地址。 Itt似乎根据防火墙规则启用了超过110的TCP流量。我看到的错误是:

 错误:connect ETIMEDOUT 104.197.23.132:110 

当我进入实例并运行tcp client时,我连接成功。所以最后的问题是,为什么本地tcp客户端(我的电脑)不能连接到计算实例?我的防火墙规则/源过滤器/ IP转发有什么问题吗?

.stack.imgur.com / KBaqS.pngrel =nofollow noreferrer> 我刚刚解决了这个问题。

你有错误的目标。转到编辑页面并单击目标的选择菜单,然后您可以选择第一个选项应用于所有实例,这是最简单的方法。


I have created a GCP compute engine instance with a static external ip address. Machine type: n1-standard-2 (2 vCPUs, 7.5 GB memory). OS is Linux/Debian.

My intention is to create a plain Node.js TCP server on the machine. 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. Itt appears that I am enabling TCP traffic over 110 according to firewall rules. 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. So the final question is, why can't local tcp client (my computer) connect to compute instance? Is there something wrong with my firewall rules / source filters / IP forwarding?

解决方案

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.

这篇关于TCP服务器的GCP计算引擎防火墙规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆