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

相关推荐
moppol10 分钟前
探索下一代云存储技术:对象存储、文件存储与块存储的区别与选择
服务器
mmsx19 分钟前
使用git生成ssh的ed25519密钥
运维·git·ssh
ZeroNews内网穿透1 小时前
服装零售企业跨区域运营难题破解方案
java·大数据·运维·服务器·数据库·tcp/ip·零售
果子⌂1 小时前
容器技术入门之Docker环境部署
linux·运维·docker
神的孩子都在歌唱2 小时前
常见的网络攻击方式及防御措施
运维·服务器·网络
深度学习04072 小时前
【Linux服务器】-安装ftp与sftp服务
linux·运维·服务器
iteye_99393 小时前
让 3 个线程串行的几种方式
java·linux
渡我白衣4 小时前
Linux操作系统:再谈虚拟地址空间
linux
阿巴~阿巴~4 小时前
Linux 第一个系统程序 - 进度条
linux·服务器·bash
小白爱电脑4 小时前
什么是2.5G交换机?
运维·网络·5g·千兆宽带