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.意思是无法识别的服务. 以下方法 ...
随机推荐
- SyncthingTray -- Syncthing wrapper for Windows
SyncthingTray Syncthing wrapper for Windows. Includes a small interface to configure start on boot a ...
- WindowsAPI详解——GetDriveType 获得逻辑驱动器的类型
http://flyxxtt.blogbus.com/logs/43181576.html 函数原型:UINT GetDriveType(LPCTSTR lpRootPathName) 参数lpRoo ...
- SQLite 管理工具 SQLite Expert
SQLite Expert – Personal Edition SQLite Expert 提供两个版本,分别是个人版和专业版.其中个人版是免费的,提供了大多数基本的管理功能. SQLite Exp ...
- AutoCAD二次开发——AutoCAD.NET API开发环境搭建
AutoCAD二次开发工具:1986年AutoLisp,1989年ADS,1990年DCL,1993年ADS-RX,1995年ObjectARX,1996年Active X Automation(CO ...
- UCN(User-Centric Networks,用户中心网络)
UCN(User-Centric Networks,以用户为中心的网络)是下一代移动通信网络(5G)的发展方向,目前尚处于初级发展阶段.2016年11月,IEEE SDN研究组(聚焦研发SDN.NFV ...
- Maven中<dependencies>节点和<dependencyManagement>节点的区别
dependencyManagement只是插件管理,并不是真正的插件依赖,所以里面包含的插件在没有子项目使用的时候,并不会真正下载 1 .使用项目继承 利用项目继承可以将结构信息,部署信息,共同的依 ...
- 【六】注入框架RoboGuice使用:(Singletons And ContextSingletons)
上一篇我们简单的介绍了一下RoboGuice的使用([五]注入框架RoboGuice使用:(Your First POJO Injection)),今天我们来看下单例以及上下文单例(ContextSi ...
- OpenStreetMap地图数据介绍(转)
原文链接:每日一读 Packtpub.OpenStreetMap(1) 相信绝大多数人都知道Wiki,但要提起地图,大家第一反应肯定是Google地图.在没看这本书之前,还真不知原来还有OpenStr ...
- 两个List循环
package execise; import java.util.ArrayList; import java.util.List; import domain.User; public class ...
- Mysql之sql语句操作
一.数据库级别操作 1.显示数据库 1 SHOW DATABASES; 默认数据库: mysql - 用户权限相关数据 test - 用于用户测试数据 information_schema - MyS ...