centos IPTables配置方法

来源:互联网 发布:au软件破解 编辑:程序博客网 时间:2024/04/29 09:15
需要的命令:
查看配置情况 iptables -L -n
<span style="color: #ff0000;">记得保存 /etc/init.d/iptables save</span>
<pre>
添加input记录 iptables -A <span style="color: #ff0000;">INPUT</span> -p tcp --<span style="color: #ff0000;">dport</span> 22 -j ACCEPT
添加output记录 iptables -A <span style="color: #ff0000;">OUTPUT</span> -p tcp --<span style="color: #ff0000;">sport</span> 22 -j ACCEPT
</pre>
一些软件的默认端口:
ftp用到端口是 <span style="color: #ff0000;">20 21</span>
ssh 端口是<span style="color: #ff0000;"> 22</span>
http端口是 <span style="color: #ff0000;">80</span>
telnet端口是 <span style="color: #ff0000;">23</span>
rsync端口是 <span style="color: #ff0000;">873</span>
svn 端口<span style="color: #ff0000;">3690</span>
pop3端口<span style="color: #ff0000;">110</span>
smtp端口<span style="color: #ff0000;">25</span>
dns端口<span style="color: #ff0000;">53</span>
mysql端口<span style="color: #ff0000;">3306</span>
nfs端口<span style="color: #ff0000;">111</span>
大概常用的就这些,其他的可查看具体软件
1、查看本机关于 IPTABLES的设置情况,并关闭所有的端口,#慎重,要不你的ssh也失去链接了
<pre>
iptables -L -n --line-number  //显示行号

iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP #慎重,要不你的ssh也失去链接了

</pre>
2.添加规则
<pre>
iptables -A INPUT -p tcp --dport 873 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 873 -j ACCEPT
#加-s 10.210.31.111为来源ip
</pre>
3.保存规则
<pre>
/etc/init.d/iptables save
</pre>
4.重启iptables
<pre>
service iptables restart
</pre>

5.删除规则,删除相应的条目,然后记得保存和重启
<pre>
iptables -L -n --line-number
iptables -D INPUT 2
iptables -D OUTPUT 2
</pre>
6.例子如,加873端口号,只允许10.218.32.153访问
<pre>
iptables -A INPUT -p tcp -s 10.218.32.153 --dport 873 -j ACCEPT
iptables -A OUTPUT -p tcp -d 10.218.32.153 --sport 873 -j ACCEPT
</pre>
结果如下
<pre>
[root@localhost /]# iptables -L -n
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22
ACCEPT     tcp  --  10.218.32.153        0.0.0.0/0           tcp dpt:873

Chain FORWARD (policy DROP)
target     prot opt source               destination         

Chain OUTPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp spt:22
ACCEPT     tcp  --  0.0.0.0/0            10.218.32.153       tcp spt:873
</pre>
原创粉丝点击