Home >Operation and Maintenance >Linux Operation and Maintenance >Linux cannot be accessed by external hosts

Linux cannot be accessed by external hosts

王林
王林Original
2019-11-16 09:40:064456browse

Linux cannot be accessed by external hosts

Cause:

Firewall problem

Solution:

Method 1: Turn off the firewall

[root@localhost ~]# service iptables stop         #关闭防火墙
[root@localhost ~]# service iptables start         #开启防火墙
[root@localhost ~]# service iptables status         #查看防火墙状态

The command to operate the firewall in cenOS7 or Red Hat7 has changed. The command is as follows:

[root@localhost ~]# systemctl stop firewalld.service             #关闭防火墙
[root@localhost ~]# systemctl start firewalld.service             #开启防火墙
[root@localhost ~]# systemctl status firewalld.service          #查看防火墙状态

Method 2: Open the specified port

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

Note: Find the line -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT and add ## after this line #-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT , you can open the 8080 port

[root@localhost ~]# service iptables restart      #重启防火墙才能生效

cenOS7 or Red Hat7 open port method is as follows:

[root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanentsuccess
[root@localhost ~# firewall-cmd --reload          #开放端口只需需要重启防火墙才能生效success

Remarks:Open port command explanation

-zone Scope

-add-port=8080/ tcp Add a port, the format is: port/communication protocol

--permanent Permanently effective

Recommended tutorial:

linux tutorial

The above is the detailed content of Linux cannot be accessed by external hosts. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to log in on linux?Next article:How to log in on linux?