Ubuntu中iptables的使用
(一) 设置开机启动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的使用的更多相关文章
- ubuntu 中iptables
ubuntu中启动及关闭iptables 在ubuntu中由于不存在 /etc/init.d/iptales文件,所以无法使用service等命令来启动iptables,需要用modprobe命令. ...
- Ubuntu 中 iptables 增删查改
iptables是linux系统自带的防火墙,功能强大.如果iptables不熟悉的话可以用apf,是一款基于iptables的防墙. 一.安装并启动防火墙 $ /etc/init.d/iptable ...
- ubuntu 中 iptables 和 ufw 的关系
我突然发现,自己平常使用的 iptables 和 ufw 到底是啥关系?平常其实iptables和ufw在配置防火墙,开启端口是,还是偶尔会使用到的. 没去思考过这两者是啥关系,哎...,这就不够好了 ...
- Ubuntu中使用iptables
(一) 设置开机启动iptables # sysv-rc-conf --level 2345 iptables on (二) iptables的基本命令 1. 列出当前iptables的策略和规则 # ...
- Ubuntu中保存iptables防火墙规则
Ubuntu中保存iptables防火墙规则的例子 打开防火墙 ufw disableufw statusufw enable ufw allow 22/tcp ufw reload iptables ...
- ubuntu中防火墙iptables配置
特别说明:此文章完全转载于https://www.cnblogs.com/EasonJim/p/6851007.html 1.查看系统是否安装防火墙 root@localhost:/usr# whic ...
- Ubuntu中开启和关闭防火墙-摘自网络
1.关闭ubuntu的防火墙 ufw disable开启防火墙ufw enable 2.卸载了iptablesapt-get remove iptables3.关闭ubuntu中的防火墙的其余命令ip ...
- ubuntu中rc.local无效
在ubuntu中写了一点iptables规则,但是,竟然iptables竟然无效,经过多方查找问题...眼泪... 终于发现是rc.local竟然没有运行,我晕.仔细检查iptables脚本n遍,没有 ...
- Ubuntu使用iptables配置防火墙提示:unrecognized service(Ubuntu配置iptables防火墙)
Ubuntu默认安装是没有开启任何防火墙的. 当使用service iptables status时发现提示iptables:unrecoginzed service.意思是无法识别的服务. 以下方法 ...
随机推荐
- spring mvc接收数组
(一)前言 对于springmvc接收数组的问题啊,我试验过几次,但是了有时候成功了,有时候失败了,也不知道为啥的,然后现在又要用到了,所以打算具体看看到底怎么回事,但是了我实验成功了顺便找了好多资料 ...
- Flex4+spring+hibernate+BlazeDS整合案例
http://wenku.baidu.com/link?url=7v5xAyD2nvChQRT60QewpvAASFHMZNvD0OxX11OASYvae8jbVNsr5I000TwwYOlChzq0 ...
- DockManager如何停靠 z
DockManager默认只能停靠在窗体上,如果想停靠在其他控件上,我们发现并没有选项可以选,可能目前大部分解决方法是新建一个用户控件文件,再在用户控件里面单独设计模块. 除了这种方法还有没有其他的呢 ...
- leetcode第一刷_Gray Code
说到格雷码,应该没人不知道,详细它有什么用,我还真不是非常清楚,我室友应该是专家.生成的规律不是非常明显,之前看到帖子讲的,这会儿找找不到了.. 思想是这种,假设有n位,在第2^(n-1)个编码以下画 ...
- [MAC OS] 常用工具
1.Charles mac下的抓包.代理神器 比如我想本地配置 到我的开发机上面.我可以通过Charles 下Tools -> Map Remote 配置跳转. 2.Postman chrom ...
- OpenCV学习(37) 人脸识别(2)
在前面一篇教程中,我们学习了OpenCV中基于特征脸的人脸识别的代码实现,我们通过代码 Ptr<FaceRecognizer> model = createEigenFaceR ...
- 给定任意字符串,计算一共能组合成多少个单词bing
CSDN编程挑战里的题目 例如有一个字符串"iinbinbing",截取不同位置的字符‘b’.‘i’.‘n’.‘g’组合成单词"bing".若从1开始计数的话, ...
- Ubuntu 12.04 安装配置 Apache2
Apache2安装 1 我们使用root账户进行安装,首先切换到root账户,输入命令: sudo su 2 安装 Apache2 apt-get install apache2 在浏览器输入你服务器 ...
- UVA 156 (13.08.04)
Ananagrams Most crossword puzzle fans are used to anagrams--groupsof words with the same letters i ...
- iOS开发-委托(Delegate)浅谈
委托其实并不是OC中才有,C#中也有,不过彼此的理解方式是不一样的,OC中委托是协议的一种,需要使用@protocol声明,委托一般在iOS开发中页面中传值用的比较多.委托是Cocoa中最简单.最灵活 ...