linux命令行查看端口情况

查看端口的使用的情况

lsof 命令
  • 1

比如查看80端口的使用的情况。

lsof -i tcp:80
  • 1

列出所有的端口

netstat -ntlp
  • 1

查看端口的状态

 /etc/init.d/iptables status
  • 1

开启端口 
开启端口以开启端口80为例。 
1 用命令开启端口:

iptables -I INPUT -p tcp --dport 80 -j accpet --写入要开放的端口
/etc/init.d/iptables save --保存修改
/etc/sysconfig/iptables restart -- 重启防火墙
或者用命令:service iptables restart重启防火墙
  • 1
  • 2
  • 3
  • 4

2 修改/etc/sysconfig/iptables文件。 
这里写图片描述 
保存文件重启防火墙。 
关闭端口 
用命令修改

iptables -I INPUT -p tcp --dport 80 -j DROP--写入修改
/etc/init.d/iptables save --保存修改
service iptables restart --重启防火墙
  • 1
  • 2
  • 3

修改配置文件 vi /etc/sysconfig/iptables:

 -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j DROP   重启防火墙,修改完成

猜你喜欢

转载自blog.csdn.net/weishuai528/article/details/80905396