Linux

無法從 Windows 連接到 Linux 埠

  • April 8, 2020

我正在嘗試在 Linux 上執行 gRPC 服務,同時在 Windows 上執行客戶端。

我似乎無法測試我在 Windows 機器上使用的 Linux 埠。兩台機器都在同一個網路中。Windows 10 和 CentOS 8。

這是 Powershell 給我的:

PS C:\WINDOWS\system32> tnc server_ip -p 55555 -Debug
DEBUG: TCP connect to (server_ip  : 55555) threw exception: Exception 
calling "GetResult" with "0" argument(s): "No connection
could be made because the target machine actively refused it 
server_ip :55555"

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is 
"Y"): y
WARNING: TCP connect to (server_ip  : 55555) failed


ComputerName           : server_ip 
RemoteAddress          : server_ip 
RemotePort             : 55555
InterfaceAlias         : Ethernet
SourceAddress          : client_ip
PingSucceeded          : True
PingReplyDetails (RTT) : 0 ms
TcpTestSucceeded       : False

我對 Linux 了解不多,但這裡有一些命令,我​​試圖檢查埠是否打開以及使用它的服務是否正在執行,以及我得到的結果:

[user@localhost ~]$ grep -w 55555 /etc/services
test        55555/tcp       # TestService

[user@localhost ~]$ sudo lsof -i -P -n | grep LISTEN
[sudo] password for user: 
GrpcServi 10933         user  166u  IPv4 1090871      0t0  TCP 127.0.0.1:55555 (LISTEN)
GrpcServi 10933         user  167u  IPv6 1090874      0t0  TCP [::1]:55555 (LISTEN)

[user@localhost ~]$ sudo netstat -tulpn | grep LISTEN     
tcp        0      0 127.0.0.1:55555         0.0.0.0:*               LISTEN      10933/./GrpcService 
tcp6       0      0 ::1:55555               :::*                    LISTEN      10933/./GrpcService 

[user@localhost ~]$ sudo netstat -tulpn | grep :55555
tcp        0      0 127.0.0.1:55555         0.0.0.0:*               LISTEN      10933/./GrpcService 
tcp6       0      0 ::1:55555               :::*                    LISTEN      10933/./GrpcService 

[user@localhost ~]$ sudo ss -tulpn | grep LISTEN                                               
tcp   LISTEN   0        128              127.0.0.1:55555          0.0.0.0:*      users: 
(("GrpcService",pid=10933,fd=166))                                                                                   
tcp   LISTEN   0        128                  [::1]:55555             [::]:*      users: 
(("GrpcService",pid=10933,fd=167))                                       

[user@localhost ~]$ sudo ss -tulpn | grep ':55555'
tcp   LISTEN   0        128              127.0.0.1:55555          0.0.0.0:*      users: 
(("GrpcService",pid=10933,fd=166))                                       
tcp   LISTEN   0        128                  [::1]:55555             [::]:*      users: 
(("GrpcService",pid=10933,fd=167))                                       

[user@localhost ~]$ sudo lsof -i -P -n | grep LISTEN
GrpcServi 10933         user  166u  IPv4 1090871      0t0  TCP 127.0.0.1:55555 (LISTEN)
GrpcServi 10933         user  167u  IPv6 1090874      0t0  TCP [::1]:55555 (LISTEN)

[user@localhost ~]$ sudo firewall-cmd --zone=public --list-all
[sudo] password for user: 
public (active)
 target: default
 icmp-block-inversion: no
 interfaces: enp2s0
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 3389/tcp 3389/udp 55555/tcp 
 protocols: 
 masquerade: yes
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 

我還嘗試在 Windows 和 Linux 上禁用防火牆以檢查是否有幫助,但無濟於事。

127.0.0.1::1, 是本地環回地址。它們只能從同一台機器上訪問。這就是為什麼您的其他機器看不到它們的原因。

您將需要更改啟動伺服器的方式。告訴它綁定本地網路地址(不是內部網路地址)。

引用自:https://unix.stackexchange.com/questions/578677