(一) 设置开机启动iptables
# sysv-rc-conf --level 2345 iptables on

(二) iptables的基本命令

1. 列出当前iptables的策略和规则
# iptables -L -n
-n: 用数字形式显示
# iptables -L -v
-v: 打印详细的信息
2. 允许已经建立的连接接收数据
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
3. 开放端口22(SSH的默认端口),您要告诉iptables允许接受到的所有目标端口为22的TCP报文通过
iptables -A INPUT -p tcp -i eth0 --dport ssh -j ACCEPT
注:ssh代表22,可以在/etc/services中查到的服务都可以这样使用。
4. 添加策略。策略也是一种规则,当所有规则都不匹配时,使用链的“策略”
链:INPUT, PREROUTING, FORWARD, POSTROUTING, OUTPUT
链策略的默认值是:ACCEPT。
表:filter (默认),nat,mangle。
#iptables -P INPUT DROP
#iptables -P OUTPUT ACCEPT
#iptables -P FORWARD DROP
----------------------------------------------------
root@patrick:~# iptables -L -n
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
Chain FORWARD (policy DROP)
target     prot opt source               destination         
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:22
----------------------------------------------------
5. 启动包转发功能
将内网的FTP请求转发到外网的一个主机上。
iptables -t nat -A PREROUTING -p tcp -dport 21 -j DNAT --to-dest 10.25.1.7:21
查看:
# iptables -L -t nat
要实现包转发,还需要编辑内核参数。
# cat /proc/sys/net/ipv4/ip_forward
0
默认包转发是禁止的。于是需要打开。编辑/etc/sysctl.conf,然后执行sysctl -p。
(三)保存iptables的规则
step 1) 保存当前iptables的规则到文件中。
# iptables-save > /etc/iptables.up.rules
step 2) 开机恢复iptables的规则。方法是添加下面这行到文件‘/etc/network/interfaces/’ 的末尾。
pre-up iptables-restore < /etc/iptables.up.rules
(四)禁用防火墙
iptables -F
似乎Ubuntu中没有类似service iptables stop这样的命令来暂停iptables。只能使用这种方法来禁用iptables(防火墙)。
使用前,请保证规则已经备份在文件中。

Ubuntu中iptables的使用的更多相关文章

  1. ubuntu 中iptables

    ubuntu中启动及关闭iptables 在ubuntu中由于不存在 /etc/init.d/iptales文件,所以无法使用service等命令来启动iptables,需要用modprobe命令. ...

  2. Ubuntu 中 iptables 增删查改

    iptables是linux系统自带的防火墙,功能强大.如果iptables不熟悉的话可以用apf,是一款基于iptables的防墙. 一.安装并启动防火墙 $ /etc/init.d/iptable ...

  3. ubuntu 中 iptables 和 ufw 的关系

    我突然发现,自己平常使用的 iptables 和 ufw 到底是啥关系?平常其实iptables和ufw在配置防火墙,开启端口是,还是偶尔会使用到的. 没去思考过这两者是啥关系,哎...,这就不够好了 ...

  4. Ubuntu中使用iptables

    (一) 设置开机启动iptables # sysv-rc-conf --level 2345 iptables on (二) iptables的基本命令 1. 列出当前iptables的策略和规则 # ...

  5. Ubuntu中保存iptables防火墙规则

    Ubuntu中保存iptables防火墙规则的例子 打开防火墙 ufw disableufw statusufw enable ufw allow 22/tcp ufw reload iptables ...

  6. ubuntu中防火墙iptables配置

    特别说明:此文章完全转载于https://www.cnblogs.com/EasonJim/p/6851007.html 1.查看系统是否安装防火墙 root@localhost:/usr# whic ...

  7. Ubuntu中开启和关闭防火墙-摘自网络

    1.关闭ubuntu的防火墙 ufw disable开启防火墙ufw enable 2.卸载了iptablesapt-get remove iptables3.关闭ubuntu中的防火墙的其余命令ip ...

  8. ubuntu中rc.local无效

    在ubuntu中写了一点iptables规则,但是,竟然iptables竟然无效,经过多方查找问题...眼泪... 终于发现是rc.local竟然没有运行,我晕.仔细检查iptables脚本n遍,没有 ...

  9. Ubuntu使用iptables配置防火墙提示:unrecognized service(Ubuntu配置iptables防火墙)

    Ubuntu默认安装是没有开启任何防火墙的. 当使用service iptables status时发现提示iptables:unrecoginzed service.意思是无法识别的服务. 以下方法 ...

随机推荐

  1. IOS快速入门

    http://www.cnblogs.com/wellsoho/p/4313312.html

  2. 【spring cloud】在spring cloud服务中,打包ms-core失败,报错Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:repackage (default) on project

    在spring cloud服务中,有一个ms-code项目,只为所有的微服务提供核心依赖和工具类,没有业务意义,作为核心依赖使用.所以没有main方法,没有启动类. 在spring cloud整体打包 ...

  3. .NET:CLR via C# Manifest

    An assembly is a collection of one or more files containing type definitions and resource files. One ...

  4. 页面中checkbox返回的是一个数组,如何对数组进行操作

    1. 仅仅利用javascript进行操作: //html代码如下: <form action="#" method="POST" onsubmit=&q ...

  5. android破解

    1.adb shell dumpsys activity top 能够获取到当前程序的Activity信息 2.1.在invoke-static/invoke-virtual指令他的返回类型是V之后可 ...

  6. Word 页眉插入自动标题(页眉显示章节标题)

    做word文档时有时候需要将章节标题加到页眉中,这里实现自动获取和自动更新页眉里面的标题 1.双击页眉,输入固定文字作为页眉左边的显示,然后敲2下table键,为接下来插入自动标题做好准备,如下图: ...

  7. Objective-C:ARC自动释放对象内存

    ARC是cocoa系统帮你完成对象内存释放的引用计数机制 .h文件 // Person.h // 01-ARC // // Created by ma c on 15/8/13. // Copyrig ...

  8. Informatica 常用组件Lookup之七 查找条件

    PowerCenter 使用查找条件来测试收到的值.这与 SQL 查询中的 WHERE 子句相似.为转换配置查找条件时,将对转换输入值和查找源或高速缓存(用查找端口代表)中的值进行比较.当您运行工作流 ...

  9. 第十一章 springboot + mongodb(简单查询)

    1.mongodb在mac上的安装 下载mongodb,https://www.mongodb.org/ 解压缩到一个指定文件夹,如:/Users/enniu1/Desktop/zjg/mongodb ...

  10. Bootstrap学习js插件篇之标签页

    简单的标签页 代码: <h1 class="page-header">4.3标签页</h1> <ul class="nav nav-tabs ...