Linux 开放端口

开放之前可以查看下哪些端口开放了,使用命令netstat -ntpl

[root@localhost ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1110/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1190/master
tcp 0 0 :::22 ::😗 LISTEN 1110/sshd
tcp 0 0 ::1:25 ::😗 LISTEN 1190/master
[root@localhost ~]#
如果要开放MySQL数据库端口3306,使用下面的命令

1
2
3
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
执行过程登录

[root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
[root@localhost ~]# /etc/rc.d/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]
[root@localhost ~]# /etc/init.d/iptables restart
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
[root@localhost ~]#
如果要关闭端口,使用下面的命令

1
2
3
4
/sbin/iptables -I INPUT -p tcp --dport 3306 -j DROP
/sbin/iptables -I OUTPUT -p tcp --sport 3306 -j DROP
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
CentOS迷你版没有firewall。需要安装后才能使用。

安装 yum install firewalld

systemctl start firewalld # 启动,

systemctl enable firewalld # 开机启动

systemctl stop firewalld # 关闭

systemctl disable firewalld # 取消开机启动

开放端口和关闭端口

1
2
3

firewall-cmd --zone=public --add-port=8090/tcp --permanent

firewall-cmd --zone=public --remove-port=8090/tcp --permanent

使配置生效

1

firewall-cmd --reload

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值