linux 查看端口,开启新端口

一、查看端口被占用命令

1、lsof -i:端口号

2、netstat -tunlp|grep 端口号

3、netstat -anp 查看哪些端口被打开 

上面命令是查看端口被进程占用的情况

二、开启新端口

举例:

 开放10000端口的解决步骤如下: 

 1、修改/etc/sysconfig/iptables文件,增加如下一行:  

 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 10000 -j ACCEPT

重启 iptables

service iptables restart
 
 2、重启防火墙,这里有两种方式重启防火墙   a) 重启后生效
  开启: chkconfig iptables on
  关闭: chkconfig iptables off   b) 即时生效,重启后失效
  开启: service iptables start

  关闭: service iptables stop   

  3、或者用menu-system-administration-firewall 

       去添加用户需要的端口。

By the way:

 a.  netstat -tanp 去显示端口状态。

     /usr/sbin/lsof -i 

b. telnet ipaddr port

    to check if ip and port is available before making connection.

 
原文地址:https://www.cnblogs.com/huzi007/p/7890455.html