Linux 开放端口号(mysql/oracle开启远程连接)

版权声明:hxt未经允许不可转载 https://blog.csdn.net/weixin_42979840/article/details/89532458

Linux 开放端口号

Linux 开放端口号(mysql开启远程连接)
在 Centos 7 或 RHEL 7 或 Fedora 中防火墙由 firewalld 来管理,而不是 iptables。
一、firewalld 防火墙
语法命令如下:启用区域端口和协议组合
firewall-cmd [–zone=] --add-port=[-]/ [–timeout=]

此举将启用端口和协议的组合。
端口可以是一个单独的端口 或者是一个端口范围 -。
协议可以是 tcp 或 udp。
查看 firewalld 状态
systemctl status firewalld

开放端口:
// --permanent 永久生效,没有此参数重启后失效
firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent

重新加载:
firewall-cmd --reload

查看端口号是否开启:
firewall-cmd --zone=public --query-port=80/tcp

删除端口号:
firewall-cmd --zone=public --remove-port=80/tcp --permanent
二、iptables 防火墙
也可以还原传统的管理方式使用 iptables

systemctl stop firewalld
systemctl mask firewalld
安装 iptables-services
yum install iptables-services
设置开机启动
systemctl enable iptables
操作命令
systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables
保存设置
service iptables save
开放某个端口 在 /etc/sysconfig/iptables 里添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

三、设置mysql
1.修改/etc/my.cnf 文件
找到bind-address = 127.0.0.1这一行
改为bind-address = 0.0.0.0即可
2.新建用户远程连接mysql数据库
grant all on . to admin@’%’ identified by ‘123456’ with grant option;
flush privileges;
允许任何ip地址(%表示允许任何ip地址)的电脑用admin帐户和密码(123456)来访问这个mysql server。
注意admin账户不一定要存在。
3.支持root用户允许远程连接mysql数据库
grant all privileges on . to ‘root’@’%’ identified by ‘123456’ with grant option;
flush privileges;

猜你喜欢

转载自blog.csdn.net/weixin_42979840/article/details/89532458