Chinaunix首页 | 论坛 | 博客
  • 博客访问: 510649
  • 博文数量: 101
  • 博客积分: 1635
  • 博客等级: 上尉
  • 技术积分: 1282
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-05 01:51
文章分类

全部博文(101)

文章存档

2019年(2)

2018年(16)

2013年(14)

2012年(69)

我的朋友

分类: LINUX

2012-11-12 20:00:45

1 selinux
selinux是redhat/centos系统的安全机制。配置繁琐,安装系统我们一般设置selinux关闭,引起不必要的麻烦。
关闭selinux的方法为:
[root@htdb ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
#SELINUX=enforcing
SELINUX=disbleed
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted
把'SELINUX=enforceing’改为'SELINUX=disabled',然后重启机器。
临时关闭selinux的命令为
[root@htdb ~]# getenforce
Enforcing
[root@htdb ~]# setenforce 0
[root@htdb ~]# getenforce
Permissive
如果要永久生效要在/etc/selinux/config的配置文件中修改。
2 iptables
iptables是linux上特有的防火墙机制,功能非常的强大
1)iptables的三个表
filter:主要用于过滤包,是系统预设的表。内建三个链input(进入本机的包),output本机发出的包
forward那些跟本机无关的包。
nat:主要用于网络地址的转换,有三个链。PREROUTING 链的作用是在包刚刚到达防火墙时改变它的目的地址,如果需要的话。OUTPUT链改变本地产生的包的目的地址。
POSTROUTING链在包就要离开防火墙之前改变其源地址。该表笔者用的不多,但有时候会用到。
mangle :这个表主要是用于给数据包打标记,然后根据标记去操作哪些包
2)iptables基本语法
a 查看规则和清除规则
[root@htdb ~]# iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 35137 packets, 8277K bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain POSTROUTING (policy ACCEPT 709 packets, 90159 bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain OUTPUT (policy ACCEPT 709 packets, 90159 bytes)
 pkts bytes target     prot opt in     out     source               destination
[root@htdb ~]# iptables -t filter -nvL
Chain INPUT (policy ACCEPT 45947 packets, 4695K bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain OUTPUT (policy ACCEPT 29314 packets, 3002K bytes)
 pkts bytes target     prot opt in     out     source               destination
清除规则的命令
[root@htdb ~]# iptables -F
[root@htdb ~]# iptables -Z
不加-t默认是对filter来操作,-F表示所有规则清除,-Z表示把包以及流量计数器置零
B 增加/删除一条规则
[root@htdb ~]# iptables -I INPUT -s 192.168.55.15 -j DROP
表示来自192.168.55.15的所有数据包丢掉
[root@htdb ~]# iptables -D INPUT -s 192.168.55.15 -j DROP
删除插入的规则 除了I和D不一样其他的地方都一样
[root@htdb ~]# iptables -A INPUT -s 192.168.55.15 -p tcp --dport 80 -j DROP
上面把所有的80端口的数据包丢掉。
删除一条规则
iptables -nvL --line-numbers
iptables -D OUTPUT 1
阅读(2467) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~