Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

CentOS 查看端口占用與開啟端口指令教學

在 CentOS 上管理端口,先學會查看占用情況,再來設定開啟或關閉。

查看端口占用

例如查看 80 端口:

lsof -i tcp:80

列出所有端口:

netstat -ntlp

開啟端口(以 80 為例)

方法一:

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
service iptables restart

方法二:編輯設定檔加入一行後重啟防火牆。

vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

關閉端口

方法一:

/sbin/iptables -I INPUT -p tcp --dport 80 -j DROP
/etc/init.d/iptables save
service iptables restart

方法二:編輯設定檔加入一行後重啟防火牆。

vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j DROP

查看端口狀態

/etc/init.d/iptables status
Copyright © Linux教程網 All Rights Reserved