Iptables是Linux操作系统常用的防火墙软件,用于服务器的访问控制。Centos7默认的防火墙是Firewalle。个人理解两者都是对规则的配置,Firewalle只是在Iptables基础上进行封装,让操作更简单。内核netfilter执行规则。
本教程使用于 RHEL 7 / CentOS 7,首选查看操作系统的版本:
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@localhost ~]#
本次测试用到的虚拟机地址:192.168.56.5;192.168.56.5;192.168.56.6
1 安装iptables
首先检查是否安装iptables,如果已经安装,或者版本比Centos7低,请略过安装Iptables的步骤,直接看使用和配置。
(1)检查是否安装iptables
[root@localhost ~]# service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.
[root@localhost ~]#
(2)安装前的准备
#停止firewalle
[root@localhost ~]# systemctl stop firewalld
#禁用firewalld服务
[root@localhost ~]# systemctl mask firewalld
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
[root@localhost ~]#
1.1 yum安装
如果目标服务器能够联网,可选择yum的方式安装。
#yum安装iptables
[root@localhost ~]# yum install iptables-services
已加载插件:fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 200 kB 00:00:00
(3/4): base/7/x86_64/primary_db | 6.0 MB 00:00:02
(4/4): 3/3
……省略中间安装日志……
已安装:
iptables-services.x86_64 0:1.4.21-28.el7
作为依赖被升级:
iptables.x86_64 0:1.4.21-28.el7
完毕!
[root@localhost ~]#
(2)安装后验证
#查看是否安装成功
[root@springb