自动化运维之Iptables基础及环境安装(十三)

640 阅读3分钟

狼狈不堪怎敢奢求爱情,负债累累怎敢奢求生活。人生只是苟延残喘罢了

iptables简介

  • iptables不是一个单一的软件工具,而是一套C/S样式的软件组,它是由工作在用户空间的iptables和工作在内核空间的Netfilter模块组成,一般统称为Iptables。

  • 用户基于用户空间的iptables软件,来设定各种包过滤规则,借助于后端内核空间的Netfilter模块实现非常强大的防火墙功能,Netfilter实现的功能主要体现在数据包过滤、数据包重定向、网络地址转换等方面。

Netfilter是linux2.4及2.6内核中集成的功能(因为它没有守护进程),它主要存在以下几个目录中:

~]# find /lib/modules/4.18.7-1.el7.elrepo.x86_64/kernel/ -name "netfilter"
/lib/modules/4.18.7-1.el7.elrepo.x86_64/kernel/net/bridge/netfilter
/lib/modules/4.18.7-1.el7.elrepo.x86_64/kernel/net/ipv4/netfilter
/lib/modules/4.18.7-1.el7.elrepo.x86_64/kernel/net/ipv6/netfilter
/lib/modules/4.18.7-1.el7.elrepo.x86_64/kernel/net/netfilter
  • 默认情况下,iptables主要工作在0SI模型中的的2~4层,我们还可以通过重编内核,让iptables支持7层的数据包管理。

iptables 和 Firewalls

在之前的linux系统中,默认的防火墙都是iptables,而随着Redhat|Centos7系统的发布,linux系统的防火墙默默的将iptables转换成了Firewalls,由Firewalls编辑各种各样的数据包管理规则,然后借助于netfilter模块来实现强大的防火墙功能,不过Firewalls的底层操作仍然是iptables,只不过它将繁杂的iptables的手工操作给封装起来,以简单易用的方式提供给大家。

Firewalld动态防火墙管理器服务(Dynamic Firewall Manager of Linux systems)是目前Centos7系统默认的防火墙管理工具,拥有命令行终端和图形化界面的配置工具,

firewalld跟iptables主要有以下区别:

  • firewalls的默认规则是拒绝,需要时设置开启,iptables正好相反。
  • firewalls可以动态修改单条规则,而且直接生效
  • firewalls简单易用,即使不理解各种数据包规则,也可以实现大部分功能。
  • 想要真正学会防火墙规则,强烈推荐学习iptables。 更详细的内容可以参考: access.redhat.com/documentati…

安装iptables

系统基本配置

  • 网络环境
关闭NetworkManager服务
systemctl stop NetworkManager
systemctl disable NetworkManager
  • 安全配置
防火墙
systemctl stop firewalld
systemctl disable firewalld
检查
firewall-cmd --state
selinux
sed -i 's#=enforcing#=disabled#' /etc/selinux/config
检查
grep --color=auto '^SELINUX' /etc/selinux/config
  • 环境主机名规划
hosts文件内容
192.168.8.14 caichen.caichen.com nagios
主机名设置
hostnamectl set-hostname caichen
exec /bin/bash
测试效果:
ping -c 1 caichen
  • 基础软件安装
安装依赖软件
yum install -y wget yum-plugin-priorities

安装软件源
wget -O /etc/yum.repos.d/CentOS-Base-ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
或者
wget -O /etc/yum.repos.d/CentOS-163.repo https://mirrors.163.com/.help/CentOS7-Base-163.repo

源优先级配置
cat /etc/yum/pluginconf.d/priorities.conf
注意:保证 [main] 配置下的 enabled = 1
然后编辑相应的repo文件,在想用的配置文件下增加priority=1

检查
yum repolist
yum clean all && yum makecache fast && yum update -y
  • 禁止内核升级
# vim /etc/yum.conf
...
exclude=kernel* 
exclude=centos-release*
  • 安装系统基础软件
yum groupinstall "Compatibility Libraries" "Console Internet Tools" "Development Tools" "Security Tools" "System Administration Tools" -y

yum install -y vim lrzsz telnet curl net-tools tree bash-completion
  • 时间同步
yum install ntpdate -y
echo '*/10 * * * * /usr/sbin/ntpdate time1.aliyun.com &>/dev/null' >> /var/spool/cron/root
                             _____           _    _____   _
                          / ____|         (_)  / ____| | |
                         | |        __ _   _  | |      | |__     ___   _ __
                         | |       / _` | | | | |      | '_ \   / _ \ | '_ \
                         | |____  | (_| | | | | |____  | | | | |  __/ | | | |
                          \_____|  \__,_| |_|  \_____| |_| |_|  \___| |_| |_|

好了各位,以上就是这篇文章的全部内容了,能看到这里人啊,都是人才。

如果这个文章写得还不错,觉得「王采臣」我有点东西的话 求点赞👍求关注❤️求分享👥 对耿男我来说真的非常有用!!!

白嫖不好,创作不易,各位的支持和认可,就是我创作的最大动力,我们下篇文章见!

王采臣 | 文 【原创】 如果本篇博客有任何错误,请批评指教,不胜感激 !微信公众号: