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

相关推荐
23124_8014 分钟前
Cookie伪造
运维·服务器
石像鬼₧魂石21 分钟前
Windows Server 2003 域控制器靶机搭建与渗透环境配置手册
linux·windows·学习
Bits to Atoms22 分钟前
宇树机器人二次开发环境配置 -- docker创建
运维·docker·容器
RisunJan24 分钟前
Linux命令-killall(根据进程名称来终止一个或多个进程)
linux·运维·服务器
信码由缰25 分钟前
塑造2026年的六大软件开发与DevOps趋势
运维·devops
小-黯38 分钟前
Linux桌面入口文件.desktop文件内容格式
linux·运维·服务器
Serverless社区1 小时前
探秘 AgentRun|基于 Serverless 的 AI Agent 沙箱工程化之路
运维·阿里云·云原生·serverless·函数计算
CheungChunChiu1 小时前
Flutter 在嵌入式开发的策略与生态
linux·flutter·opengl
十五年专注C++开发1 小时前
CMake基础: 在release模式下生成调试信息的方法
linux·c++·windows·cmake·跨平台构建
不会代码的小猴1 小时前
Linux环境编程第三天笔记
linux·笔记