iptables简单应用
可以修改/etc/rc.d/boot.local让规则重启后也能生效,如:
/sbin/iptables -F
/sbin/iptables -A INPUT -i eth0 -p tcp --sport 80 -j ACCEPT
/sbin/iptables -A INPUT -i eth0 -p tcp -j DROP
/sbin/iptables -A INPUT -i eth0 -p udp -j DROP
iptables是一个链的方式从前往后判断,如果前面的规则成立就不会往后继续,所以要注意顺序,一般每行对应一条规则。
-A是Append意思,也就是追加
-I是Insert意思,也就是插入
-F表示清除(即删除)掉已有规则,也就是清空。
查看已有的规则,执行命令:iptables -L -n
如(参数-L为list意思,-n表示以数字方式显示IP和端口,不指定-n则显示为名称,如:http即80端口):
# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:443
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:80
DROP tcp -- 0.0.0.0/0 0.0.0.0/0
DROP udp -- 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
从可以看到:iptables有三种规则链(Chain),即INPUT、OUTPUT和FORWARD。
INPUT 用于指定输入规则,比如外部是可以访问本机的80端口
OUTPUT 用于指定输出规则,比如本机是否可以访问外部的80端口
FORWARD 用于指定端口转发规则,比如将8080端口的数据转到到80端口
-I和-A需要指定链(Chain)名,其中-I的链名后还需要指定第几条(行)规则。
可通过-D参数删除规则,有两种删除方式,一是匹配模式,二是指定第几条(行)。
也可以通过-R参数修改已有规则,另外-L参数后也可以跟链(Chain)名,表示只列出指定链的所有规则。
-j参数后跟的是动作,即满足规则时执行的操作,可以为ACCEPT、DROP、REJECT和REDIRECT等。
在iptables的INPUT链的第一行插入一条规则(可访问其它机器的80端口):
iptables -I INPUT 1 -p tcp --sport 80 -j ACCEPT
在iptables的INPUT链尾追加一条规则(可访问其它机器的80端口):
iptables -A INPUT -p tcp --sport 80 -j ACCEPT
如果要让其它机器可以访问本机的80端口,则为:
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
插入前:
# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP tcp -- 0.0.0.0/0 0.0.0.0/0
DROP udp -- 0.0.0.0/0 0.0.0.0/0
插入:
# iptables -I INPUT 1 -p tcp --sport 80 -j ACCEPT
插入后:
# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:80
DROP tcp -- 0.0.0.0/0 0.0.0.0/0
DROP udp -- 0.0.0.0/0 0.0.0.0/0
追加前:
# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP tcp -- 0.0.0.0/0 0.0.0.0/0
DROP udp -- 0.0.0.0/0 0.0.0.0/0
追加:
# iptables -I INPUT 1 -p tcp --sport 80 -j ACCEPT
追加后(ACCEPT将不能生效):
# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP tcp -- 0.0.0.0/0 0.0.0.0/0
DROP udp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp spt:80
iptables简单应用的更多相关文章
- iptables简单配置
iptables简单配置 分类: Linux 安全2010-10-20 16:56 4241人阅读 评论(0) 收藏 举报 input防火墙tcpfilterubuntuservice # iptab ...
- iptables简单使用
1.安装iptables yum install iptables-services 2.iptables简单使用 iptables防火墙文件路径/etc/sysconfig/iptables sys ...
- [ 总结 ] web server iptables 简单配置
[root@server ~]# iptables -F [root@server ~]# iptables -X [root@server ~]# iptables -A INPUT -m stat ...
- iptables 简单介绍及应用 Linux防火墙
iptables 即 Linux防火墙 的简单介绍及使用 iptables生效位置如下图: 其中, 网络防火墙也可以使用一台启用了iptables的Linux主机代替; 路由器或集线器等设施在拓扑中省 ...
- iptables 简单配置
通过命令 netstat -tnl 可以查看当前服务器打开了哪些端口 Ssh代码 netstat -tnl 查看防火墙设置 Ssh代码 iptables -L -n 开放 ...
- Linux iptables简单配置
#!/bin/sh#modprobe ipt_MASQUERADEmodprobe ip_conntrack_ftpmodprobe ip_nat_ftpiptables -Fiptables -t ...
- iptables简单用法
iptables -t 表名 <-A/I/D/R> 规则链名 [规则号] <-i/o 网卡名> -p 协议名 <-s 源IP/源子网> --sport 源端口 &l ...
- iptables简单规则记录
先来一句:好记性不如烂笔头! 1.iptables简介 iptables是基于包过滤的防火墙,它主要工作在osi模型的2,,4层,也可以工作在7层(iptables + squid) 2.原理 防火墙 ...
- iptables简单了解
简介 Iptables是unix/linux自带的一款优秀且开源的基于包过滤的防火墙工具. 怎么用 可以用来做主机防火墙. 可以做局域网共享上网. 可以做ip及端口映射. Iptables工作流程 i ...
随机推荐
- Service里边启动Activity注意事项
Intent intentv = new Intent(Intent.ACTION_VIEW); intentv.setData(uri); intentv.putExtra("keepTi ...
- SeekBar
<SeekBar android:id=”@+id/seek”android:layout_width=”match_parent”android:layout_height=”wrap_con ...
- 运行msckf_vio
MSCKF_vio是一种基于多状态约束卡尔曼滤波器的双目视觉里程计.其中多状态约束是指将多帧图像的相机位姿加入卡尔曼状态向量中,在进行卡尔曼增益之前通过多帧图像之间的约束进行最小二乘优化来估计特征点 ...
- kubadm创建k8s v1.10集群
kubadm创建k8s集群 1:服务器信息以及节点介绍 主机名 ip 备注 k8s-master 192.168.0.104 master etcd keepalived k8s-client1 19 ...
- Python.tornado.0
Tornado https://github.com/facebook/tornado http://www.tornadoweb.org/en/stable/guide/intro.html (A ...
- gcc产生类型转换告警
问题背景: 看 https://www.cnblogs.com/sinaxyz/p/4525208.html 这个篇blog时候,发现在应用层代码中,函数 int open_netlink() 中,有 ...
- include 指令和 include 动作引入 jsp 页面时中文乱码
include指令:<%@ include file="new.jsp" %> include动作:<jsp:include page="new.jsp ...
- Web 文件上传方面的安全问题
一. 文件上传漏洞与WebShell的关系 文件上传漏洞是指网络攻击者上传了一个可执行的文件到服务器并执行.这里上传的文件可以是木马,病毒,恶意脚本或者WebShell等.这种攻击方式是最为直接和有效 ...
- IOS初级:UIScrollView & UIPageControl
UIScrollView其实构建的就像一列很长的火车,每滑动一个屏幕,展示一节车厢. //主屏幕高度 #define kScreenHeight [UIScreen mainScreen].bound ...
- C#调用开源图像识别类库tessnet2
首先下载tessnet2_32.dll及相关语言包,将dll加入引用 private tessnet2.Tesseract ocr = new tessnet2.Tesseract();//声明一个O ...