iptable配置
作者 佚名技术
来源 Linux系统
浏览
发布时间 2012-03-23
|
iptables 基本语法 内核2.6.18
4张表
表和链:
filter: input forward output
nat: prerouting output postrouting
mangle:perrouting output postrouting input forward
raw:prerouting output
-------------------------------------
man iptables
iptables -L
默认是:filter表
---------------------------------
保持SSH 登陆
iptables -t filter -A INPUT -p tcp --dport 22 -j accept
iptables -t filter -A OUPUT -p tcp --sport 22 -j accept
--------------------------------
iptables -L --line 查看链的号码
-------------------------------------------
设定默认的链规则: 设置安全的链,先打开SSH 然后关闭默认规则,然后再逐个添加允许的规则
iptables -t filter -A INPUT -p tcp --dport 22 -j accept
iptables -t filter -A OUPUT -p tcp --sport 22 -j accept
iptables -P OUTPUT DROP
iptables -P INPUT DROP
注意:当添加端口时, 指定协议.
================================
测试用:
=============================================================================
打开telnet 23 端口
iptables -t filter -A INPUT -p tcp --dport 23 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --sport 23 -j ACCEPT
或
iptables -t filter -A OUTPUT -p tcp --sport 23 -d 169.254.1.148 -j ACCEPT
----------------------------------------------------------------------------------
打开icmp ping 的功能
[root@client ~]# iptables -t filter -A INPUT -p icmp -j ACCEPT
[root@client ~]# iptables -t filter -A OUTPUT -p icmp -j ACCEPT
[root@client ~]# iptables -L
iptables -L --line
[root@client ~]# iptables -L --line
Chain INPUT (policy DROP)
num target prot opt source destination
1 ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
2 ACCEPT tcp -- anywhere anywhere tcp dpt:telnet
3 ACCEPT icmp -- anywhere anywhere
iptables -D INPUT 3(icmp的号码)
添加流量限制的测试:
iptables -A INPUT -p icmp -m limit --limit 2/m --limit-burst 3 -j ACCEPT
C:\Documents and Settings\Haier>ping 169.254.1.233
Pinging 169.254.1.233 with 32 bytes of data:
Reply from 169.254.1.233: bytes=32 time=2ms TTL=64
Reply from 169.254.1.233: bytes=32 time<1ms TTL=64
Reply from 169.254.1.233: bytes=32 time<1ms TTL=64
Request timed out.
Ping statistics for 169.254.1.233:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 2ms, Average = 0ms
--------------------------------------------------------------------------
开启,以免一些程序无法正常运行
开启 本地回环地址
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
---------------------------------------------------------------------
开启DNS 跟其他的协议有点不同,注意, |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn
为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
|