iptables 与 asterisk

运维 系统运维
iptables 是与最新的 2.6.x 版本Linux 内核集成的 IP 信息包过滤系统。上篇我给大家讲了iptables下开放ftp连接,本文为大家讲下iptables 与 asterisk 的故事。

iptables asterisk

  iptables fo asterisk

  SIP on UDP port 5060. Other SIP servers may need TCP port 5060 as well

  iptables -A INPUT -p udp -m udp—dport 5004:5082 -j ACCEPT

  IAX2 - the IAX protocol

  iptables -A INPUT -p udp -m udp—dport 4569 -j ACCEPT

  IAX – most have switched to IAX v2, or ought to

  iptables -A INPUT -p udp -m udp—dport 5036 -j ACCEPT

  RTP – the media stream

  iptables -A INPUT -p udp -m udp—dport 10000:20000 -j ACCEPT

  MGCP – if you use media gateway control protocol in your configuration

  iptables -A INPUT -p udp -m udp—dport 2727 -j ACCEPT

  参考:http://www.voip-info.org/wiki-Asterisk+firewall+rules

#p#

  iptables 详解

  iptables—version来查看系统是否安装了iptables

  iptables -help来查看一个快速帮助

  man iptables来查看所有命令和选项的完整介绍

  iptables—list 查看系统中现有的iptables规划集

  一般语法如下:

  iptables [-t table] command [match] [target]

  table

  filter用于一般的信息包过滤,包含INPUT,OUTPUT和FORWARD链。nat用于要转发的信息包。

  command

  command部分是iptables命令最重要的部分。它告诉iptables命令要做什么,例如插入规则、将规则添加到链的末尾或删除规则。

  -A 或—append:将一条规则附加到链的末尾。如 iptables -A INPUT -s 210.12.1.23 -j ACCEPT (接受来自源210.12.1.23地数据包)

  - D 或—delete:从链中删除规则。如iptables -D INPUT —dport 80 -j DROP (丢弃前往端口80的包);iptalbes -D OUTPUT 3 (删除链编号为3的规则)

  -P 或—policy,设置链的缺少策略(处理与其它规则不匹配的包)。如iptables -P INPUT DROP (丢弃与所有规则都不匹配的包)

  -N 或—new-chain:用指定名称创建一个新链。如iptables -N alowed-chain

  - F 或—flush:删除指定链或所有链(未指定名称时)。如iptables -F FORWARD 或iptables -F

  -L 或—list,列出链中的所有规则。如iptables -L allowed-chain

  match

  iptables命令的可选match部分指定信息包与规则匹配所应具有的特征(如源地址、目的地址、协议等)。

  -p 或—protocal:检查特定协议(TCP、UDP、ICMP、ALL),可用!表示非。如iptables -A INPUT -p TCP ,UDP或iptables -A INPUT -p !ICMP,两条命令作用一样。

  -s 或—source:根据信息的源IP来匹配。如iptables -A OUTPUT -s 192.168.1.1,iptables -A OUTPUT -s 192.168.0.0/24(从0.0到0.24),iptables -A OUTPUT -s !203.16.1.89

  -d 或—destination,根据目标IP来匹配。如 iptables -A INPUT -d 192.168.1.1

  target

  目标是由规则指定的操作,对与那些规则匹配的信息包执行这些操作。除了允许用户定义的目标之外,还有许多可用的目标选项。

  ACCEPT , DROP, REJECT , RETURN

  示例

  本例中的规则将会阻止来自某一特定IP范围内的数据包,因为该IP地址范围被管理员怀疑有大量恶意攻击者在活动:

  iptables -t filter -A INPUT -s 123.456.789.0/24 -j DROP

  也可以很轻易地阻止所有流向攻击者IP地址的数据包,该命令稍有不同:

  iptables -t filter -A OUTPUT -d 123.456.789.0/24 -j DROP

  为每一个链设置缺省的规则:

  iptables -P INPUT DROP

  iptables -P FORWARD DROP

  iptables -P OUTPUT ACCEPT 这里选项-P用于设置链的策略,只有三个内建的链才有策略。这些策略可以让信息毫无限制地流出,但不允许信息流入。

  允许来自网络接口ppp0(internet接口),并且来源端口是80的数据进入你的计算机

  iptables -A INPUT -i ppp0 -p tcp—sport 80 -j ACCEPT

  要提供www服务

  iptables -A INPUT -i ppp0 -p tcp—dport 80 -j ACCEPT

  阻止所有没有经过你系统授权的TCP连接:

  iptables -t filter -A INPUT -i eth0 -p tcp—syn -j DROP 这里的-i指的是网卡,-p则是指协议,—syn则表示带有syn标识设置的TCP数据包。SYN用于初始化一个TCP连接,如果自己机器上没有运行任何服务器,别人也就不会向你发送SYN数据包。

  规则的保存与恢复

  iptables-save > iptables-script

  iptables-restore iptables-script

通过文章,我们知道了iptables 和 asterisk,希望本文对大家有所帮助!

【编辑推荐】

责任编辑:赵鹏 来源: 网络转载
相关推荐

2011-03-15 13:39:14

iptablesstun

2011-03-17 15:32:25

2011-03-15 15:47:25

iptables安装命令

2011-03-15 11:05:03

2010-01-04 14:44:23

Ubuntu Aste

2011-03-15 17:25:38

2011-03-15 09:10:42

Linux防火墙Iptables

2011-03-17 17:19:24

iptables

2011-03-18 09:26:13

Iptables规则

2011-03-15 09:59:59

iptables实例

2021-10-13 16:00:53

KubeProxyIptables

2011-03-16 11:17:56

IptablesICMP

2011-03-17 17:45:45

iptables规则

2011-03-15 09:46:31

2011-03-14 14:40:11

iptables编译

2011-03-15 14:01:13

2011-03-15 16:26:46

iptablesnat

2011-03-15 16:34:36

Iptables性能

2011-03-15 14:50:03

使用IPTables

2011-03-17 16:43:49

点赞
收藏

51CTO技术栈公众号