Fork me on GitHub

CentOS开端口问题

关闭SELINUX

##查看SELINUX状态
/usr/sbin/sestatus -v      
getenforce             

#修改config配置文件,重启后即可
vi /etc/selinux/config    #SELINUX=enforcing改为SELINUX=disabled

#临时关闭(不用重启机器):
setenforce 0      ##设置SELinux 成为permissive模式,
##setenforce 1 设置SELinux 即可成为enforcing模式

CentOS7防火墙

firewall-cmd --state    #显示状态
firewall-cmd --zone=public --list-ports    #查看所有打开的端口
firewall-cmd --reload    #更新防火墙规则
firewall-cmd --get-active-zones    #查看区域信息
firewall-cmd --get-zone-of-interface=eth0    #查看指定接口所属区域
firewall-cmd --panic-on    #拒绝所有包
firewall-cmd --panic-off    #取消拒绝状 态
firewall-cmd --query-panic    #查看是否拒绝
 
#添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)
#重新载入
firewall-cmd --reload
#查看
firewall-cmd --zone=public --query-port=80/tcp
#删除
firewall-cmd --zone=public --remove-port=80/tcp --permanent
systemctl start firewalld    #启动
systemctl status firewalld     #查看状态
systemctl disable firewalld    #停止
systemctl stop firewalld    #禁用
systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
systemctl start firewalld.service    #启动一个服务
systemctl stop firewalld.service    #关闭一个服务
systemctl restart firewalld.service    #重启一个服务
systemctl status firewalld.service    #显示一个服务的状态

systemctl enable firewalld.service    #在开机时启用一个服务
systemctl disable firewalld.service    #在开机时禁用一个服务
systemctl is-enabled firewalld.service    #查看服务是否开机启动

systemctl list-unit-files|grep enabled    #查看已启动的服务列表
systemctl --failed    #查看启动失败的服务列表

CentOS6

修改文件/etc/sysconfig/iptables

    #su vi /etc/sysconfig/iptables 
    -A INPUT -p tcp -m tcp --dport 8066 -j ACCEPT
    # service iptables restart
Linux下开启/关闭防火墙命令
    #1) 永久性生效,重启后不会复原
    #开启: chkconfig iptables on
    #关闭: chkconfig iptables off

    #2) 即时生效,重启后复原
    #开启: service iptables start
    #关闭: service iptables stop

测试

1.确定服务是否启动,端口是否正在被监听

ps -ef|grep mycat

2.netstat测试是否在被监听

netstat -an|grep 8066

打开端口

关闭端口

步骤:

  1. 安装好虚拟机配置好网络 ping 通主机。
  2. 关闭SELINUX。
    vi /etc/selinux/config    #SELINUX=enforcing改为SELINUX=disabled
    reboot    #重启
  3. 开防火墙端口,或者这接关闭(不建议)。
    注意:开了端口后一定要有服务监听(例如Tomcat一定要启动,否则是telnet不通的)!!!也就是说开了端口一定要起服务才能telnet通。
  4. telnet IP port。
posted @ 2018-04-20 20:51  秋夜雨巷  阅读(1107)  评论(0编辑  收藏  举报