selinux端口标记(基于yum仓的配置)(实验需要两个虚拟机:一台CentOs,一台红帽6)

https://blog.csdn.net/yanjun821126/article/details/80828908?utm_source=app&app_version=4.17.2&code=app_1562916241&uLinkId=usr1mkqgl919blenhttps://blog.csdn.net/yanjun821126/article/details/80828908?utm_source=app&app_version=4.17.2&code=app_1562916241&uLinkId=usr1mkqgl919blenhttps://blog.csdn.net/yanjun821126/article/details/80828908?utm_source=app&app_version=4.17.2&code=app_1562916241&uLinkId=usr1mkqgl919blen

[root@cento211 yum.repos.d]# semanage port -l 

1.基于yum 仓配置是否配置完好

 查看两台虚拟机的IP地址:

2.查看端口号相对应的列表 

[root@cento211 yum.repos.d]# semanage port -l 

3.安装httpd

[root@cento211 yum.repos.d]# yum -y install httpd

4.启用httpd

[root@cento211 yum.repos.d]# systemctl enable httpd 
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

5.编辑网页文件

[root@cento211 yum.repos.d]# vi /var/www/html/index.html 
I will be successful!!!

6.修改主配置文件

[root@cento211 yum.repos.d]# vi /etc/httpd/conf/httpd.conf
(把端口号80修改成82)(注意:查找 /Listen 将端口号80 修改成82端口)

7.查看selinux当前的状态

[root@cento211 yum.repos.d]# getenforce
Enforcing(当前状态)

8.启动当前的服务

root@cento211 yum.repos.d]# systemctl start httpd

9.会报错,可以查看哪里出错

[root@cento211 yum.repos.d]# systemctl status httpd.service -l

 10.端口报错解决此问题

(1)查看端口号:

[root@cento211 yum.repos.d]# semanage port -l |grep http
[root@cento211 yum.repos.d]# firewall-cmd --list-all 
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: dhcpv6-client ssh
  ports: (没有端口号)
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

添加82端口号:

[root@cento211 yum.repos.d]# semanage port -a -t http_port_t -p tcp 82

查看82端口号后查看:

开启httpd 的服务

[root@cento211 yum.repos.d]# systemctl start httpd

本机测试:

root@cento211 yum.repos.d]# curl 10.1.1.211:82
I will be successful!!! 

 

在另一台测试机测试

Curl  10.1.1.211(不能连接到主机)

是因为在防火墙默认机制里没有允许82号端口:(添加规则)

[root@cento211 yum.repos.d]# firewall-cmd --permanent --add-port=82/tcp 
success
 

重置

[root@cento211 yum.repos.d]# firewall-cmd --reload 
success

在红帽6测试,测试成功!!!

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>