欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

linux iptables 添加 插入 附加 删除,查看,修改 有大用 有大大用 有大大大用 有大大大大用

shiping1 的头像

iptables 添加,删除,查看,修改
iptables是linux系统自带的防火墙,功能强大,学习起来需要一段时间,下面是一些习iptables的时候的记录。如果iptables不熟悉的话可以用apf,是一款基于iptables的防火墙,挺好用的。请参考:linux apf 防火墙 安装 配置

 

一,安装并启动防火墙

  1. [root@linux ~]# /etc/init.d/iptables start  

当我们用iptables添加规则,保存后,这些规则以文件的形势存在磁盘上的,以centos为例,文件地址是/etc/sysconfig/iptables,我们可以通过命令的方式去添加,修改,删除规则,也可以直接修改/etc/sysconfig/iptables这个文件就行了。

二,添加防火墙规则

1,添加filter表

  1. [root@linux ~]# iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT  //开放21端口  

出口我都是开放的iptables -P OUTPUT ACCEPT,所以出口就没必要在去开放端口了。

2,添加nat表

  1. [root@linux ~]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j MASQUERADE  

将源地址是 192.168.10.0/24 的数据包进行地址伪装

3,-A默认是插入到尾部的,可以-I来插入到指定位置

  1. [root@linux ~]# iptables -I INPUT 3 -p tcp -m tcp --dport 20 -j ACCEPT  

  2.   

  3. [root@linux ~]# iptables -L -n --line-number  

  4. Chain INPUT (policy DROP)  

  5. num  target     prot opt source               destination  

  6. 1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0  

  7. 2    DROP       icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 8  

  8. 3    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:20                //-I指定位置插的  

  9. 4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22  

  10. 5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80  

  11. 6    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED  

  12. 7    DROP       all  --  0.0.0.0/0            0.0.0.0/0           state INVALID,NEW  

  13. 8    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:21                //-A默认插到最后  

  14.   

  15. Chain FORWARD (policy ACCEPT)  

  16. num  target     prot opt source               destination           

  17.   

  18. Chain OUTPUT (policy ACCEPT)  

  19. num  target     prot opt source               destination  

三,查下iptable规则

1,查看filter表

  1. [root@linux ~]# iptables -L -n --line-number |grep 21 //--line-number可以显示规则序号,在删除的时候比较方便  

  2. 5    ACCEPT     tcp  --  192.168.1.0/24       0.0.0.0/0           tcp dpt:21  

如果不加-t的话,默认就是filter表,查看,添加,删除都是的

2,查看nat表

  1. [root@linux ~]# iptables -t nat -vnL POSTROUTING --line-number  

  2. Chain POSTROUTING (policy ACCEPT 38 packets, 2297 bytes)  

  3. num   pkts bytes target     prot opt in     out     source               destination  

  4. 1        0     0 MASQUERADE  all  --  *      *       192.168.10.0/24      0.0.0.0/0  

四,修改规则

  1. [root@linux ~]# iptables -R INPUT 3 -j DROP    //将规则3改成DROP  

五,删除iptables规则

  1. [root@linux ~]# iptables -D INPUT 3  //删除input的第3条规则  

  2.   

  3. [root@linux ~]# iptables -t nat -D POSTROUTING 1  //删除nat表中postrouting的第一条规则  

  4.   

  5. [root@linux ~]# iptables -F INPUT   //清空 filter表INPUT所有规则  

  6.   

  7. [root@linux ~]# iptables -F    //清空所有规则  

  8.   

  9. [root@linux ~]# iptables -t nat -F POSTROUTING   //清空nat表POSTROUTING所有规则  

六,设置默认规则

  1. [root@linux ~]# iptables -P INPUT DROP  //设置filter表INPUT默认规则是 DROP  

所有添加,删除,修改后都要保存起来,/etc/init.d/iptables save.上面只是一些最基本的操作,要想灵活运用,还要一定时间的实际操作。

来自 http://blog.51yip.com/linux/1404.html
 

Linux防火墙规则的查看、添加、删除和修改

  •  

  • |

  • 浏览:3090

  • |

  • 更新:

  • |

  • 标签:linux 

这里只列出比较常用的参数,详细的请查看man iptables

 

1、查看

 

