阿里云centos配置iptables防火墙

紫long 紫long     2022-08-08     220

关键词:

虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT。OUTPUT和FORWORD都是ACCEPT的规则

一、检查iptables服务状态

首先检查iptables服务的状态

[root@woxplife ~]# service iptables status
iptables: Firewall is not running.

说明iptables服务是有安装的,但是没有启动服务。
如果没有安装的话可以直接yum安装

yum install -y iptables

启动iptables

[root@woxplife ~]# service iptables start
iptables: Applying firewall rules:                         [  OK  ]

看一下当前iptables的配置情况

[root@woxplife ~]# iptables -L -n

二、清除默认的防火墙规则

复制代码
#首先在清除前要将policy INPUT改成ACCEPT,表示接受一切请求。
#这个一定要先做,不然清空后可能会悲剧
iptables -P INPUT ACCEPT
 
#清空默认所有规则
iptables -F
 
#清空自定义的所有规则
iptables -X
 
#计数器置0
iptables -Z
复制代码

三、配置规则

复制代码
#允许来自于lo接口的数据包
#如果没有此规则,你将不能通过127.0.0.1访问本地服务,例如ping 127.0.0.1
iptables -A INPUT -i lo -j ACCEPT 
 
#ssh端口22
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
 
#FTP端口21
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
 
#web服务端口80
iptables -A INPUT -p tcp --dport 80 -j ACCEP
 
#tomcat
iptables -A INPUT -p tcp --dport xxxx -j ACCEP
 
#mysql
iptables -A INPUT -p tcp --dport xxxx -j ACCEP
 
#允许icmp包通过,也就是允许ping
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
 
#允许所有对外请求的返回包
#本机对外请求相当于OUTPUT,对于返回数据包必须接收啊,这相当于INPUT了
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
 
#如果要添加内网ip信任(接受其所有TCP请求)
iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
 
#过滤所有非以上规则的请求
iptables -P INPUT DROP
复制代码

四、保存

首先iptables -L -n看一下配置是否正确。
没问题后,先不要急着保存,因为没保存只是当前有效,重启后就不生效,这样万一有什么问题,可以后台强制重启服务器恢复设置。
另外开一个ssh连接,确保可以登陆。

确保没问题之后保存

#保存
[root@woxplife ~]# service iptables save
 
#添加到自启动chkconfig
[root@woxplife ~]# chkconfig iptables on

iptables防火墙

...闭也可以)cmd-->telnet47.52.xxx.xxx99 02__安装iptables安装防火墙centos6.8/etc/sysconfig/没有iptables安装iptablesiptables-POUTPUTACCE 查看详情

阿里云服务开放端口配置

...程序连接服务;显示连接成功     阿里云服务器防火墙关闭了,iptables的INPUT和OUTPUT规则还是在生效;2.安全组配置规则   在云服务器管理控制台配置访问规则,开放指定端口;    查看详情

centos下配置iptables防火墙linuxnat(iptables)配置

CentOS下配置防火墙配置nat转发服务CentOS下配置iptables防火墙linuxNAT(iptables)配置CentOS下配置iptables 1,vim/etc/sysconfig/network 这里可以更改主机名称。NETWORKING=yesNETWORKING_IPV6=noHOSTNAME=BGI-TJ.localdomain GATEWAY 查看详情

centos防火墙的配置方法详解iptables

CentOS6/7系统是基于linux中的,它的防火墙其实就是iptables了。下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助。iptables是与Linux内核集成的IP信息包过滤系统,其自带防火墙功能,我们在配置完服务... 查看详情

centos7安装配置iptables防火墙

...下如果不想用centos7自带的FIREwall而用7之前版本的iptables当防火墙,这样自动加端口比较方便,可以如下方式配置:一、关闭Firewall防火墙执行以下操作:systemctlstopfirewalld.servicesystemctldisablefirewalld.service二、安装iptables防火墙yuminstall... 查看详情

centos6下防火墙(iptables)的配置方法详解

CentOS6系统是基于linux中的,它的防火墙其实就是iptables了。下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助。iptables是与Linux内核集成的IP信息包过滤系统,其自带防火墙功能,我们在配置完服务... 查看详情

centos7安装配置iptables防火墙

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761CentOS7默认的防火墙不是iptables,而是firewalle.安装iptable iptable-service [plain] viewplain copy  #先检查是否安装了iptables&n 查看详情

centos切换为iptables防火墙并进行相关配置(代码片段)

CentOS切换为iptables防火墙切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务。1、关闭firewall:servicefirewalldstopsystemctldisablefirewalld.service#禁止firewall开机启动2、安装iptables防火墙yuminstalliptables-services#安装3、编辑iptab 查看详情

centos7.3下的一个iptables配置

centos7.3默认使用的防火墙应该是firewall,而不是iptables。而我们xxmj服务器使用的是iptables防火墙。所以,在配置防火墙之前,我们需要先关闭firewall,安装iptables。查看firewall的安装和启动状态[[email protected]~]#yumlistinstalledfirewall... 查看详情

centos7.3下的一个iptables配置

centos7.3默认使用的防火墙应该是firewall,而不是iptables。而我们如果想要再服务器上使用iptables防火墙,在配置防火墙之前,我们需要先关闭firewall,安装iptables。当前环境:[[email protected] ~]# cat /etc/redhat-release Ce... 查看详情

centos7关闭firewall安装iptables并配置

一、配置防火墙,开启80端口、3306端口CentOS7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service #停止firewallsystemctldisablefirewalld.service #禁止firewall开机启动 2、安装iptables... 查看详情

centos7的防火墙怎么开放端口

可以用iptables防火墙试试CentOS_6.5配置iptables防火墙策略#清除预设表filter中的所有规则链的规则iptables-F#清除预设表filter中使用者自定链中的规则iptables-X#保存iptables配置serviceiptablessave#重启iptables服务serviceiptablesrestart#查看iptables规... 查看详情

转载centos7关闭firewall防火墙指令以及更换安装iptables并配置

转载连接 http://ashui.net/archives/2015/943.html 一、配置防火墙,开启80端口、3306端口CentOS7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service#停止firewallsystemctldisablefirewalld 查看详情

centos7关闭firewall安装iptables并配置

 一、配置防火墙,开启80端口、3306端口CentOS7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service #停止firewallsystemctldisablefirewalld.service #禁止firewall开机启动 2、安装ipta 查看详情

centos7关闭firewall安装iptables并配置(转)

http://www.cnblogs.com/valu/p/5649689.html 一、配置防火墙,开启80端口、3306端口CentOS7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service #停止firewallsystemctldisablefirewalld. 查看详情

centos7配置iptables规则(代码片段)

 iptables,是Linux下自带的一款免费的基于包过滤的防火墙工具,可以对流入、流出、流经服务的数据包进行精细的控制,而在centos7中将iptables给取消掉了,我们需要自行安装,下面介绍iptables的安装及使用。    一、安装ipt... 查看详情

centos7防火墙firewalld和centos6防火墙iptables的一些配置命令

CentOS7防火墙一、防火墙的开启、关闭、禁用、查看状态命令(1)启动防火墙:systemctlstartfirewalld(2)关闭防火墙:systemctlstopfirewalld(3)设置开机启用防火墙:systemctlenablefirewalld.service(4)设置开机禁用防火墙:systemctldisablefire... 查看详情

centos防火墙的配置(代码片段)

CentOS防火墙的配置1、CentOS6.*iptables1.1、红帽官方文档:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security_guide/sect-security_guide-firewalls1.2、安装:yuminstalliptables-y1.3、开启关闭iptables服务:这是临时操作,重启服务器... 查看详情