[ 总结 ] web server iptables 简单配置
[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 简单配置的更多相关文章
- iptables简单配置
iptables简单配置 分类: Linux 安全2010-10-20 16:56 4241人阅读 评论(0) 收藏 举报 input防火墙tcpfilterubuntuservice # iptab ...
- iptables 简单配置
通过命令 netstat -tnl 可以查看当前服务器打开了哪些端口 Ssh代码 netstat -tnl 查看防火墙设置 Ssh代码 iptables -L -n 开放 ...
- Linux iptables简单配置
#!/bin/sh#modprobe ipt_MASQUERADEmodprobe ip_conntrack_ftpmodprobe ip_nat_ftpiptables -Fiptables -t ...
- JetBrains IDEA Web开发简单配置
很早前因为使用了一年的MyEclipse,不想更换其他的IDE工具,是因为各项配置,以及快捷键等.前段时间更换了IDEA工具,初步了解了一些功能,包括快捷,调试,配置,都很优于MyEclipse.但是 ...
- PHP内置的Web Server的使用
自PHP5.4之后 PHP内置了一个Web 服务器. 让我们来看看php Web Server的简单使用: 启动php Web Server php -S localhost:8080 通过 php ...
- 释放SQL Server占用的内存 .Net 读取xml UrlReWriter 在web.config中简单的配置
释放SQL Server占用的内存 由于Sql Server对于系统内存的管理策略是有多少占多少,除非系统内存不够用了(大约到剩余内存为4M左右),Sql Server才会释放一点点内存.所以很多 ...
- Web Server Jexus配置及使用
Web Server Jexus配置及使用 一.jexus概念: Jexus 即 Jexus Web Server,简称JWS,是Linux平台上的一款ASP.NET WEB服务器,是 Linux. ...
- Jexus-5.6.3使用详解、Jexus Web Server配置
一.Jexus Web Server配置 在 jexus 的工作文件夹中(一般是“/usr/jexus”)有一个基本的配置文件,文件名是“jws.conf”. jws.conf 中至少有 Site ...
- Unity3d Web Player 与server端联网配置
针对Unity3d Web Player 的server端联网配置写一随笔咯. 以SmartFoxServer2X官方的Unity3d Example ”tris“为例,部署好服务器之后,在Unit ...
随机推荐
- Linux 远程主机安全配置
开启了新的 Linux 服务器后,首要任务是做安全配置. 首先更新: # ubuntu sudo apt-get update # 获取 apt 源的软件列表 sudo apt-get upgrade ...
- BZOJ 4595 SHOI2015 激光发生器 射线,线段,偏转
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4595 题意概述: 给出一条射线和N条线段,射线遇到线段会发生反射,令入射角alpha,出射 ...
- HDU 4441 Queue Sequence(优先队列+Treap树)(2012 Asia Tianjin Regional Contest)
Problem Description There's a queue obeying the first in first out rule. Each time you can either pu ...
- BufferedInputStream/BufferedOutputStream
BufferedInputStream: public synchronized int read() throws IOException int res=bis.read(); System.ou ...
- C#的Response.BinaryWrite图片乱码问题
今天学习Response对象,该对象的有很多的输出方式,其中有一个binaryWrite可以输出图片,但是在输出图片一开始出现了乱码,后来通过百度得到解决: 代码: FileStream stream ...
- lintcode-95-验证二叉查找树
95-验证二叉查找树 给定一个二叉树,判断它是否是合法的二叉查找树(BST) 一棵BST定义为: 节点的左子树中的值要严格小于该节点的值. 节点的右子树中的值要严格大于该节点的值. 左右子树也必须是二 ...
- CentOS 7 samba 配置
1.安装samba sudo yum install samba 2.环境配置 a.关闭防火墙 sudo systemctl stop firewalld.service #停止firewallsud ...
- web online ide &web online editor & web online playground & web online runtime
web online ide &web online editor web online ide &web online editor & web online playgro ...
- RadioGroup和GroupBox有什么区别?
我在RadioGroup中放RadioButton和GroupBox中一样,搞不明白. radiogroup有个item属性都是radio控件,不需要拖控件上去.groupbox需要自己拖控件 分组的 ...
- P2124 奶牛美容
题目描述 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 6 16 ................ ..XXXX....XXX... ...XXXX....XX... .XXXX ...