iptables(3)
----------------------------iptables企业应用
****************************单机防火墙列表
#!/bin/bash
#===================<set variable>=================
IPT=/sbin/iptables
SERVER=192.168.0.1
PARTNER=192.168.0.200
#===================<Clear Original Rule>==========
$IPT -A INPUT -p tcp -m state --state INVALID -j DROP
$IPT -A INPUT -p tcp -d $SERVER --dport 25 -j ACCEPT
$IPT -A INPUT -p tcp -d $SERVER --dport 80 -j ACCEPT
$IPT -A INPUT -p tcp -d $SERVER --dport 110 -j ACCEPT
$IPT -A INPUT -p tcp -s $PARTNER -d $SERVER --dport 22 -j ACCEPT
$IPT -A INPUT -p tcp -s $PARTNER -d $SERVER --dport 23 -j ACCEPT
$IPT -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
****************************网关防火墙列表
-------外网 --------------------网关防火墙-------------------内网PC1 192.168.0.200
10.0.100 eth0 eth1 |
10.0.1.200 192.168.0.1 内网PC2 192.168.0.100
#!/bin/bash
#===================<set variable>=================
IPT=/sbin/iptables
MAIL_SER=10.0.1.100
ACC_PC=192.168.0.200
INTERNAL=192.168.0.0/24
EXTERNAL=10.0.1.200
#===================<Set Default Policy>==========
echo 1 > /proc/sys/net/ipv4/ip_forward
$IPT -t filter -P INPUT DROP
$IPT -t filter -P FORWARD DROP
#===================<Clear Original Rule>=========
$IPT -t filter -F
#===================<Set INPUT Rule>==============
$IPT -A INPUT -p tcp -m state --state INVALID -j DROP
$IPT -A INPUT -p tcp -m state --state ESTABLISEHD,RELATED -j ACCEPT
#===================<Set FORWARD Rule>==============
$IPT -A FORWARD -i eth0 -o eth1 -m state --state INVALID -j DROP
$IPT -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISEHD,RELATED -j ACCEPT
$IPT -A FORWARD -i eth1 -o eth0 -p tcp -s $ACC_PC -d $MAIL_SER --dport 25:100 -j ACCEPT
$IPT -A FORWARD -i eth1 -o eth0 -p all -s $ACC_PC -j DROP
$IPT -A FORWARD -i eth1 -o eth0 -p tcp --dport 25,110 -j ACCEPT
$IPT -A FORWARD -i eth1 -o eth0 -p tcp --dport 80,443 -j ACCEPT
$IPT -A FORWARD -i eth1 -o eth0 -p udp --dport 53 -j ACCEPT
$IPT -A POSTROUTING -o eth0 -s $INTERNAL -j NAT --to $EXTERNAL
****************************发布ssh端口
-------外网 --------------------网关防火墙-------------------内网PC1 192.168.0.200
10.0.100 eth0 eth1 |
10.0.1.200 192.168.0.1 内网PC2 192.168.0.100
#!/bin/bash
#===================<set variable>=================
IPT=/sbin/iptables
INTERNAL=192.168.0.0/24
NAT_E=10.0.1.200
PC1=192.168.0.200
PC2=192.168.0.100
#===================<Set Default Policy>==========
echo 1 > /proc/sys/net/ipv4/ip_forward
#===================<Clear Original Rule>=========
$IPT -t filter -F
$IPT -t nat -F
#===================<Set INPUT Rule>==============
$IPT -A INPUT -p tcp -m state --state INVALID -j DROP
$IPT -A INPUT -p tcp -m state --state ESTABLISEHD,RELATED -j ACCEPT
#===================<Set PREROUTING Chain>==============
$IPT -A PREROUTING -i eth0 -p tcp --dport 22 -j DNAT --to $PC1:22
$IPT -A PREROUTING -i eth0 -p tcp --dport 22 -j DNAT --to $PC1:23
#===================<Set POSTROUTING Chain>==============
$IPT -A POSTROUTING -o eth0 -s $INTERNA -j DNAT --to $NAT_E
*****************升级kernel
# rpm -ivh kernel-2.6.32-431.5.1.el6.src.rpm
# cd rpmbuild/SOURCES
# tar -jxvf linux-2.6.32-431.5.1.el6.tar.bz2 -C /usr/src/
# cd /usr/src/
# ln -sv linux-2.6.32-431.5.1.el6 linux
# tar -zxvf netfilter-layer7-v2.23.tar.gz -C /usr/src/
# cd /usr/src/linux
# patch -p1 < /usr/src/netfilter-layer7-v2.23/kernel-2.6.32-layer7-2.23.patch
# cp /boot/config-2.6.32-431.el6.x86_64 ./config
你多次使用了这些源程序编译内核,那么最好要先运行一下这个命令
#make mrproper
使用make oldconfig可以继承老的kernel的配置,为自己的配置省去很多麻烦
#make oldconfig
#make menuconfig是文字界面下推荐一种方式,在这里可以选择你需要编译到核心的模块
# make menuconfig
yum install gcc* -y
yum install ncurses-devel -y
# make menuconfig
空格键用于选择配置类型
对不同功能的配置选择
[ ]:空选时表示不需要在新内核中使用该功能
[ M ]:表示将此项功能编译为模块,以便在需要时加载 Module
[ * ]:将此项功能直接编入新内核,作为新内核的一部分需要配置哪些内核编译参数
*/
#Networking support --->
# Networking options --->
# Network packet filtering framework (Netfilter) --->
# iP:netfilter configuraton --->
<M> IPv4 connection tracking support (required for NAT)
# Full NAT
#Networking support --->
# Networking options --->
# Network packet filtering framework (Netfilter) --->
# core netfilter configuration --->
<M> Netfilter connection tracking support
# "connlimit" match support"
# "time" match support
# "string" match support
# "layer7" match support
# [*] Layer 7 debugging output
或者:
Networking support → Networking Options →Network packet filtering framework →Code Netfilter Configuration
Ü <M> Netfilter connection tracking support
Ü <M> “layer7” match support
Ü <M> “string” match support
Ü <M> “time” match support
Ü <M> “iprange” match support
Ü <M> “connlimit” match support
Ü <M> “state” match support
Ü <M> “conntrack” connection match support
Ü <M> “mac” address match support
Ü <M> "multiport" Multiple port match support
v Networking support → Networking Options →Network packet filtering framework → IP: Netfilter Configuration
Ü <M> IPv4 connection tracking support (required for NAT)
Ü <M> Full NAT
v <M> MASQUERADE target support
# make (报错)
‘ksign_def_public_key’ undeclared (first use in this function)
解决方法:
#make menuconfig(进入基于文本菜单的配置界面)
1.选择”Enable loadable module support“,选择"Module signature verification (EXPERIMENTAL)",按”N“取消该选项。
2.回到主菜单(main menu),选择”Cryptographic API“,取消”In-kernel signature checker (EXPERIMENTAL)“即可。
# make modules
# make modules_install
# make install
# vim /boot/grub/grub.conf (选择新内核)
# reboot
# cp /etc/init.d/iptables ~/
# cp /etc/sysconfig/iptables-config ~/
# rpm -e iptables-1.4.7-11.el6.x86_64 --nodeps
# tar -jxvf iptables-1.4.12.1.tar.bz2 -C /usr/src/
# cd /usr/src/iptables-1.4.12.1/
# cp /usr/src/netfilter-layer7-v2.23/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* ./extensions/
# ./configure --prefix=/usr --with-ksource=/usr/src/linux
# make
# make install
# tar -zxvf I7-protocols-2009-05-28.tar.gz
# cd l7-protocols-2009-05-28/
# make install
# mv ~/iptables /etc/init.d/
# cp iptables-config /etc/sysconfig/
# cp /usr/sbin/iptables /sbin/
# cp /usr/sbin/iptables-restore /sbin/
# cp /usr/sbin/iptables-save /sbin/
# /etc/init.d/iptables restart
# iptables -t mangle -A POSTROUTING -m layer7 --l7proto qq -j DROP
# iptables -A FORWARD -m layer7 --l7proto qq -j REJECT 禁止QQ登录
# iptables -t mangle -I PREROUTING -m layer7 --l7proto edonkey -j DROP
测试:
iptables -t mangle -A POSTROUTING -m layer7 --l7proto qq -j DROP
iptables(3)的更多相关文章
- iptables
一.在服务器上打开 22.80.9011端口: iptables -A INPUT -p tcp --dport 9011 -j ACCEPT iptables -A OUTPUT -p tcp -- ...
- 浅谈iptables 入站 出站以及NAT实例
--------------本文是自己工作上的笔记总结,适合的可以直接拿去用,不适合的,适当修改即可!--------------- iptbales默认ACCEPT策略,也称通策略,这种情况下可以做 ...
- Failed to stop iptables.service: Unit iptables.service not loaded.
redhat 7 [root@lk0 ~]# service iptables stop Redirecting to /bin/systemctl stop iptables.service Fai ...
- CentOS7安装iptables防火墙
CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...
- linux iptables常用命令之配置生产环境iptables及优化
在了解iptables的详细原理之前,我们先来看下如何使用iptables,以终为始,有可能会让你对iptables了解更深 所以接下来我们以配置一个生产环境下的iptables为例来讲讲它的常用命令 ...
- CentOS系统配置 iptables防火墙
阿里云CentOS系统配置iptables防火墙 虽说阿里云推出了云盾服务,但是自己再加一层防火墙总归是更安全些,下面是我在阿里云vps上配置防火墙的过程,目前只配置INPUT.OUTPUT和FO ...
- /etc/sysconfig/下找不到iptables文件解决方法
时间:2014-12-19 01:17来源:csdn 作者:大智 举报 点击:5639次 本想做些防火墙策略.防火墙策略都是写在/etc/sysconfig/iptables文件里面的.可我发现我也没 ...
- docker通过iptables修改或新增镜像映射端口
443 8088 22 端口是初始映射端口 [root@SERVER ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAM ...
- lnmp 预设iptables设置
「LNMP」iptables初始配置 首先使用命令iptables -P INPUT ACCEPT允许所有连接,否则容易把自己关在外边.然后使用iptables -F;iptables -X;ip ...
- 关闭SELinux和iptables防火墙
1.关闭SELinux: 编辑SELinux配置文件: [root@Redis selinux]# vim /etc/selinux/config 修改SELINUX配置项为disable SELIN ...
随机推荐
- asp.net mvc导出execl_转载
public FileResult ExportExcel() { var sbHtml = new StringBuilder(); sbHtml.Append("<table bo ...
- 生命周期函数以及vue的全局注册
beforeCreate 在创造实例之前 created 创造实例以后 beforeMount 在挂载前 render 渲染节点到页面上 //将虚拟dom数组渲染出来 mounted 挂载以后 bef ...
- flutter图片铺满父框
正常我们需要显示一张图片,会用到Image这个控件. 打个比方,我们加载一张本地的图片, 先看一下这个Image.asset的源码: Image.asset(String name, { Key ke ...
- B站弹幕姬(🐔)分析与开发(上篇)
辞职之后 休息了一段时间,最近准备开始恢复去工作的状态了,所以搞点事情来练练手.由于沉迷b站女妆大佬想做个收集弹幕的然后根据弹幕自动回复一些弹幕的东西.网上搜了一下有个c#的版本,感觉还做得不错,于是 ...
- Python:matplotlib绘制散点图
与线型图类似的是,散点图也是一个个点集构成的.但不同之处在于,散点图的各点之间不会按照前后关系以线条连接起来. 用plt.plot画散点图 奇怪,代码和前面的例子差不多,为什么这里显示的却是散 ...
- Python自动化运维之pexpect从入门到精通
1. 应用场景 模拟ssh, telnet远程登录, 模拟ftp文件上传 2. 安装 参考资料: <pexpect实例分析>https://www.ibm.com/developerwor ...
- DBExpress动态连接SQL-Server
procedure TForm1.Button1Click(Sender: TObject);var theCNN : TSQLConnection;//定义连接,要引用 DB, SqlExprbe ...
- easyui combobox 在datagrid中动态加载数据
场景:datagrid 中用编辑框修改数据,有一个列使用的combobox 在可编辑的时候需要动态绑定数据,这个数据是在根据其他条件可变的 思路:在每次开启编辑框的时候动态绑定数据, datagri ...
- 学习 Spring (十六) AOP API
Spring入门篇 学习笔记 Spring AOP API 是 Spring 1.2 历史用法,现在仍然支持 这是 Spring AOP 基础,现在的用法也是基于历史的,只是更简便了 Pointcut ...
- spring和junit整合