[CentOS]iptables设置,刚弄死一台服务器,请各位帮我看看怎么修改

是是非非 2009-01-08 02:54:29
对外开放的服务有 http (80) / https (443) / ssh(1433) / ftp (1434 : 2000~2099) / 某服务 (12921/10086)

脚本如下:


#!/bin/bash
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X

ServicePorts="80 443 1433 1434 2000:2099 10086 12921"
AccessPorts="20 21 22 53 80 443 1433 1434 2000:2099 3306 10086 12921"
#Default
iptables -P INPUT DROP
#Access
for aPort in $AccessPorts ; do
iptables -A INPUT -i eth1 -p tcp --sport $aPort -j ACCEPT
iptables -A INPUT -i eth1 -p udp --sport $aPort -j ACCEPT
done

#Service
for sPort in $ServicePorts ; do
iptables -A INPUT -i eth1 -p tcp --dport $sPort -j ACCEPT
iptables -A INPUT -i eth1 -p udp --dport $sPort -j ACCEPT
done
...全文
858 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
帮顶
是是非非 2009-01-09
  • 打赏
  • 举报
回复
谢谢楼上。。。。

加分成功。。
makewong 2009-01-09
  • 打赏
  • 举报
回复
#!/bin/bash
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X

ServicePorts="80 443 1433 1434 2000:2099 10086 12921"
AccessPorts="20 21 22 53 80 443 1433 1434 2000:2099 3306 10086 12921"
#Default
iptables -P INPUT DROP
#Access
#这里应该是内到外访问吧。用-o
for aPort in $AccessPorts ; do
iptables -A INPUT -o eth1 -p tcp --sport $aPort -j ACCEPT
iptables -A INPUT -o eth1 -p udp --sport $aPort -j ACCEPT
done

#Service
#这里应该是外到内吧,用-i
for sPort in $ServicePorts ; do
iptables -A INPUT -i eth1 -p tcp --dport $sPort -j ACCEPT
iptables -A INPUT -i eth1 -p udp --dport $sPort -j ACCEPT
done

threeleafzerg007 2009-01-09
  • 打赏
  • 举报
回复
恩? 楼主这么多分分,接分,帮顶
是是非非 2009-01-09
  • 打赏
  • 举报
回复
没解决。。。现在只能是关闭防火墙了。。。


是备份服务器,哈,不幸中的万幸了。。
wangxuhero 2009-01-09
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 makewong 的回复:]
#!/bin/bash
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X

ServicePorts="80 443 1433 1434 2000:2099 10086 12921"
AccessPorts="20 21 22 53 80 443 1433 1434 2000:2099 3306 10086 12921"
#Default
iptables -P INPUT DROP
#Access
#这里应该是内到外访问吧。用-o
for aPort in $AccessPorts ; do
iptables -A INPUT -o eth1 -p tcp --sport $aPort -j ACCEPT
iptables -A I…
[/Quote]

-o也应该是放在output链中,况且默认output都是access的,无需再定义。

不知楼主问题解决没,生产机应尽快恢复啊。。。
Gdatasheet 2009-01-08
  • 打赏
  • 举报
回复
LZ有空 了解一下思科 的IOS 对你认识iptables 帮助大大的
Gdatasheet 2009-01-08
  • 打赏
  • 举报
回复
#!/bin/bash
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X

ServicePorts="80 443 1433 1434 2000:2099 10086 12921"
AccessPorts="20 21 22 53 80 443 1433 1434 2000:2099 3306 10086 12921"

#Access
for aPort in $AccessPorts ; do
iptables -A INPUT -i eth1 -p tcp --sport $aPort -j ACCEPT
iptables -A INPUT -i eth1 -p udp --sport $aPort -j ACCEPT
done

#Service
for sPort in $ServicePorts ; do
iptables -A INPUT -i eth1 -p tcp --dport $sPort -j ACCEPT
iptables -A INPUT -i eth1 -p udp --dport $sPort -j ACCEPT
done

