Blogger Information
Blog 41
fans 0
comment 1
visits 40389
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
防火墙相关知识(CentOS)
yeyiluLAMP
Original
729 people have browsed it

CentOS 7.x

0:安装

sudo yum install firewalld

1、firewalld的基本使用


启动: service firewalld start

查看状态: service firewalld  status

停止: service firewalld disable

禁用: service firewalld stop


2. 配置firewalld-cmd

查看版本: firewall-cmd --version

查看帮助: firewall-cmd --help

显示状态: firewall-cmd –state

列出所有的区域:firewall-cmd --get-zones

列出默认区域:firewall-cmd --get-default-zone

列出所有区域配置: firewall-cmd --list-all-zone

查看所有打开的端口: firewall-cmd --zone=public --list-ports

查看规则:iptables -L -n

更新防火墙规则: firewall-cmd --reload

查看区域信息:  firewall-cmd --get-active-zones

查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0


3.添加服务

firewall-cmd –add-service=ssh
firewall-cmd –query-service=ssh
firewall-cmd –remove-service=ssh


4.那怎么开启一个端口呢

添加

firewall-cmd --zone=public --add-port=80/tcp

永久生效再加上 --permanent 然后reload防火墙

重新载入

firewall-cmd --reload

查看

firewall-cmd --zone=public --query-port=80/tcp

删除

firewall-cmd --zone=public --remove-port=80/tcp

只允许内网192.168.0.0/16网段开放3306端口

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" port protocol="tcp" port="3306" accept"


CentOS 6.x

0. 配置防火墙

[root@centos6 ~]# vi /etc/sysconfig/iptables        #添加(在22端口那一行下面添加):
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT    #允许80端口通过防火墙

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT    #允许3306端口通过防火墙

#重启防火墙  
[root@centos6 ~]# /etc/init.d/iptables restart


顺便补充下关于LAMP/LNMP环境搭建事前必须做的准备:

1.配置网卡

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 

BOOTPROTO=static
IPADDR=192.168.33.128
NETMASK=255.255.225.0
GATEWAY=192.168.33.2
DNS1=192.168.33.2
ONBOOT=yes

没有的项手动添加,记得重启网卡:

[root@localhost ~]# /etc/init.d/network stop
[root@localhost ~]# /etc/init.d/network start

2. 关闭SELINUX
vi  /etc/sysconfig/selinux

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted

#注释掉SELINUX=disabled #增加

:wq 保存,关闭

setenforce 0   #使配置立即生效


事实上,如果对CentOS7.x默认的防火墙firewalld不熟悉的话,也可以使用CentOS6.x的iptables防火墙

一、防火墙配置

CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1、关闭firewall:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

2、安装iptables防火墙

yum install iptables-services #安装
vi /etc/sysconfig/iptables #编辑防火墙配置文件

# sample configuration for iptables service

# you can edit this manually or use system-config-firewall

# please do not ask us to add additional ports/services to this default configuration

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT


:wq! #保存退出
systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
/usr/libexec/iptables/iptables.init restart #重启防火墙


二、关闭SELINUX


vim  /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

 
:wq! #保存退出

setenforce 0 #使配置立即生效


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post