1. 一键批处理设置

    
  1. #!/bin/bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin:~/bin
  3. export PATH
  4. # Check if user is root
  5. if [ $UID != 0 ]; then echo "Error: You must be root to run the install script, please use root to install lanmps";exit;fi
  6. iptables-save >> _.iptables.up.rules #保存防火墙设置,以便没保存时使用
  7. iptables -L -n 2>&1 | tee -a "_.iptables.log"
  8. iptables -F        #清除预设表filter中的所有规则链的规则
  9. iptables -X        #清除预设表filter中使用者自定链中的规则
  10. iptables -Z        #计数器清零
  11. iptables -P INPUT DROP
  12. iptables -P OUTPUT ACCEPT
  13. iptables -P FORWARD ACCEPT
  14. #双向
  15. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  16. #允许本机
  17. iptables -A INPUT -i lo -j ACCEPT
  18. #FTP
  19. iptables -A INPUT -p tcp --dport 21 -j ACCEPT
  20. #SSH
  21. iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  22. #www 80
  23. iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  24. #13306 映射转发到  mysql数据库 3306
  25. iptables -A PREROUTING -p tcp --dport 13306 -j REDIRECT --to-ports 3306 -t nat
  26. #3306 mysql数据库
  27. #iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
  28. #memache
  29. #iptables -A INPUT -p tcp --dport 11211 -j ACCEPT
  30. #对于OUTPUT规则,因为预设的是ACCEPT,所以要添加DROP规则,减少不安全的端口链接。
  31. iptables -A OUTPUT -p tcp --sport 31337 -j DROP
  32. iptables -A OUTPUT -p tcp --dport 31337 -j DROP
  33. #丢弃坏的TCP包
  34. iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
  35. #处理IP碎片数量,防止攻击,允许每秒100个
  36. #iptables -A FORWARD -f -m limit --limit 100/s --limit-burst 100 -j ACCEPT
  37. #设置ICMP包过滤,允许每秒1个包,限制触发条件是10个包
  38. #iptables -A FORWARD -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
  39. #防止外部的ping和SYN洪水攻击
  40. iptables -A INPUT -p tcp --syn -m limit --limit 100/s --limit-burst 100 -j  ACCEPT
  41. #ping洪水攻击,限制每秒的ping包不超过10个
  42. iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s –limit-burst 10 -j ACCEPT
  43. #防止各种端口扫描,将SYN及ACK SYN限制为每秒钟不超过200个
  44. iptables -A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -m limit --limit 20/sec --limit-burst 200 -j ACCEPT
  45. #最后规则拒绝所有不符合以上所有的
  46. iptables -A INPUT -j DROP
  47. if [ -z "`grep "iptables-save" /etc/network/interfaces`" ]
  48. then
  49. echo "#以下有防火墙需要的可以使用
  50. pre-up iptables-restore < /etc/iptables.up.rules #启动时应用防火墙
  51. post-down iptables-save > /etc/iptables.up.rules #关闭时保存防火墙设置,以便下次启动时使用  " >> /etc/network/interfaces
  52. else
  53. echo "iptables-save find "
  54. fi
  55. clear
  56. echo "iptables ok ";
  57. echo ""
  58. iptables -L -n
  59. cat /etc/network/interfaces

把上面的保存为 (如果还有其他端口规则请一起在上面配置,执行时清空规则):

  1. lanmps_iptables.sh

上传到服务器然后设置权限,并执行

  1. chmod 777 lanmps_iptables.sh
  2. ./lanmps_iptables.sh

那么  防火墙就设置完成了

2. ubuntu iptables 防火墙 启动

  1. modprobe ip_tables

3. ubuntu iptables 防火墙 关闭

ubuntu 并没有关闭命令,所以要通过变通方法解决防火墙

  1. iptables -F
  2. iptables -X  
  3. iptables -Z  
  4. iptables -P INPUT ACCEPT  
  5. iptables -P OUTPUT ACCEPT  
  6. iptables -P FORWARD ACCEPT  
  7. modprobe -r ip_tables  
  8. 依次执行以上命令即可关闭iptables,否则在执行modproble -r ip_tables时将会提示  FATAL: Module ip_tables is in use.

4. Iptables的保存和调用

防止每次开机或重启后都需要去调用一次,把它设置自动执行

第一步 更改网卡配置文件

  1. sudo vi /etc/network/interfaces

