帮助中心

DNS污染处理

常见问题

香港高防IP

常见问题

新加坡高防服务器

产品简介 操作指南 常见问题

新加坡云服务器

产品简介 操作指南 常见问题

香港服务器租用

产品简介 操作指南 常见问题

香港高防服务器

产品简介 操作指南 常见问题

域名服务

域名服务

CentOS启用iptables防火墙

时间 : 2023-01-17 09:43:44
编辑 : 华纳云

CentOS在7.0之前貌似都是用的iptables为防火墙的,在7.0以后都是firewall,其实我也不知道为嘛,但是大部分人都是用iptables,so我也用它了。

一、关闭firewall

 
1 //停止firewall
2 sudo systemctl stop firewalld.service
3 //禁止firewall开机启动
4 sudo systemctl disable firewalld.service

二、当然就是安装iptables防火墙

1.安装

1 //安装
2 sudo yum install iptables-services

2.配置

//编辑iptables,如果权限不够打开时使用sudo
vi /etc/sysconfig/iptables
//文件内容
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
//保存文件
C+C 然后:wq退出->由于受emacs的习惯这里的C就代表Ctrl,so  C+C其实就是Ctrl+C,以后基本都会那么写,比较方便。
//重启防火墙使配置生效
sudo systemctl restart iptables.service
//设置防火墙开机启动
sudo systemctl enable iptables.service

OK,这时,你的iptables就已经配置好了,如果以后你还想添加端口,那么接着往下看。

3.开放端口

//里面的*要替换成你要开放的端口号
/sbin/iptables -I INPUT -p tcp –dport * -j ACCEPT
//保存配置
/etc/rc.d/init.d/iptables save
//查看你更改后的iptables
/etc/init.d/iptables status
//重启iptables
sudo service iptables restart

好了,这些就是一些有关iptables的基本配置了,有超高难度的东西,也希望大家能告诉我一下。


客服咨询
7*24小时技术支持
Telegram
hncloudnoc

技术支持

渠道支持