当前位置:首页 > linux > 正文内容

linux更改服务端口

six2年前 (2024-04-29)linux1848
在Linux中,更改服务端口通常涉及编辑服务的配置文件。以下是几个常见服务及其默认配置文件的路径,以及更改端口的基本步骤:

SSH服务(默认端口22):

编辑 /etc/ssh/sshd_config 文件,找到 Port 22 并将其更改为你想要的端口号,比如 Port 2222,然后重启SSH服务:sudo systemctl restart sshd.

HTTP服务(Apache,默认端口80):

编辑 /etc/apache2/ports.conf 文件(可能路径根据发行版不同而不同),找到 Listen 80 并更改为 Listen 8080,然后重启Apache服务:sudo systemctl restart apache2.

HTTPS服务(Apache,默认端口443):

编辑 /etc/apache2/ports.conf 文件,找到 Listen 443 并更改为 Listen 4433,然后重启Apache服务。

MySQL数据库(默认端口3306):

编辑 /etc/mysql/my.cnf 或 /etc/mysql/mariadb.cnf 文件,在 [mysqld] 部分添加或修改 port = 3307,然后重启MySQL服务:sudo systemctl restart mysql.

PostgreSQL数据库(默认端口5432):

编辑 /etc/postgresql/<version>/main/postgresql.conf 文件,找到 port = 5432 并更改为 port = 5433,然后重启PostgreSQL服务:sudo systemctl restart postgresql.

Redis服务(默认端口6379):

编辑Redis配置文件 /etc/redis/redis.conf,找到 port 6379 并更改为 port 6380,然后重启Redis服务:sudo systemctl restart redis-server.

确保更改后的端口没有被其他服务使用,并且你的防火墙设置允许通过新端口的流量。

相关文章

Linux系统 ifconfig使用不了 解决方法

1、首先需要先确认是否未配置环境变量,因为ifconfig在“/sbin/”目录,需要使用管理员用户进行操作,使用 echo %PATH 查看用户环境变量 ls /sbin | grep if...

CentOS常用基础命令大全

1.关机 (系统的关机、重启以及登出 ) 的命令 shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3) shutdo...

centos7修改系统时间和修改硬件时间

CentOS7的时间分为系统时间和硬件时间。二者都修改,重启系统才会永久生效。 修改步骤如下 1.查看当前系统时间 date 2.修改当前系统时间 date -s "2022-10-14 19:...

shell脚本编程:将文件中指定行的内容进行替换

(1)在文件中通过关键字查找得到其所在的行号        &nbs...

SFTP基本功之get、put命令操作

登录远程服务器 open xxx.xxx.xxx.xxx // ip get 远程文件名 本地文件名 put 本地文件名 远程文件名 服务器下载至本地 get -r xxxx.xx //...

xshell 之win控制台启动参数

-url [protocol://][user[:password]@]host[:port] xshell 启动参数 xshell -url  ftp://root:123456@192...