9. iptables 配置
来源:互联网 发布:嵌入式linux内核移植 编辑:程序博客网 时间:2024/06/06 07:51
9. iptables 配置
iptables 配置文件存放位置:
[root@Demon yum.repos.d]# vim /etc/rc.d/init.d/iptables
一、只给 Centos 6.5 打开 22 和 80 端口,并且重启后有效:
1、查看所有 iptables 配置:
[root@Demon yum.repos.d]# iptables -L -n (当前防火墙是关闭的)
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
2、只允许 80 和 22 端口通过防火墙
# 清除所有规则
[root@Demon opt]# iptables -F
# 只允许 发送的包从 22 端口进入和返回, -A 的意思是添加一条 INPUT 规则, -p 指定为什么协议,--dport 为目标端口
[root@Demon opt]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
[root@Demon opt]# iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
# 允许本机访问本机
[root@Demon opt]# iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
[root@Demon opt]# iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
# 允许所有 IP 访问 80 端口
[root@Demon opt]# iptables -A INPUT -p tcp -s 0/0 --dport 80 -j ACCEPT
[root@Demon opt]# iptables -A OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
[root@Demon opt]# iptables -P INPUT DROP
[root@Demon opt]# iptables -P OUTPUT DROP
[root@Demon opt]# iptables -P FORWARD DROP
# 保存配置
[root@Demon opt]# iptables-save > /etc/sysconfig/iptables
[root@Demon opt]# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT all -- localhost localhost
ACCEPT tcp -- anywhere anywhere tcp dpt:http
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:ssh state ESTABLISHED
ACCEPT all -- localhost localhost
ACCEPT tcp -- anywhere anywhere tcp spt:http state ESTABLISHED
# 重启电脑后, ping 一下百度:
[root@Demon opt]# ping www.baidu.com
ping: unknown host www.baidu.com
二、关闭 iptables
# 打开防火墙,重启生效
# chkconfig iptables on
# 关闭防火墙,重启生效
# chkconfig iptables off
# 打开防火墙,立即生效,重启后不生效
# chkconfig start
# 关闭防火墙,立即生效,重启后不生效
# chkconfig stop
0 0
- 9. iptables 配置
- iptables配置
- iptables配置
- IPTABLES配置
- iptables 配置
- iptables配置
- IPTABLES配置
- iptables配置
- 配置iptables
- iptables 配置
- iptables配置
- iptables配置
- 配置iptables
- iptables配置
- IPTABLES配置
- iptables配置
- iptables 配置工具比较
- IPTABLES配置方法介绍
- 17.2.20 Sparsifying Neural Network Connections for Face Recognition 小感
- 读取excel文件并将其中数据转换成脚本数据结构
- 编译unity-mono( 写给超级初学者的朋友)
- surface pro 4专业版没有64位虚拟机选项的解决办法
- 深度学习简介--PPT
- 9. iptables 配置
- springmvc接收json串,转换为实体类List探索
- Position属性四个值区别和用法
- zookeeper选举规则
- 10. 编译软件包
- OpenCV python学习笔记(六)
- 【USACO4.4.2】追查坏牛奶(BSOI2140)
- 博客园自定义之博客园公告栏添加时钟——利用canvas画出一个时钟
- 11. 系统状态管理