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

相关推荐
ltl6 小时前
校验和与数据完整性:CRC32C、xxHash 与端到端校验
linux
我是小灰灰吖7 小时前
Ubuntu 22.04 设置 CPU 性能模式:提升系统响应速度
linux·ubuntu
ltl7 小时前
持续性能分析:Parca、Pyroscope、Grafana Beyla
linux
ltl7 小时前
Direct I/O 与 O_DIRECT:绕过缓存的得与失
linux
盐焗鹌鹑蛋8 小时前
【Linux】进程控制
linux
微三云 - 廖会灵 (私域系统开发)9 小时前
抖店 OPC 自动化运营系统架构与商业代理分控体系完整解析
运维·系统架构·自动化
G31135422739 小时前
大模型不可用时,业务还能不能继续:企业需要设计降级方案
大数据·服务器·数据库·人工智能·深度学习
办公室马主任9 小时前
华南机械加工企业选MES服务商怎么选?
大数据·运维·人工智能·制造
盐焗鹌鹑蛋10 小时前
【Linux】进程程序替换
linux
鸠摩智首席音效师10 小时前
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead
linux