socket Connect refused

When using socket for network programming, when the client uses the connect function to connect to the server, sometimes there will be a Connection refused error.

The two reasons for this kind of error (what I have encountered so far) are:

1. The server does not start the corresponding port for listening.

2. There is a firewall on the server, blocking the current access.


Now to solve the second case:

1. When the system is installed with software such as firewall, adjust it according to the corresponding software commands or rules

For example, if we installed firewall, we can use

 The systemctl stop firewalld.service command stops the firewall.

firewall-cmd --state to view the status of the firewall.


2. Using iptables:

iptables -F clears all rules

iptables [-t table] [-AI chain] [-io interface] [-p protocol] [-s source] [-d destination] [--sport range] [--dport range] -j [action] set a rule. [not for nat and mangle]

The value of each placeholder is:

1.table : filter [-t specifies the table of operations]

2.chain : INPUT OUTPUT [-AI specifies the chain of operations]

3.interface: your own network interface [can be obtained through {`ip a`}] [-io Note that this is the network interface specified by the two parameters i/o]

4.protocol : tcp udp[-p specifies the protocol]

5.source : source ip [-s]

6.destination: destination ip [as a forwarding function, it should not be used directly as a server] [-d]

7.range : range of ports {eg 1234:4321 means port 1234 to port 4321}[--sport/--dport]

8.action: ACCEPT/REJECT/DROP[-j specifies the action of this rule, accept/reject/drop]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325898671&siteId=291194637