Centos6.8 DNS服务器配置iptables防火墙

本文详细介绍了在CentOS6.8系统中配置和管理iptables防火墙的过程,包括查看版本、grep命令查找规则、添加允许规则(如22端口SSH访问)、启动和开机自启设置,以及检查当前配置。
摘要由CSDN通过智能技术生成

#系统

centos6.8

[root@root ~]# cat /etc/redhat-release 
CentOS release 6.8 (Final)
#防火墙

[root@root ~]# rpm -qa | grep iptables
iptables-1.4.7-16.el6.x86_64
iptables-ipv6-1.4.7-16.el6.x86_64
#iptables防火墙配置文件

[root@root ~]# vim /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
#-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --sport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --sport 53 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A INPUT -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp --dport 22 -s 192.168.1.1 -j ACCEPT
-A INPUT -p tcp --dport 22 -j DROP
COMMIT

#说明

-A INPUT:表示将规则添加到INPUT链中,即针对输入流量的规则。
-m state --state NEW:使用state模块,匹配状态为NEW的数据包,即新建的连接。
-m tcp -p tcp:使用tcp模块,匹配TCP协议的数据包。
–dport 53:匹配目标端口号为53的数据包,即DNS服务的默认端口号。
-j ACCEPT:如果以上条件匹配,则接受该数据包。

#说明

-A INPUT -p tcp --dport 22 -s 192.168.1.1 -j ACCEPT

22端口ssh限制源IP192.168.1.1

#启动iptables/重启启动iptables

service iptables start

service iptables restart

#设置开机自启

chkconfig iptables on

#查看开机自启

chkconfig --list | grep iptables

#检查iptables配置

iptables -L

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值