2019独角兽企业重金招聘Python工程师标准>>>

CentOS 7 缺省采用了 firewalld ,尽管还是可以安装并支持 iptables,但是还是跟上新东西为好!其实iptables 我也没有用过,哈哈哈!

防火墙功能很强大,但是,日常要做的最多的还是开放端口,记录一下,以便随时 copy

1、 开放 8080 端口

1. 查看防火墙状态sudo systemctl status firewalldsudo firewall-cmd --staterunning
2. 防火墙基本命令# 开启service firewalld start# 重启service firewalld restart# 关闭sudo service firewalld stop# 查看防火墙规则sudo firewall-cmd --list-all sudo firewall-cmd --state
3. 开启 8080 端口sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent重启防火墙sudo systemctl restart firewalld.servicesudo firewall-cmd --reload4. 不知道为什么,就把自己关在外面了 ssh 连接不上去了!sudo firewall-cmd --list-all public (active)target: defaulticmp-block-inversion: nointerfaces: enp0s3sources: services: ssh dhcpv6-clientports: protocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules: ** 可以看到,ports 一个都没有!   ** 干脆重新增加端口的时候,先加上 20,22 端口sudo firewall-cmd --zone=public --add-port=80/tcp --permanentsudo firewall-cmd --zone=public --add-port=22/tcp --permanentsudo firewall-cmd --zone=public --add-port=21/tcp --permanentsudo firewall-cmd --zone=public --add-port=20/tcp --permanentsudo firewall-cmd --zone=public --add-port=8080/tcp --permanentsudo firewall-cmd --zone=public --add-port=4433/tcp --permanent重启防火墙sudo systemctl restart firewalld.service
重新查看防火墙规则sudo firewall-cmd --list-all public (active)target: defaulticmp-block-inversion: nointerfaces: enp0s3sources: services: ssh dhcpv6-clientports: 80/tcp 22/tcp 21/tcp 20/tcp 8080/tcp 4433/tcpprotocols: masquerade: noforward-ports: source-ports: icmp-blocks: rich rules:
** 现在可以安全的退出、重新 ssh 了!

2、再增加一个其他端口 (例如:4433)发生错误

   1. 测试:将以上 chuangke.conf 的端口改成 4433后sudo systemctl restart nginx返回错误!Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.2. 测试 nginx 配置是 OK!sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful3. 查看错误信息sudo systemctl status nginx.service......3月 29 15:07:26 centos7-71 nginx[18289]: nginx: [emerg] bind() to 0.0.0.0:4433 failed (13: Permission denied)......3月 29 15:07:26 centos7-71 systemd[1]: Unit nginx.service entered failed state.3月 29 15:07:26 centos7-71 systemd[1]: nginx.service failed.

** 4433 端口不允许!

3、semanage 解决 http 端口访问配置(Selinux)

参考 https://blog.csdn.net/runsnail2018/article/details/81185138 https://zhb1208.iteye.com/blog/1432957

1. 直接安装 semanage 会提示:没有 semanagesudo yum updatesudo yum install semanage 已加载插件:fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com没有可用软件包 semanage。错误:无须任何处理2. 按照参考文档,执行一下设置和安装命令1). yum provides /usr/sbin/semanage2). yum -y install policycoreutils-python3). 现在就可以执行 semanage 命令了
3. 查看 http 可以访问的端口sudo semanage port -l | grep http_port_thttp_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t            tcp      5988** 果然没有发现 4433 端口!
4. 增加 4433 到 http 访问端口sudo semanage port -a -t http_port_t  -p tcp 4433
5. 再来看看 http 端口
sudo semanage port -l | grep http_port_thttp_port_t                    tcp      4433, 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t            tcp      5988
** 现在可以访问 4433 了sudo systemctl restart nginxsudo systemctl status nginx.serviceOK!

一直没有搞明白 SELinux 干么用的!现在有点儿明白了!

不是简单从防火墙开放一个端口就可以了 还要配置 特定服务(这次是 HTTP)可以使用哪些端口

4、切换root目录一直 403 错误

参考 https://blog.csdn.net/a690392431/article/details/85914076

** 这个博客应该是正确的!但是,我照着操作了,还是不行!

实在没有办法了!
只好先关闭 SELinux !以后再学习!sudo vim /etc/selinux/config# by wzh 20190329 disable SELINUXSELINUX=disabled# SELINUX=enforcing重启才能生效!查看 SELinux
sestatusSELinux status:                 disabled