iptables -nvL –line-number

-L查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表,可以加上-t NAT参数。

-n不对ip地址进行反查,加上这个参数显示速度会快很多。

-v输出详细信息,包含通过该规则的数据包数量,总字节数及相应的网络接口。

–line-number显示规则的序列号,这个参数在删除或修改规则时会用到。

2、添加

 

添加规则有两个参数:-A和-I。其中-A是添加到规则的末尾;-I可以插入到指定位置,没有指定位置的话默认插入到规则的首部。

 

当前规则:

 

[root@test ~]# iptables -nL --line-number

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    DROP       all  --  192.168.1.1          0.0.0.0/0

2    DROP       all  --  192.168.1.2          0.0.0.0/0

3    DROP       all  --  192.168.1.4          0.0.0.0/0

添加一条规则到尾部:

 

[root@test ~]# iptables -A INPUT -s 192.168.1.5 -j DROP

再插入一条规则到第三行,将行数直接写到规则链的后面:

 

[root@test ~]# iptables -I INPUT 3 -s 192.168.1.3 -j DROP

查看:

 

[root@test ~]# iptables -nL --line-number

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    DROP       all  --  192.168.1.1          0.0.0.0/0

2    DROP       all  --  192.168.1.2          0.0.0.0/0

3    DROP       all  --  192.168.1.3          0.0.0.0/0

4    DROP       all  --  192.168.1.4          0.0.0.0/0

5    DROP       all  --  192.168.1.5          0.0.0.0/0

可以看到192.168.1.3插入到第三行,而原来的第三行192.168.1.4变成了第四行。

 

3、删除

 

删除用-D参数

 

删除之前添加的规则iptables -A INPUT -s 192.168.1.5 -j DROP:

 

[root@test ~]# iptables -D INPUT -s 192.168.1.5 -j DROP

有时候要删除的规则太长,删除时要写一大串,既浪费时间又容易写错,这时我们可以先使用--line-number找出该条规则的行号,再通过行号删除规则。

 

[root@test ~]# iptables -nv --line-number

iptables v1.4.7: no command specified

