centos7通过firewalld更改sshd端口-创新互联
1.设置selinux端口
[root@hn ~]# semanage port -l|grep ssh
-bash: semanage: 未找到命令
[root@hn ~]# whereis semanage
semanage:
本文名称:centos7通过firewalld更改sshd端口-创新互联
分享路径:http://azwzsj.com/article/epsej.html
缺少semanage,需要安装net-tools (这个包同时还包含了ifconfig,否则只能用ip addr看了~)
创新互联公司基于十年网站建设行业经验,一直致力于为中小型企业提供信息化解决方案,创新互联公司做到开放、开源,让企业所有核心数据掌握到企业手里,打破行业乱象,让企业被网络公司掌控的局面不再发生;美工设计部,产品/程序研发部,营销策划部,售后客服部。一切服务为企业量身定制,专注为您![root@hn ~]# yum install net-tools [root@hn ~]# semanage port -l|grep ssh -bash: semanage: 未找到命令安装后还是提示未找到,还需要安装policycoreutils-python
[root@hn ~]# yum -y install policycoreutils-python
[root@hn ~]# semanage port -l|grep ssh ssh_port_t tcp 22 [root@hn ~]# semanage port -a -t ssh_port_t -p tcp 12345 [root@hn ~]# semanage port -l|grep ssh ssh_port_t tcp 12345, 22如果要添加mysql端口,可以: semanage port -a -t mysqld_port_t -p tcp 3306
2.设置firewalld里的端口(特定ip参考:http://www.z4zr.com/page/1006.html, 更多可参考: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7-Beta/html/Security_Guide/sec-Using_Firewalls.html)
[root@hn ~]# systemctl status firewalld firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled) Active: active (running) since 六 2015-10-17 15:51:47 CST; 3h 5min ago Main PID: 807 (firewalld) CGroup: /system.slice/firewalld.service └─807 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid 10月 17 15:51:46 hn.kd.ny.adsl systemd[1]: Starting firewalld - dynamic firewall daemon... 10月 17 15:51:47 hn.kd.ny.adsl systemd[1]: Started firewalld - dynamic firewall daemon. [root@hn ~]# firewall-cmd --zone=public --add-port=12345/tcp --permanent success [root@hn ~]# firewall-cmd --query-port=12345/tcp no [root@hn ~]# systemctl reload firewalld [root@hn ~]# firewall-cmd --query-port=12345/tcp FirewallD is not running [root@hn ~]# firewall-cmd --query-port=12345/tcp FirewallD is not running [root@hn ~]# systemctl start firewalld [root@hn ~]# firewall-cmd --query-port=12345/tcp yes如果添加mysql端口,使其可局部访问,则:firewall-cmd --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.0.4/24" port protocol="tcp" port="3306" accept" --permanent
3.修改sshd_config中的Port
[root@hn ~]# vi /etc/ssh/sshd_config Port 12345[root@hn ~]# systemctl restart sshd.service4.测试
本文名称:centos7通过firewalld更改sshd端口-创新互联
分享路径:http://azwzsj.com/article/epsej.html