#Default
iptables -P INPUT DROP
Gdatasheet 2009-01-08
  • 打赏
  • 举报
回复
mark,我现在准备把iptables弄到开发板上去跑。。。
是是非非 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 wangxuhero 的回复:]
楼主理解得没错。
INPUT    数据包通过Route Table后,目地为本机
OUTPUT  由本机发出,进入Route Table前

其实iptables就是模拟了防火墙的特性,如果楼主配置过防火墙的话,应该很好理解iptables的配置规则。

[/Quote]

防火墙。。。我只用过XP自带的防火墙。。。
wangxuhero 2009-01-08
  • 打赏
  • 举报
回复
楼主理解得没错。
INPUT 数据包通过Route Table后,目地为本机
OUTPUT 由本机发出,进入Route Table前

其实iptables就是模拟了防火墙的特性,如果楼主配置过防火墙的话,应该很好理解iptables的配置规则。


是是非非 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 guosha 的回复:]
顺序不对吧,直接第一条语句就把所有的包给丢掉了。
[/Quote]

我看了几个教程,都说iptables -P INPUT DROP 只是定义一个默认规则

而且看他们的实例代码都这么写的。。。

是这样的么?
是是非非 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 wangxuhero 的回复:]
你可以打印一下你当前的配置还有预设规则
iptables -L -n

由于不清楚你的input,output的预设规则怎样,
建议把accessport策略去掉看一下。
还有--sport最好和-s选项一起使用,用来限定某些地址的某些端口,而不是全部源地址。
[/Quote]

INPUT 是指别人访问我,或者我发出请求的回应吧
OUTPUT 是指我访问别人,或者对别人请求的回应,是这样的吗?

比如说对于一个HTTP请求,就包含INPUT和OUTPUT两个规则是吗?
INPUT是any -> 80 OUTPUT是 80 -> any 这么理解对吗?

puheavy123 2009-01-08
  • 打赏
  • 举报
回复
iptables要做好确实不是很容易,不过多看点环境,多看点书,还是没什么问题的。
wangxuhero 2009-01-08
  • 打赏
  • 举报
回复
你可以打印一下你当前的配置还有预设规则
iptables -L -n

由于不清楚你的input,output的预设规则怎样,
建议把accessport策略去掉看一下。
还有--sport最好和-s选项一起使用,用来限定某些地址的某些端口,而不是全部源地址。
快乐田伯光 2009-01-08
  • 打赏
  • 举报
回复
顺序不对吧,直接第一条语句就把所有的包给丢掉了。
是是非非 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wangxuhero 的回复:]
iptables -A INPUT -i eth1 -p tcp --sport $aPort -j ACCEPT
iptables -A INPUT -i eth1 -p udp --sport $aPort -j ACCEPT

数据包进入本机使用input策略访问本机的ServicePorts端口没错。
但是AccessPorts,只允许源端口是这几个端口的数据包的进入本机??


[/Quote]

哈,其实我是照着几个教程抄袭的。。。

就是想实现允许外网访问我ServicePorts里面定义的几个端口~

因为担心默认规则把服务器自己的联网功能给咔嚓了~所以也放开几个端口……不知道对不对

input / output加上 sport / dport 搞的我分不清方向了。。。
wangxuhero 2009-01-08
  • 打赏
  • 举报
回复
iptables -A INPUT -i eth1 -p tcp --sport $aPort -j ACCEPT
iptables -A INPUT -i eth1 -p udp --sport $aPort -j ACCEPT

数据包进入本机使用input策略访问本机的ServicePorts端口没错。
但是AccessPorts,只允许源端口是这几个端口的数据包的进入本机??

alaiyeshi 2009-01-08
  • 打赏
  • 举报
回复
BS狐狸,,还要1w分。。
我只要5K分
alaiyeshi 2009-01-08
  • 打赏
  • 举报
回复
我不来这里献丑了,低调的水过,msn上聊
加载更多回复(7)

19,610

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