第二部 在最后增加配置

  1. #以下有防火墙需要的可以使用
  2. pre-up iptables-restore < /etc/iptables.up.rules #启动时应用防火墙
  3. 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 防火墙设置的更多相关文章

  1. IPTables系列:如何配置Ubuntu 14.04中的IPTables防火墙

    IPTables基本命令 在向大家介绍复杂防火墙规则之前,还是先上一些简单的料,让大家对IPTables最为基本的命令有一些简单了解. 首先要说明的是IPTables命令必需以root权限运行,这意味 ...

  2. 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 ...

  3. 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 ...

  4. Ubuntu 13.04/12.10安装Oracle 11gR2图文教程(转)

    Ubuntu 13.04/12.10安装Oracle 11gR2图文教程 原文标题:How to Install Oracle 11G R2 Enterprise Edition Database U ...

  5. 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 ...

  6. 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. ...

  7. Ubuntu 14.04/14.10下安装VMware Workstation 11图文教程

    VMware workstation 是一个可以进行桌面操作的虚拟软件.它可以让我们在一台电脑或者虚拟机中运行多个虚拟机. 由VMware公司研发和维护.由于是商业软件,我们需要买他们家的许可证或者说 ...

  8. [转] Ubuntu 14.04/14.10下安装VMware Workstation 11图文教程

    点击这里查看原文 译者:GuiltyMan 本文由 Linux公社翻译组 原创翻译  Linux公社 诚意奉献 更多请访问此处博客网站 VMware workstation 是一个可以进行桌面操作的虚 ...

  9. Vmware下Ubuntu 14.04静态IP地址的设置方法

    一.环境 宿主机 Win 8.1 虚拟机工具 VMware 10.0 虚拟主机系统 Ubuntu 14.04   二.说明 这里需要注意的是:VMware对于VMnet8采用如下规则(192.168. ...

随机推荐

  1. Eclipse中的创建maven项目,无法添加src/main/java等source folder

    maven无法添加src/main/java 通过Eclipse创建Java Web项目,目录结构如下: 默认是只有src/main/resources 这个source folder 按照maven ...

  2. PXE+Kickstart 批量安装CentOS 7

    安装之前 将需要安装 CentOS 的服务器与 PXE 服务器通过网络设备连接:PXE 服务器安装 CentOS,并且关闭firewalld.selinux,设置静态IP地址,本例设为10.0.0.1 ...

  3. word里的字号与html字号的对应关系

    在word里输入一段文字,把文字调成需要的大小,即"三号或者小三",然后把文件另存为网页,在格式里选择“html”格式,然后把word关闭,将另存的html文件用编辑工具打开,就可 ...

  4. Spring Boot中自动执行sql脚本

    说明:所有的代码基于SpringBoot 2.0.3版本 背景 在应用程序启动后,可以自动执行建库.建表等SQL脚本.下文中以要自动化执行people.sql脚本为例说明,脚本在SpringBoot工 ...

  5. Mac下使用crontab来实现定时任务

    说明: 1.Linux和Mac下操作crontab都是一致的 2.配置文件都在/etc/crontab下,如果没有就创建. 3.测试发现直接使用crontab -e命令创建的定时任务是放在临时文件夹的 ...

  6. 2018最新win10 安装tensorflow1.4(GPU/CPU)+cuda8.0+cudnn8.0-v6 + keras 安装CUDA失败 导入tensorflow失败报错问题解决

    原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/9747019.html 基本开发环境搭建 1. Microsoft Windows 版本 关于W ...

  7. 有符号整数比较v.s.无符号整数比较

    本文尝试从汇编的角度给出有符号整数比较与无符号整数比较的区别所在. 在<深入理解计算机系统>(英文版第二版)一书中的Page#77,有下面一个练习题: 将上述示例代码写入foo1.c文件, ...

  8. 低版本的linux系统装samba服务器

    这里所用系统fedora14,安装samba服务器.我是壮壮熊. 由于工作原因,需要在feaord14上装samba服务器. 问题描述:用yum -y install samba安装samba后,需要 ...

  9. python实例:快速找出多个字典中的公共键

    1.生成随机字典 # 从abcdefg 中随机取出 3-6个,作为key, 1-4 的随机数作为 value s1 = {x : randint(1, 4) for x in sample('abcd ...

  10. Mysql查询今天、昨天、7天、近30天、本月、上一月数据

    今天 SELECT * FROM 表名 WHERE TO_DAYS(时间字段名) = TO_DAYS(now()); 昨天 SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ...