ubuntu 14.04/14.10 iptables 防火墙设置
1. 一键批处理设置
- #!/bin/bash
- PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin:~/bin
- export PATH
- # Check if user is root
- if [ $UID != 0 ]; then echo "Error: You must be root to run the install script, please use root to install lanmps";exit;fi
- iptables-save >> _.iptables.up.rules #保存防火墙设置,以便没保存时使用
- iptables -L -n 2>&1 | tee -a "_.iptables.log"
- iptables -F #清除预设表filter中的所有规则链的规则
- iptables -X #清除预设表filter中使用者自定链中的规则
- iptables -Z #计数器清零
- iptables -P INPUT DROP
- iptables -P OUTPUT ACCEPT
- iptables -P FORWARD ACCEPT
- #双向
- iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- #允许本机
- iptables -A INPUT -i lo -j ACCEPT
- #FTP
- iptables -A INPUT -p tcp --dport 21 -j ACCEPT
- #SSH
- iptables -A INPUT -p tcp --dport 22 -j ACCEPT
- #www 80
- iptables -A INPUT -p tcp --dport 80 -j ACCEPT
- #13306 映射转发到 mysql数据库 3306
- iptables -A PREROUTING -p tcp --dport 13306 -j REDIRECT --to-ports 3306 -t nat
- #3306 mysql数据库
- #iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
- #memache
- #iptables -A INPUT -p tcp --dport 11211 -j ACCEPT
- #对于OUTPUT规则,因为预设的是ACCEPT,所以要添加DROP规则,减少不安全的端口链接。
- iptables -A OUTPUT -p tcp --sport 31337 -j DROP
- iptables -A OUTPUT -p tcp --dport 31337 -j DROP
- #丢弃坏的TCP包
- iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
- #处理IP碎片数量,防止攻击,允许每秒100个
- #iptables -A FORWARD -f -m limit --limit 100/s --limit-burst 100 -j ACCEPT
- #设置ICMP包过滤,允许每秒1个包,限制触发条件是10个包
- #iptables -A FORWARD -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
- #防止外部的ping和SYN洪水攻击
- iptables -A INPUT -p tcp --syn -m limit --limit 100/s --limit-burst 100 -j ACCEPT
- #ping洪水攻击,限制每秒的ping包不超过10个
- iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s –limit-burst 10 -j ACCEPT
- #防止各种端口扫描,将SYN及ACK SYN限制为每秒钟不超过200个
- iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -m limit --limit 20/sec --limit-burst 200 -j ACCEPT
- #最后规则拒绝所有不符合以上所有的
- iptables -A INPUT -j DROP
- if [ -z "`grep "iptables-save" /etc/network/interfaces`" ]
- then
- echo "#以下有防火墙需要的可以使用
- pre-up iptables-restore < /etc/iptables.up.rules #启动时应用防火墙
- post-down iptables-save > /etc/iptables.up.rules #关闭时保存防火墙设置,以便下次启动时使用 " >> /etc/network/interfaces
- else
- echo "iptables-save find "
- fi
- clear
- echo "iptables ok ";
- echo ""
- iptables -L -n
- cat /etc/network/interfaces
把上面的保存为 (如果还有其他端口规则请一起在上面配置,执行时清空规则):
- lanmps_iptables.sh
上传到服务器然后设置权限,并执行
- chmod 777 lanmps_iptables.sh
- ./lanmps_iptables.sh
那么 防火墙就设置完成了
2. ubuntu iptables 防火墙 启动
- modprobe ip_tables
3. ubuntu iptables 防火墙 关闭
- modprobe ip_tables
ubuntu 并没有关闭命令,所以要通过变通方法解决防火墙
- iptables -F
- iptables -X
- iptables -Z
- iptables -P INPUT ACCEPT
- iptables -P OUTPUT ACCEPT
- iptables -P FORWARD ACCEPT
- modprobe -r ip_tables
- 依次执行以上命令即可关闭iptables,否则在执行modproble -r ip_tables时将会提示 FATAL: Module ip_tables is in use.
4. Iptables的保存和调用
防止每次开机或重启后都需要去调用一次,把它设置自动执行
第一步 更改网卡配置文件
- sudo vi /etc/network/interfaces
第二部 在最后增加配置
- #以下有防火墙需要的可以使用
- pre-up iptables-restore < /etc/iptables.up.rules #启动时应用防火墙
- post-down iptables-save > /etc/iptables.up.rules #关闭时保存防火墙设置,以便下次启动时使用
如果不明白的看 http://blog.csdn.net/fenglailea/article/details/12191607#t1
感谢:http://hongwei.im/iptables-setting-for-ubuntu-1304
ubuntu 14.04/14.10 iptables 防火墙设置的更多相关文章
- IPTables系列:如何配置Ubuntu 14.04中的IPTables防火墙
IPTables基本命令 在向大家介绍复杂防火墙规则之前,还是先上一些简单的料,让大家对IPTables最为基本的命令有一些简单了解. 首先要说明的是IPTables命令必需以root权限运行,这意味 ...
- CVE-2015-1328 Ubuntu 12.04, 14.04, 14.10, 15.04 overlayfs Local Root
catalog . 引言 . Description . Effected Scope . Exploit Analysis . Principle Of Vulnerability . Patch ...
- Fix catalyst driver in Ubuntu 13.04 / 13.10
Fix catalyst driver in Ubuntu 13.04 / 13.10(墙外文章备份) 1. Introduction I found lots of people strugglin ...
- Ubuntu 13.04/12.10安装Oracle 11gR2图文教程(转)
Ubuntu 13.04/12.10安装Oracle 11gR2图文教程 原文标题:How to Install Oracle 11G R2 Enterprise Edition Database U ...
- Get back Typing Break in Ubuntu 12.04 & 11.10(转载)
转自:http://ubuntuguide.net/get-back-typing-break-in-ubuntu-12-04-11-10 Since Ubuntu 11.10 Oneiric, th ...
- Ubuntu 16.04/16.10安装 KDE Plasma
KDE目前的最新版本是Plasma 5.7(2016-10).Ubuntu默认的桌面环境是Unity,下面记录怎么在Ubuntu 16.04/16.10上安装KDE. Ubuntu 16.04/16. ...
- Ubuntu 14.04/14.10下安装VMware Workstation 11图文教程
VMware workstation 是一个可以进行桌面操作的虚拟软件.它可以让我们在一台电脑或者虚拟机中运行多个虚拟机. 由VMware公司研发和维护.由于是商业软件,我们需要买他们家的许可证或者说 ...
- [转] Ubuntu 14.04/14.10下安装VMware Workstation 11图文教程
点击这里查看原文 译者:GuiltyMan 本文由 Linux公社翻译组 原创翻译 Linux公社 诚意奉献 更多请访问此处博客网站 VMware workstation 是一个可以进行桌面操作的虚 ...
- Vmware下Ubuntu 14.04静态IP地址的设置方法
一.环境 宿主机 Win 8.1 虚拟机工具 VMware 10.0 虚拟主机系统 Ubuntu 14.04 二.说明 这里需要注意的是:VMware对于VMnet8采用如下规则(192.168. ...
随机推荐
- scp 一次拷贝多个文件
用正则表达式去匹配即可, scp *.tar root@11.11.11.12:/root/ 拷贝当前目录下的所有tar类型的文件到服务器上
- Centos7安装python3.7.1并与python2共存
转自:http://www.cnblogs.com/JahanGu/p/7452527.html参考:https://www.jb51.net/article/104326.htm 1. 备份原来的p ...
- OpenERP 疑问之一
def _get_send_amount(self,cr,uid,ids,name,args,context=None): res={} MRP={} lines = self.browse(cr,u ...
- [Xamarin.Android] 如何透過電子郵件部署Xamarin.Android App (转帖)
Android App在部署到實機的時候不像iOS的App限制你一定要使用向Apple申請的開發者憑證,在Apple不管是你要上架到Apple Store或者是企業內部署,你都必須向蘋果申請憑證. 而 ...
- JavaScript定时器与执行机制
JavaScript动画中是必须使用到定时器的,这里做一个总结. var label = 'someLable'; console.time(label); console.timeEnd(label ...
- jenkins构建GitHub项目
一.Jenkins 配置 Git 首先,登录 Jenkins ,在首页找到 “系统管理 -> Global Tool Configuration -> Git ” Path to Git ...
- 1-1、create-react-app 配置 mobx
1.用npx create-react-app my-app安装项目 2.cd my-app 3.执行 npm run eject 让配置文件可见 4.npm install --saveDev ...
- 09 jdk1.5的并发容器:ConcurrentHashMap
一 概述 JDK5中添加了新的concurrent包,相对同步容器而言,并发容器通过一些机制改进了并发性能 因为同步容器将所有对容器状态的访问都串行化了,这样保证了线程的安全性,所以这种方法的代价就是 ...
- [转]Web后台模拟前端post(带NTLM验证)
本文转自:http://www.cnblogs.com/pzstudyhard/p/4805885.html using System.Data; using System.Net; using Sy ...
- Spring注解_详解
@Autowired 注释 将 @Autowired 注释标注在成员变量上 import org.springframework.beans.factory.annotation.Autowire ...
