本文共 1624 字,大约阅读时间需要 5 分钟。
# 安装命令yum install -y net-tools# 查看进程端口号netstat -nap | grep 进程pid# 查看端口占用# -t (tcp) 仅显示tcp相关选项# -u (udp)仅显示udp相关选项# -n 拒绝显示别名,能显示数字的全部转化为数字# -l 仅列出在Listen(监听)的服务状态# -p 显示建立相关链接的程序名netstat -tunlp | grep 端口号
# 安装yum install -y lsof# 查看指定端口的进程lsof -i:8080# 显示开启文件abc.txt的进程lsof abc.txt# 显示abc进程现在打开的文件lsof -c abc# 列出进程号为1234的进程所打开的文件lsof -c -p 1234# 显示归属gid的进程情况lsof -g gid# 显示目录下被进程开启的文件lsof +d /usr/local/# 同上,但是会搜索目录下的目录,时间较长lsof +D /usr/local/# 显示使用fd为4的进程lsof -d 4# 显示所有打开的端口和UNIX domain文件lsof -i -U
# 开启防火墙systemctl start firewalld.service# 防火墙开机启动systemctl enable firewalld.service# 关闭防火墙systemctl stop firewalld.service# 查看防火墙状态firewall-cmd --state# 查看现有的规则iptables -nL# 查看已开启的端口firewall-cmd --zone=public --list-ports# 重载防火墙配置firewall-cmd --reload# 添加单个单端口firewall-cmd --permanent --zone=public --add-port=81/tcp# 添加多个端口firewall-cmd --permanent --zone=public --add-port=8080-8083/tcp# 删除某个端口firewall-cmd --permanent --zone=public --remove-port=81/tcp# 针对某个 IP开放端口firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="6379" accept"firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.233" accept"# 删除某个IPfirewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.1.51" accept"# 针对一个ip段访问firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.1.0/24" port protocol="tcp" port="9200" accept"# 添加操作后别忘了执行重载firewall-cmd --reload
转载地址:http://nfegf.baihongyu.com/