Linux之修改服务端口号

本次演示以SSH服务为例,SSH默认监听端口是22,先保留了22端口,所以我们要进入ssh的配置文件添加新端口并注释或删掉原有端口。

1、使用vi编辑器修改文件 sshd_config,路径是/etc/ssh/sshd_config,找到"#Port 22",添加新的端口号10086。

2、如果你关闭了SELinux,可以忽略第二步

先查看SELinux开放给ssh使用的端口

复制代码
semanage port -l  | grep ssh

可以看到我的系统SELinux没有给SSH开放10086端口,那么咱们自己添加进去

复制代码
semanage port -a -t ssh_port_t -p tcp 10086

再次查看结果

3、如果你关闭了防火墙,可以忽略第三步

检查防火墙是否开通10086端口

复制代码
firewall-cmd --permanent --query-port=10086/tcp

结果显示未开通10086端口,需要开通

复制代码
firewall-cmd  --permanent  --add-port=10086/tcp

再次检查端口已开通

4、重启SSH服务和防火墙

复制代码
systemctl restart sshd
systemctl status sshd
复制代码
systemctl restart firewalld.service
systemctl status firewalld.service

5、尝试通过10086端口登录SSH

注意事项:

在查看SELinux开放给ssh使用的端口(semanage port -l| grep ssh)时,

如果提示:bash: semanage: command not found

则执行下面命令:

使用yum查找提供此功能的的软件包:yum provides semanage

安装policycoreutils-python软件包:yum install policycoreutils-python -y

然后再执行上面的命令

查阅了相关资料,发现是CentOS8上这个包已经换了一个名称了:

It's renamed in el8: policycoreutils-python-utils-2.9-9.el8.noarch

于是使用命令yum -y install policycoreutils-python-utils ,成功安装semanage

相关推荐
dishugj10 分钟前
【linux】Redhat 6.3系统安装zabbix-agent软件包,无法使用YUM源问题
linux·运维·zabbix
无奈笑天下30 分钟前
【麒麟镜像vmtools异常排查指导书】
linux·运维·经验分享·云计算·kylin
dajun18112345632 分钟前
PC端中文免费在线跨职能泳道图制作工具
运维·架构·流程图·敏捷流程·交通物流
Xの哲學1 小时前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
FlourishingMind1 小时前
蓝牙授时CTS (Current Time Service)、PTP、NTP
运维·服务器·网络
2301_800050991 小时前
docker
运维·docker·容器
QT 小鲜肉2 小时前
【Linux命令大全】001.文件管理之mmove命令(实操篇)
linux·服务器·前端·chrome·笔记
Winner13002 小时前
查看rk3566摄像头设备、能力、支持格式
linux·网络·人工智能
MaximusCoder2 小时前
Linux信息收集Command
运维·服务器·经验分享
QT 小鲜肉2 小时前
【Linux命令大全】001.文件管理之mdel命令(实操篇)
linux·运维·服务器·chrome·笔记