在服务器上架了一个tomcat,指定好端口号,我就开始访问,未果! :(
公司对服务器(RedHat)端口限制,可谓是滴水不漏! :idea:
用iptables 查看防火墙设置:
[img]http://dl.iteye.com/upload/attachment/301916/41284685-96f5-3a76-8fea-fef8015698b4.jpg[/img]
我需要一个8880端口,看来是不能访问了! :D
直接修改配置文件:
[img]http://dl.iteye.com/upload/attachment/301918/90b92d9d-1659-3c1d-a0d8-684b9cb6972d.jpg[/img]
照猫画虎,增加红框中的内容!
这样做还不保险,诡异状况下这个端口还是会被屏蔽!
强制保存:
[img]http://dl.iteye.com/upload/attachment/302478/00760d4f-7ff6-39f0-846d-e9f800be0f3b.jpg[/img]
然后,重启服务:
[img]http://dl.iteye.com/upload/attachment/301923/0db01b91-0261-3ca9-9695-7e8be96bbf58.jpg[/img]
再看看防火墙设置:
[img]http://dl.iteye.com/upload/attachment/301929/f1a3d8e2-8870-343b-bce5-1b4015a9eca1.jpg[/img]
OK,现在就可以通过ip+端口在局域网内访问了! :D
来点实际的,限制外网非80端口的一切访问
使用命令
使用[b]iptables-save[/b]强制生效,但我无论如何使用该命令,重启ipatbles服务后,都是根据配置文件走的。
来个直接的,编辑iptables
追加以下内容:
重启iptables:
查看iptables状态:
[quote]Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 127.0.0.1 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
DROP all -- !10.0.0.0/8 0.0.0.0/0 [/quote]
一定要注意顺序,一定是先做ACCEPT的配置,最后做DROP的配置!!! :D
否则,配置错误了,连SSH都没得用! :)
[color=red][b]最后,最关键的一步,使得iptable配置随系统启动:[/b][/color]
[quote]# service iptables save
将当前规则保存到 /etc/sysconfig/iptables: [确定][/quote]
据说
[quote]
Iptables的命令选项
iptables [-t tables] command option parameter target
-A 在链尾添加一条规则
-C 将规则添加到用户定义链之前对其进行检查
-D 从链中删除一条规则
-E 重命名用户定义的链,不改变链本身
-F 清空链,删除链上的所有规则
-I 在链中插入一条规则
-L 列出某个链上的规则,如iptables –L INPUT 列出INPUT链的规则
-N 创建一个新链
-P 定义某个链的默认策略
-R 替换链上的某条规则
-X 删除某个用户相关的链
-Z 将所有表的所有
[/quote]
公司对服务器(RedHat)端口限制,可谓是滴水不漏! :idea:
用iptables 查看防火墙设置:
iptables -nL
[img]http://dl.iteye.com/upload/attachment/301916/41284685-96f5-3a76-8fea-fef8015698b4.jpg[/img]
我需要一个8880端口,看来是不能访问了! :D
直接修改配置文件:
vi /etc/sysconfig/iptables
[img]http://dl.iteye.com/upload/attachment/301918/90b92d9d-1659-3c1d-a0d8-684b9cb6972d.jpg[/img]
照猫画虎,增加红框中的内容!
这样做还不保险,诡异状况下这个端口还是会被屏蔽!
强制保存:
service iptables save
[img]http://dl.iteye.com/upload/attachment/302478/00760d4f-7ff6-39f0-846d-e9f800be0f3b.jpg[/img]
然后,重启服务:
service iptables restart
[img]http://dl.iteye.com/upload/attachment/301923/0db01b91-0261-3ca9-9695-7e8be96bbf58.jpg[/img]
再看看防火墙设置:
iptables -nL
[img]http://dl.iteye.com/upload/attachment/301929/f1a3d8e2-8870-343b-bce5-1b4015a9eca1.jpg[/img]
OK,现在就可以通过ip+端口在局域网内访问了! :D
来点实际的,限制外网非80端口的一切访问
使用命令
#接受80端口的tcp访问,且指定网卡为eth1
iptables -A INPUT -p tcp -m tcp --dport 80 -i eth1 -j ACCEPT
#拒绝非内网地址的一切访问,指定网卡为eth1
iptables -A INPUT -s ! 10.0.0.0/255.0.0.0 -i eth1 -j DROP
使用[b]iptables-save[/b]强制生效,但我无论如何使用该命令,重启ipatbles服务后,都是根据配置文件走的。
来个直接的,编辑iptables
vim /etc/sysconfig/iptables
追加以下内容:
#接受80端口的tcp访问,且指定网卡为eth1
-A INPUT -p tcp -m tcp --dport 80 -i eth1 -j ACCEPT
#拒绝非内网地址的一切访问,指定网卡为eth1
-A INPUT -s ! 10.0.0.0/255.0.0.0 -i eth1 -j DROP
重启iptables:
service iptables restart
查看iptables状态:
iptables -nL
[quote]Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 127.0.0.1 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
DROP all -- !10.0.0.0/8 0.0.0.0/0 [/quote]
一定要注意顺序,一定是先做ACCEPT的配置,最后做DROP的配置!!! :D
否则,配置错误了,连SSH都没得用! :)
[color=red][b]最后,最关键的一步,使得iptable配置随系统启动:[/b][/color]
service iptables save
[quote]# service iptables save
将当前规则保存到 /etc/sysconfig/iptables: [确定][/quote]
据说
chkconfig iptables on
也可以达到自动启动作用,即启动iptables就会自动读取配置文件(/etc/sysconfig/iptables) 。[quote]
Iptables的命令选项
iptables [-t tables] command option parameter target
-A 在链尾添加一条规则
-C 将规则添加到用户定义链之前对其进行检查
-D 从链中删除一条规则
-E 重命名用户定义的链,不改变链本身
-F 清空链,删除链上的所有规则
-I 在链中插入一条规则
-L 列出某个链上的规则,如iptables –L INPUT 列出INPUT链的规则
-N 创建一个新链
-P 定义某个链的默认策略
-R 替换链上的某条规则
-X 删除某个用户相关的链
-Z 将所有表的所有
[/quote]