CentOS 7中netstat查询80端口未返回预期结果的技术咨询
Let's break down why your netstat command isn't showing port 80, and walk through how to fix the issue step by step:
1. Fix Your netstat Command First
The problem with your original command netstat -pnltu | grep -i "80" is that it matches any string containing "80"—like the PID 1780 (which has "80" in it) or port 8080. To only target port 80 specifically, use a more precise grep pattern:
# Match exact port 80 (avoids false matches with 8080/PIDs) netstat -pnltu | grep ":80\>" # Or focus only on IPv4 listeners (httpd might not be configured for IPv6) netstat -pnltu4 | grep ":80"
2. Verify httpd is Running
If port 80 still doesn't appear, first check if httpd is even active:
systemctl status httpd
If it shows inactive (dead), start the service and enable it to run on boot:
systemctl start httpd systemctl enable httpd
3. Check httpd's Listen Configuration
It's possible httpd isn't set to listen on port 80. Verify the Listen directives in your configuration files:
# Check the main httpd config file grep -n "Listen" /etc/httpd/conf/httpd.conf # Check additional configs in the conf.d directory grep -r "Listen" /etc/httpd/conf.d/
You should see a line like Listen 80 or Listen 0.0.0.0:80. If not, add this line to /etc/httpd/conf/httpd.conf and restart the service:
systemctl restart httpd
4. Use ss Instead of netstat (CentOS 7 Recommended)
CentOS 7 prefers ss (from the iproute2 package) over the deprecated net-tools (which includes netstat). It's faster and more reliable for checking network listeners:
ss -tulpn | grep ":80"
If httpd is listening on 80, you'll see output similar to:
LISTEN 0 128 *:80 : users:(("httpd",pid=1234,fd=4))
5. Check Firewall Rules
Even if httpd is listening on 80, your firewall might be blocking traffic to the port. Verify your firewalld rules:
firewall-cmd --list-all
If you don't see http or 80/tcp in the services or ports section, add the rule permanently:
firewall-cmd --add-service=http --permanent firewall-cmd --reload
内容的提问来源于stack exchange,提问作者Singam

