Linux网络访问黑/白名单服务

Linux网络访问黑/白名单服务

基于当前网络的发达,一些技术人员会想到其它网站和服务器看看,不管是为了实践还是其它不好的目的,我们为了服务器的安全都需要把它们屏蔽在我们的系统之外,让我们的服务器安全可靠。

  • Linux配置黑白名单格式

    编辑/etc/hosts.deny和/etc/hosts.allow文件配合使用完成网络IP的屏蔽

/etc/hosts.allow
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
sshd:10.1.5.*:allow
sshd:10.2.5.*:allow
以上写法表示允许10.1.510.2.5两个ip段连接sshd服务(这必然需要hosts.deny这个文件配合使用),当然:allow完全可以省略的
如果管理员集中在一个IP那么这样写是比较省事的
all:10.1.5.10//他表示接受10这个ip的所有请求!

/etc/hosts.deny文件,此文件是拒绝服务列表,文件内容如下:
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
sshd:all:deny
注意看:sshd:all:deny表示拒绝了所有sshd远程连接。:deny可以省略。
所以:当hosts.allow和 host.deny相冲突时,以hosts.allow设置为准。
注意修改完后:
service xinetd restart
才能让刚才的更改生效

/etc/hosts.allow(允许)和/etc/hosts.deny(禁止)这两个文件是tcpd服务器的配置文件
tcpd服务器可以控制外部IP对本机服务的访问
linux 系统会先检查/etc/hosts.deny规则,再检查/etc/hosts.allow规则,如果有冲突 按/etc/hosts.allow规则处理

比如:
1.禁止所有ip访问linux 的ssh功能
可以在/etc/hosts.deny添加一行 sshd:all:deny

2.禁止某一个ip(192.168.11.112)访问ssh功能
可以在/etc/hosts.deny添加一行sshd:192.168.11.112

3.如果在/etc/hosts.deny和/etc/hosts.allow同时 有sshd:192.168.11.112 规则,则192.168.11.112可以访问主机的ssh服务
总结:通过这种方法可以控制部分非授权访问,但不是一劳永逸的方法!我们在看服务日志的时候或许会看到很多扫描记录,不是还是直接针对root用户的,这时控制你的访问列表就非常有作用了!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值