快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

iptables 配置方法介绍

 

ipchains 和 iptables 在语法上的主要的差异,注意如下∶

1. 在 ipchains 中,诸如 input 链,是使用小写的 chains 名,在 iptables 中,要改用大写 INPUT。

2. 在 iptables 中,要指定规则是欲作用在那一个规则表上(使用 -t 来指定,如 -t nat),若不指定,则预设是作用在 filter 这个表。

3. 在 ipchains 中, -i 是指介面(interface),但在 iptables 中,-i 则是指进入的方向,且多了 -o,代表出去的方向。

4. 在 iptables 中,来源 port 要使用关键字 --sport 或 --source-port

5. 在 iptables 中,目的 port 要使用关键字 --dport 或 --destination-port

6. 在 iptables 中,"丢弃" 的处置动作,不再使用 DENY 这个 target,改用 DROP。

7. 在 ipchains 的记录档功能 -l,已改为目标 -j LOG,并可指定记录档的标题。

8. 在 ipchains 中的旗标 -y,在 iptables 中可用 --syn 或 --tcp-flag SYN,ACK,FIN SYN

9. 在 iptables 中,imcp messages 型态,要加上关键字 --icmp-type,如∶

iptables -A OUTPUT -o eth0 -p icmp -s $FW_IP --icmp-type 8 -d any/0 -j ACCEPT

 

 

 

 

 

iptables 使用时的样板

在设定 iptables 的封包过滤规则时,有几个样板的动作,若先熟に?牵??缶涂勺孕刑子茫?来死嗤疲?芸斓兀??涂梢越?胝飧鎏斓刂?小?/P>

 

 

观察目前的设定

作法如下∶

 

 

 

iptables -L -n

iptablse -t nat -L -n

 

 

 

 

 

定义变数

FW_IP="163.26.197.8"

 

 

 

 

打开核心 forward 功能

作法如下∶

 

 

 

###-----------------------------------------------------###

# 打开 forward 功能

###-----------------------------------------------------###

 

 

 

echo "1" > /proc/sys/net/ipv4/ip_forward

 

 

 

 

 

清除所有的规则

一开始要先清除所有的规则,重新开始,以免旧有的规则影响新的设定。作法如下∶

 

 

 

###-----------------------------------------------------###

# 清除先前的设定

###-----------------------------------------------------###

# 清除预设表 filter 中,所有规则链中的规则

iptables -F

# 清除预设表 filter 中,使用者自订链中的规则

iptables -X

 

 

 

# 清除mangle表中,所有规则链中的规则

iptables -F -t mangle

# 清除mangle表中,使用者自订链中的规则

iptables -t mangle -X

 

 

 

# 清除nat表中,所有规则链中的规则

iptables -F -t nat

# 清除nat表中,使用者自订链中的规则

iptables -t nat -X

 

 

 

 

顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论