码迷,mamicode.com
首页 > 其他好文 > 详细

centos7通过firewalld更改sshd端口

时间:2015-10-17 20:33:00      阅读:413      评论:0      收藏:0      [点我收藏+]

标签:

1.设置selinux端口

[root@hn ~]# semanage port -l|grep ssh
-bash: semanage: 未找到命令
[root@hn ~]# whereis semanage
semanage:

缺少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

 2.设置firewalld里的端口

[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

3.修改sshd_config中的Port

[root@hn ~]# vi /etc/ssh/sshd_config

Port 12345
[root@hn ~]# systemctl restart  sshd.service

4.测试  

  

centos7通过firewalld更改sshd端口

标签:

原文地址:http://www.cnblogs.com/jenqz/p/4888019.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!