Try `iptables -h' or 'iptables --help' for more information.

[root@test ~]# iptables -nL --line-number

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    DROP       all  --  192.168.1.1          0.0.0.0/0

2    DROP       all  --  192.168.1.2          0.0.0.0/0

3    DROP       all  --  192.168.1.3          0.0.0.0/0

删除第二行规则

 

[root@test ~]# iptables -D INPUT 2

4、修改

 

修改使用-R参数

 

先看下当前规则:

 

[root@test ~]# iptables -nL --line-number

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    DROP       all  --  192.168.1.1          0.0.0.0/0

2    DROP       all  --  192.168.1.2          0.0.0.0/0

3    DROP       all  --  192.168.1.5          0.0.0.0/0

将第三条规则改为ACCEPT:

 

[root@test ~]# iptables -R INPUT 3 -j ACCEPT

再查看下:

 

[root@test ~]# iptables -nL --line-number

Chain INPUT (policy ACCEPT)

num  target     prot opt source               destination

1    DROP       all  --  192.168.1.1          0.0.0.0/0

2    DROP       all  --  192.168.1.2          0.0.0.0/0

3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

第三条规则的target已改为ACCEPT。

来自 http://jingyan.baidu.com/article/ca2d939dd3adbdeb6c31ced5.html


 CentOS 6 iptables 开放端口80 3306 22等

发表于2年前(2013-10-17 19:38)   阅读(6212) | 评论(2) 12人收藏此文章, 我要收藏
1

9月19日成都 OSC 源创会正在报名,送机械键盘和开源无码内裤  


CentOS 6 iptables 开放端口80 3306 22等

#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
然后保存:
#/etc/init.d/iptables save
 
查看打开的端口:
# /etc/init.d/iptables status

极端情况

#关闭防火墙
/etc/init.d/iptables stop

来自 http://my.oschina.net/blindcat/blog/169657


 

centos linux防火墙添加80端口iptables  

2013-07-09 14:52:16|  分类: linux|举报|字号 订阅

下载LOFTER客户端
 
 
CentOS防火墙在虚拟机的CENTOS装好APACHE不能用,郁闷,解决方法如下 
 
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT 
 
然后保存: 
 
/etc/rc.d/init.d/iptables save 
centos 5.3,5.4以上的版本需要用 
service iptables save 
来实现保存到配置文件。 
这样重启计算机后,CentOS防火墙默认已经开放了80和22端口。 
 
这里应该也可以不重启计算机: 
 
/etc/init.d/iptables restart 
 
CentOS防火墙的关闭,关闭其服务即可: 
 
查看CentOS防火墙信息:/etc/init.d/iptables status 
 
关闭CentOS防火墙服务:/etc/init.d/iptables stop 
 
永久关闭?不知道怎么个永久法: 
 
chkconfig –level 35 iptables off 
 
上面的内容是针对老版本的centos,下面的内容是基于新版本。 
 
iptables -P INPUT DROP 
 
这样就拒绝所有访问 CentOS 5.3 本系统数据,除了 Chain RH-Firewall-1-INPUT (2 references) 的规则外 , 呵呵。 
 
用命令配置了 iptables 一定还要 service iptables save 才能保存到配置文件。 
 
cat /etc/sysconfig/iptables 可以查看 防火墙 iptables 配置文件内容 
 
# Generated by iptables-save v1.3.5 on Sat Apr 14 07:51:07 2001 
*filter 
:INPUT DROP [0:0] 
:FORWARD ACCEPT [0:0] 
:OUTPUT ACCEPT [1513:149055] 
:RH-Firewall-1-INPUT - [0:0] 
-A INPUT -j RH-Firewall-1-INPUT 
-A FORWARD -j RH-Firewall-1-INPUT 
-A RH-Firewall-1-INPUT -i lo -j ACCEPT 
-A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type any -j ACCEPT 
-A RH-Firewall-1-INPUT -p esp -j ACCEPT 
-A RH-Firewall-1-INPUT -p ah -j ACCEPT 
-A RH-Firewall-1-INPUT -d 224.0.0.251 -p udp -m udp --dport 5353 -j ACCEPT 
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT 
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT 
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited 
COMMIT 
# Completed on Sat Apr 14 07:51:07 2001 
 
另外补充: 
CentOS 防火墙配置 80端口 
看了好几个页面内容都有错,下面是正确方法: 
#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 
#/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT 
 
然后保存: 
#/etc/rc.d/init.d/iptables save 
 
再查看是否已经有了: 
[root@vcentos ~]# /etc/init.d/iptables status 
Table: filter 
Chain INPUT (policy ACCEPT) 
num target prot opt source destination 
1 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:80 
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 
3 RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0 
 
Chain FORWARD (policy ACCEPT) 
num target prot opt source destination 
1 RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0 
 
* 设置iptables为自动启动 
chkconfig --level 2345 iptables on 
 
可能因为大家使用的版本不一,所有使用方法也略有不同。 
 
如果需要远程管理mysql,则使用以下指令临时打开,用完后关闭  
 
* 打开指令  
iptables -A INPUT -p tcp -s xxx.xxx.xxx.xxx --dport 3306 -j ACCEPT  
 
* 关闭指令  
iptables -D INPUT -p tcp -s xxx.xxx.xxx.xxx --dport 3306 -j ACCEPT


来自 http://webnoties.blog.163.com/blog/static/18352514120136925216946/


linux防火墙iptables允许指定端口通过

www.111cn.net 编辑:Bolshevik 来源:转载
下面小编来给大家以允许80端口通过防火墙为实例来给各位同学介绍linux防火墙iptables的一些常用设置,这里算是引用一个简单实例拖出大量iptables的一些规则吧。


1、允许通过某一端口

vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙)

/etc/init.d/iptables restart 

#最后重启防火墙使配置生效

只允许特定ip访问某端口?参考下面命令,只允许46.166.150.22访问本机的80端口。如果要设置其他ip或端口,改改即可。

iptables -I INPUT -p TCP --dport 80 -j DROP
iptables -I INPUT -s 46.166.150.22 -p TCP --dport 80 -j ACCEPT

在root用户下执行上面2行命令后,重启iptables, service iptables restart

查看iptables是否生效:

[root@www.ctohome.com]# iptables -L
Chain INPUT (policy ACCEPT)
target           prot opt source               destination         
ACCEPT     tcp  --  46.166.150.22    anywhere            tcp dpt:http 
DROP         tcp  --  anywhere             anywhere            tcp dpt:http

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination        

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination       

 上面命令是针对整个服务器(全部ip)禁止80端口,如果只是需要禁止服务器上某个ip地址的80端口,怎么办?

下面的命令是只允许来自174.140.3.190的ip访问服务器上216.99.1.216的80端口

iptables -A FORWARD -s 174.140.3.190 -d 216.99.1.216 -p tcp -m tcp --dport 80 -j ACCEPT 
iptables -A FORWARD -d 216.99.1.216 -p tcp -m tcp --dport 80 -j DROP

如果您不熟悉linux的ssh命令,那么可以在webmin/virtualmin面板中设置,达到相同效果。参考:webmin面板怎样设置允许特定ip访问80端口,禁止80端口


更多iptables参考命令如下:

1.先备份iptables

# cp /etc/sysconfig/iptables /var/tmp

需要开80端口,指定IP和局域网

下面三行的意思:

先关闭所有的80端口

开启ip段192.168.1.0/24端的80口

开启ip段211.123.16.123/24端ip段的80口

# iptables -I INPUT -p tcp --dport 80 -j DROP 
# iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
# iptables -I INPUT -s 211.123.16.123/24 -p tcp --dport 80 -j ACCEPT

以上是临时设置。

2.然后保存iptables

# service iptables save

3.重启防火墙

#service iptables restart

===============以下是转载================================================

以下是端口,先全部封再开某些的IP

iptables -I INPUT -p tcp --dport 9889 -j DROP 
iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 9889 -j ACCEPT
如果用了NAT转发记得配合以下才能生效

iptables -I FORWARD -p tcp --dport 80 -j DROP 
iptables -I FORWARD -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT

 

 

常用的IPTABLES规则如下:
只能收发邮件,别的都关闭
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -j DROP
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p udp --dport 53 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 25 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0F:EA:25:51:37 -p tcp --dport 110 -j ACCEPT


IPSEC NAT 策略
iptables -I PFWanPriv -d 192.168.100.2 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 80 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:80

iptables -t nat -A PREROUTING -p tcp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723

iptables -t nat -A PREROUTING -p udp --dport 1723 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:1723

iptables -t nat -A PREROUTING -p udp --dport 500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:500

iptables -t nat -A PREROUTING -p udp --dport 4500 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.100.2:4500


FTP服务器的NAT
iptables -I PFWanPriv -p tcp --dport 21 -d 192.168.1.22 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 21 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.1.22:21


只允许访问指定网址
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -d www.ctohome.com -j ACCEPT
iptables -A Filter -d www.guowaivps.com -j ACCEPT
iptables -A Filter -j DROP


开放一个IP的一些端口,其它都封闭
iptables -A Filter -p tcp --dport 80 -s 192.168.1.22 -d www.pconline.com.cn -j ACCEPT
iptables -A Filter -p tcp --dport 25 -s 192.168.1.22 -j ACCEPT
iptables -A Filter -p tcp --dport 109 -s 192.168.1.22 -j ACCEPT
iptables -A Filter -p tcp --dport 110 -s 192.168.1.22 -j ACCEPT
iptables -A Filter -p tcp --dport 53 -j ACCEPT
iptables -A Filter -p udp --dport 53 -j ACCEPT
iptables -A Filter -j DROP


多个端口
iptables -A Filter -p tcp -m multiport --destination-port 22,53,80,110 -s 192.168.20.3 -j REJECT


连续端口
iptables -A Filter -p tcp -m multiport --source-port 22,53,80,110 -s 192.168.20.3 -j REJECT iptables -A Filter -p tcp --source-port 2:80 -s 192.168.20.3 -j REJECT


指定时间上网
iptables -A Filter -s 10.10.10.253 -m time --timestart 6:00 --timestop 11:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j DROP
iptables -A Filter -m time --timestart 12:00 --timestop 13:00 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT
iptables -A Filter -m time --timestart 17:30 --timestop 8:30 --days Mon,Tue,Wed,Thu,Fri,Sat,Sun -j ACCEPT

禁止多个端口服务
iptables -A Filter -m multiport -p tcp --dport 21,23,80 -j ACCEPT


将WAN 口NAT到PC
iptables -t nat -A PREROUTING -i $INTERNET_IF -d $INTERNET_ADDR -j DNAT --to-destination 192.168.0.1


将WAN口8000端口NAT到192。168。100。200的80端口
iptables -t nat -A PREROUTING -p tcp --dport 8000 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.1.22:80


MAIL服务器要转的端口
iptables -t nat -A PREROUTING -p tcp --dport 110 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.1.22:110
iptables -t nat -A PREROUTING -p tcp --dport 25 -d $INTERNET_ADDR -j DNAT --to-destination 192.168.1.22:25


只允许PING 202。96。134。133,别的服务都禁止
iptables -A Filter -p icmp -s 192.168.1.22 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -j DROP

禁用BT配置
iptables –A Filter –p tcp –dport 6000:20000 –j DROP

禁用QQ防火墙配置
iptables -A Filter -p udp --dport ! 53 -j DROP
iptables -A Filter -d 218.17.209.0/24 -j DROP
iptables -A Filter -d 218.18.95.0/24 -j DROP
iptables -A Filter -d 219.133.40.177 -j DROP

基于MAC,只能收发邮件,其它都拒绝
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -j DROP
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 25 -j ACCEPT
iptables -I Filter -m mac --mac-source 00:0A:EB:97:79:A1 -p tcp --dport 110 -j ACCEPT

禁用MSN配置
iptables -A Filter -p udp --dport 9 -j DROP
iptables -A Filter -p tcp --dport 1863 -j DROP
iptables -A Filter -p tcp --dport 80 -d 207.68.178.238 -j DROP
iptables -A Filter -p tcp --dport 80 -d 207.46.110.0/24 -j DROP

只允许PING 202。96。134。133 其它公网IP都不许PING
iptables -A Filter -p icmp -s 192.168.1.22 -d 202.96.134.133 -j ACCEPT
iptables -A Filter -p icmp -j DROP

禁止某个MAC地址访问internet:
iptables -I Filter -m mac --mac-source 00:20:18:8F:72:F8 -j DROP

禁止某个IP地址的PING:
iptables –A Filter –p icmp –s 192.168.0.1 –j DROP

禁止某个IP地址服务:
iptables –A Filter -p tcp -s 192.168.0.1 --dport 80 -j DROP
iptables –A Filter -p udp -s 192.168.0.1 --dport 53 -j DROP

只允许某些服务,其他都拒绝(2条规则)
iptables -A Filter -p tcp -s 192.168.0.1 --dport 1000 -j ACCEPT
iptables -A Filter -j DROP

禁止某个IP地址的某个端口服务
iptables -A Filter -p tcp -s 10.10.10.253 --dport 80 -j ACCEPT
iptables -A Filter -p tcp -s 10.10.10.253 --dport 80 -j DROP

禁止某个MAC地址的某个端口服务

iptables -I Filter -p tcp -m mac --mac-source 00:20:18:8F:72:F8 --dport 80 -j DROP

禁止某个MAC地址访问internet:
iptables -I Filter -m mac --mac-source 00:11:22:33:44:55 -j DROP

禁止某个IP地址的PING:
iptables –A Filter –p icmp –s 192.168.0.1 –j DROP

下面转截


启动iptables
service iptables start
iptables –list //*查看iptables规则集*//
下面是没有定义规划时iptables的样子:
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination

如何开启/关闭指定端口
例如:
开启81端口:
iptables -I INPUT -i eth0 -p tcp –dport 81 -j ACCEPT
iptables -I OUTPUT -o eth0 -p tcp –sport 81 -j ACCEPT
关闭81端口:
iptables -I INPUT -i eth0 -p tcp –dport 81 -j DROP
iptables -I OUTPUT -o eth0 -p tcp –sport 81 -j DROP
然后保存
/etc/rc.d/init.d/iptables save

eth0为网卡名称,可以输入ifconfig来查看网卡信息,注意填写正确的网卡名称。

可以使用lsof命令来查看某一端口是否开放.查看端口可以这样来使用.
我就以81端口为例:
lsof -i:81
如果有显示说明已经开放了,如果没有显示说明没有开放。


来自 http://www.111cn.net/sys/linux/54609.htm


普通分类: