[root@server ~]# iptables -F
[root@server ~]# iptables -X
[root@server ~]# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT    # 不允许服务器主动建立新连接
[root@server ~]# iptables -A INPUT -p tcp -m multiport --dport , -m state --state NEW -j ACCEPT   # 允许22,80端口的连接和监听
[root@server ~]# iptables -A OUTPUT -p tcp -m multiport --sport 22,80 -j ACCEPT  # 允许客户端访问22,80端口
[root@server ~]# iptables -P INPUT DROP  # 默认禁止
[root@server ~]# iptables -P FORWARD DROP  # 默认禁止
[root@server ~]# iptables -P OUTPUT DROP  # 默认禁止
[root@server ~]# iptables -A INPUT -p udp --sport -j ACCEPT  # 允许dns服务
[root@server ~]# iptables -A OUTPUT -p udp --dport -j ACCEPT  # 允许dns服务
[root@server ~]# iptables -A INPUT -p icmp -j ACCEPT    # 开启 icmp协议
[root@server ~]# iptables -A OUTPUT -p icmp -j ACCEPT  # 开启 icmp协议
[root@server ~]# service iptables save    # 保存配置
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@server ~]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]

对应一般的简单web服务器基本够用,当然ssh端口肯定会修改,以上命令也进行调整。如果要禁止别人ping服务器,建议进行以下设置:

临时生效:echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

永久生效:

[root@server ~]# echo "net.ipv4.icmp_echo_ignore_all = 1" >> /etc/sysctl.conf
[root@server ~]# sysctl -p

# Generated by iptables-save v1.4.7 on Mon Mar  ::
*filter
:INPUT DROP [:]
:FORWARD DROP [:]
:OUTPUT DROP [:]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m multiport --sports , -m state --state NEW -j ACCEPT
-A INPUT -p udp -m udp --sport -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A OUTPUT -p tcp -m multiport --sports 22,80 -j ACCEPT
-A OUTPUT -p udp -m udp --dport -j ACCEPT
-A OUTPUT -p icmp -j ACCEPT
COMMIT
# Completed on Mon Mar ::

可以直接复制上面iptables配置到vim /etc/sysconfig/iptables 然后重启iptables

关于转发:

因为非root用户不能监听1024以下端口,所以经常使用iptables来进行转发的工作:

iptables -t nat -A PREROUTING -p tcp --dport  -j REDIRECT --to-port 8080  # 8080端口映射到80端口
iptables -t nat -A PREROUTING -p tcp --dport -j DNAT --to-destination 192.168.2.11:8080 # 192.168.2.11的8080端口映射到80端口。可用于两台主机转发

[ 总结 ] web server iptables 简单配置的更多相关文章

  1. iptables简单配置

    iptables简单配置 分类: Linux 安全2010-10-20 16:56 4241人阅读 评论(0) 收藏 举报 input防火墙tcpfilterubuntuservice # iptab ...

  2. iptables 简单配置

    通过命令 netstat -tnl 可以查看当前服务器打开了哪些端口  Ssh代码   netstat -tnl     查看防火墙设置  Ssh代码   iptables -L -n      开放 ...

  3. Linux iptables简单配置

    #!/bin/sh#modprobe ipt_MASQUERADEmodprobe ip_conntrack_ftpmodprobe ip_nat_ftpiptables -Fiptables -t ...

  4. JetBrains IDEA Web开发简单配置

    很早前因为使用了一年的MyEclipse,不想更换其他的IDE工具,是因为各项配置,以及快捷键等.前段时间更换了IDEA工具,初步了解了一些功能,包括快捷,调试,配置,都很优于MyEclipse.但是 ...

  5. PHP内置的Web Server的使用

    自PHP5.4之后 PHP内置了一个Web 服务器. 让我们来看看php Web Server的简单使用: 启动php Web Server php -S localhost:8080 通过 php ...

  6. 释放SQL Server占用的内存 .Net 读取xml UrlReWriter 在web.config中简单的配置

    释放SQL Server占用的内存   由于Sql Server对于系统内存的管理策略是有多少占多少,除非系统内存不够用了(大约到剩余内存为4M左右),Sql Server才会释放一点点内存.所以很多 ...

  7. Web Server Jexus配置及使用

    Web Server  Jexus配置及使用 一.jexus概念: Jexus 即 Jexus Web Server,简称JWS,是Linux平台上的一款ASP.NET WEB服务器,是 Linux. ...

  8. Jexus-5.6.3使用详解、Jexus Web Server配置

    一.Jexus Web Server配置   在 jexus 的工作文件夹中(一般是“/usr/jexus”)有一个基本的配置文件,文件名是“jws.conf”. jws.conf 中至少有 Site ...

  9. Unity3d Web Player 与server端联网配置

    针对Unity3d Web Player 的server端联网配置写一随笔咯.  以SmartFoxServer2X官方的Unity3d Example ”tris“为例,部署好服务器之后,在Unit ...

随机推荐

  1. node gyp的问题

    解决 binding.gyp not found (xxx/xxx/xxx) while trying to load binding.gyp 问题 在使用ccap图形验证码模块时遇到这个问题 Err ...

  2. xampp开户,apache打开出现端口被占用提示

    刚装上去的时候,可以打开xampp,但是重启的时候出现以后以下问题 13:49:02  [Apache]     Error: Apache shutdown unexpectedly.13:49:0 ...

  3. winform 外部组件发生异常

    问题描述.先前程序运行可以正常,但是突然这次调试就弹出此异常: 解决方法:1.本次调试是不是重新生成解决方案了?应该是因为之前的解决方案删了,把引用的dll(包含此dll关联的dll)自动删掉: 2. ...

  4. 查看ClassLoader载入了哪些类?

    在执行jar时加上-verbose:class java  -verbose:class -Xms1G -Xmx2G -jar xx.jar 必要时还可以使用 >log.txt 将输出输入到文本 ...

  5. 微信公众号开发java框架:wx4j(MenuUtils篇)

    wx4j-MenuUtils使用 函数说明:发送http请求到微信服务器,完成菜单创建 参数:构造菜单对象 返回值:微信响应的json字符串 public static String createMe ...

  6. penLDAP学习笔记

    LDAP协议 目录是一组具有类似属性.以一定逻辑和层次组合的信息.常见的例子是通讯簿,由以字母顺序排列的名字.地址和电话号码组成.目录服务是一种在分布式环境中发现目标的方法.目录具有两个主要组成部分: ...

  7. Bjarne Stroustrup语录2

    一.致读者  1. 在编程序时,你是在为你针对某个问题的解决方案中的思想建立起一种具体表示.让程序的结构尽可能地直接反映这些思想:   ★.如果你能把“它”看成一个独立的概念,就把它做成一个类.    ...

  8. Nginx学习笔记之加强篇

    在上一篇文章Nginx学习笔记之应用篇中,我们已经可以正式运行自己的网站了.但是在使用Nginx服务器时还需要注意几个问题: 1.Nginx服务器上配置的单个站点的并发量不超过1024 2.Nginx ...

  9. [BZOJ1449] [JSOI2009]球队收益 / [BZOJ2895] 球队预算

    Description 在一个篮球联赛里,有n支球队,球队的支出是和他们的胜负场次有关系的,具体来说,第i支球队的赛季总支出是Cix^2+Diy^2,Di<=Ci.(赢得多,给球员的奖金就多嘛) ...

  10. 几个JQuery解析XML的程序例子

    用JavaScript解析XML数据是常见的编程任务,JavaScript能做的,JQuery当然也能做.下面我们来总结几个使用JQuery解析XML的例子. 第一种方案: <script ty ...