#说明:
SELinux将网络端口标记为类型标,因此不可能使用未配置类型的端口来启动服务。
1) 显示端口类型列表
[root@srv1 ~]# semanage port -l
SELinux Port Type Proto Port Number
afs3_callback_port_t tcp 7001
afs3_callback_port_t udp 7001
afs_bos_port_t udp 7007
afs_fs_port_t tcp 2040
afs_fs_port_t udp 7000, 7005
afs_ka_port_t udp 7004
afs_pt_port_t tcp 7002
afs_pt_port_t udp 7002
afs_vl_port_t udp 7003
agentx_port_t tcp 705
......
......
2) 将Apache的监听端口改为8222
[root@srv1 ~]# vim /etc/httpd/conf/httpd.conf
# 修改42行,更改如下
Listen 8222
[root@srv1 ~]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details. # 启动失败
3) 查看SELinux对httpd的默认的端口配置
[root@srv1 ~]# semanage port -l | grep -E -w "80|443"
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
4) 更改port type
[root@srv1 ~]# semanage port -a -t http_port_t -p tcp 8222
[root@srv1 ~]# semanage port -l | grep "^http_port_t"
http_port_t tcp 8222, 80, 81, 443, 488, 8008, 8009, 8443, 9000
5) 测试
[root@srv1 ~]# systemctl restart httpd
[root@srv1 ~]# systemctl is-active httpd
active
[root@srv1 ~]# netstat -lantp | grep 8222
tcp6 0 0 ::: 8222 :::* LISTEN 2174/httpd
|