linux端口开放、禁止、查看

1、添加\禁止端口

修改配置文件命令:
vim /etc/sysconfig/iptables
添加:
iptables -A INPUT -p tcp –dport p o r t j A C C E P T : i p t a b l e s A I N P U T p t c p d p o r t port -j DROP

启动服务:
/etc/init.d/iptables restart

2、查看开放端口

netstat -nupl (UDP类型的端口)
netstat -ntpl (TCP类型的端口)

a 表示所有
n 表示不查询dns
t 表示tcp协议
u 表示udp协议
p 表示查询占用的程序
l 表示查询正在监听的程序

netstat -ntpl | grep 3306 //这个表示查找处于监听状态的,端口号为3306的进程

[root@home ~]# netstat -ntpl | grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      25302/mysqld   
[root@home ~]# netstat -nupl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
udp        0      0 172.18.1.143:123            0.0.0.0:*                               1526/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               1526/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               1526/ntpd     
[root@home ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:6369                0.0.0.0:*                   LISTEN      3284/beam.smp       
tcp        0      0 0.0.0.0:18083               0.0.0.0:*                   LISTEN      3284/beam.smp       
tcp        0      0 127.0.0.1:8743              0.0.0.0:*                   LISTEN      26488/java          
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      19651/sendmail      
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      24538/nginx       

猜你喜欢

转载自blog.csdn.net/xianglingchuan/article/details/80083364