Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to solve the problem that linux cannot be accessed by external hosts

Shulou Source: shulou.com Published: 2022-06-03 00:04:57 10月02日 Update

How to solve the problem that linux cannot be accessed by external hosts? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Reason:

Firewall issu

Solution:

Method 1: turn off the firewall

[root@localhost ~] # service iptables stop # turn off the firewall [root@localhost ~] # service iptables start # turn on the firewall [root@localhost ~] # service iptables status # View the firewall status

The command for cenOS7 or Red Hat7 to operate the firewall has changed, as follows:

[root@localhost ~] # systemctl stop firewalld.service # turn off the firewall [root@localhost ~] # systemctl start firewalld.service # turn on the firewall [root@localhost ~] # systemctl status firewalld.service # View the firewall status

Method 2: open the designated port

[root@localhost ~] # vim / etc/sysconfig/iptables:INPUT ACCEPT [0:0]: FORWARD ACCEPT [0:0]: OUTPUT ACCEPT [0:0]-An INPUT-m state-state RELATED ESTABLISHED-j ACCEPT-An INPUT-p icmp- j ACCEPT-An INPUT-I lo-j ACCEPT-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 22-j ACCEPT-An INPUT-m state-state NEW-m tcp-p tcp-dport 8080-j ACCEPT-An INPUT-j REJECT-reject-with icmp-host-prohibited-A FORWARD-j REJECT-- reject-with icmp-host-prohibited

Note: find the line-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 22-j ACCEPT, and add-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 8080-j ACCEPT after this line to open port 8080

[root@localhost ~] # service iptables restart # restart the firewall to take effect

CenOS7 or Red Hat7 open the port as follows:

[root@localhost ~] # firewall-cmd-- zone=public-- add-port=8080/tcp-- permanentsuccess [root@localhost ~ # firewall-cmd-- reload # Open port only needs to restart the firewall to take effect success

Note: open port command explanation

-zone scope

-add-port=8080/tcp add port, format: Port / communication protocol

-- permanent is in effect forever

So much for the answer on how to solve the problem that linux cannot be accessed by external hosts. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.

Tags: Firewall fire protection port method open question command host line remarks more status help solution easy easy function content reason just need Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno Redmi vpn Apple