转载于:https://my.oschina.net/u/1440971/blog/3034354

Centos7 防火墙和Selinux 一些简单操作命令相关推荐

  1. centos7防火墙开启与关闭及开通策略

    文章参考于: Centos7安装防火墙firewall https://www.cnblogs.com/anxminise/p/9650104.html 防火墙(firewalld与iptables) ...

  2. CentOS7关闭防火墙和SELinux

    CentOS7关闭防火墙和SELinux 关闭防火墙 临时关闭防火墙 systemctl stop firewalld 临时打开防火墙 systemctl start firewalld 防火墙开机关 ...

  3. CentOS7防火墙配置

    CentOS7防火墙配置 自CentOS7开始默认防火墙放弃iptables启用了firewall,简单端口配置如下: 添加端口: firewall-cmd –zone=public –add-por ...

  4. 保存linux防火墙配置,centos7 防火墙配置文件_centos7保存防火墙配置

    原标题:centos7 防火墙配置文件_centos7保存防火墙配置 修改防火墙配置文件之前需要对之前防火墙做好备份 重启防火墙后需要确认防火墙状 2.systemctl是CentOS7的服务管理工具 ...

  5. linux centos7保存防火墙设置,修改centos7防火墙设置,修改centos7防火墙

    修改centos7防火墙设置,修改centos7防火墙 一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关 ...

  6. centos7防火墙基本操作

    文章目录 前言 1.查看防火墙是否开启 2.关闭和开启防火墙 3.查看端口开放情况 4.开放8080端口 5.重启防火墙(开放完端口后一定要重启!!!) 6.关闭8080端口 7.查询8080端口是否 ...

  7. CentOS7防火墙添加端口

    CentOS7防火墙添加端口 CentOS防火墻添加端口比较简单,三步走(皆以root用户执行,或者用sudo命令): 1.查看开发的端口 firewall-cmd --zone=public --l ...

  8. CentOS7防火墙服务(Firewalld)关闭实战

    CentOS7防火墙服务(Firewalld)关闭实战 目录 CentOS7防火墙服务(Firewalld)关闭实战 #查看linux服务器防火墙状态

  9. Linux关闭防火墙、SELinux

    使用root权限: Linux关闭防火墙: 1. chkconfig –list|grep iptables 2. chkconfig iptables off 永久关闭防火墙 3. chkconfi ...

最新文章

  1. js中delete是es6_js和es6中的字符串方法总结
  2. Android模拟器emulator-arm.exe出现错误
  3. 粤东农批项目座谈会 农业大健康·李喜贵:功能性农业差异化加工
  4. javascript 对象方法、类方法、原型方法
  5. 华为软件研发面试题1
  6. python条形图的动画显示水能时钟_[宜配屋]听图阁
  7. 使用checked关键字处理“溢出”错误
  8. Kernel那些事儿之内存管理(8) --- Slab(中)
  9. arduino eeg脑电模块_应用深度学习EEGNet来处理脑电信号
  10. 苹果电脑上的Word打不开怎么办?Word文件怎么恢复?
  11. EAP-TLS/EAP-TTLS/EAP-PEAP
  12. Excel 对表格的某一列数据进行名次排序
  13. 【Unity】 节奏类游戏的表盘卡点功能
  14. k8s之PV以及PVC
  15. UUNITY3D插件InControl的简单使用_安卓端连接蓝牙手柄
  16. 小功率静电保护器与TVS管选型,看完醍醐灌顶
  17. 行业研究报告:合束器市场现状及未来发展趋势
  18. 孩子免费就读|私企经理自费赴美国东海岸高校访学
  19. CAD表格制作之CAD软件中如何新建表格?
  20. Scrum的三个工件(产品Backlog、Sprint Backlog、产品增量 )

热门文章

  1. Android 利用源码调试 详解TouchEvent 事件分发机制
  2. 编写你的第一个 Flutter App
  3. java 一次性输入与输出_Java入门——(7)IO(输入与输出)
  4. oracle的乐观锁和悲观锁
  5. docker常用命令行集锦
  6. 【LeetCode】最大子序和
  7. BOM--location对象、history对象
  8. 【BZOJ 4832】 [Lydsy2017年4月月赛] 抵制克苏恩 期望概率dp
  9. 2015 HIAST Collegiate Programming Contest J
  10. 03-25实验一、命令解释程序的编写