linux 如何禁止IP访问http服务器

如题所述

Linux系统中,如果需要禁止特定ip地址访问来保证系统的安全,只需通过操作iptalbes来实现,下面就给绍下Linux如何禁止某个ip地址访问。
一、概述
这两个文件是tcpd服务器的配置文件,tcpd服务器可以控制外部IP对本机服务的访问。这两个配置文件的格式如下:
#服务进程名:主机列表:当规则匹配时可选的命令操作
server_name:hosts-list[:command]
/etc/hosts.allow控制可以访问本机的IP地址,/etc/hosts.deny控制禁止访问本机的IP。如果两个文件的配置有冲突,以/etc/hosts.deny为准。
/etc/hosts.allow和/etc/hosts.deny两个文件是控制远程访问设置的,可以允许或者拒绝某个ip或者ip段的客户访问linux的某项服务。
比如SSH服务,通常只对管理员开放,那就可以禁用不必要的IP,而只开放管理员可能使用到的IP段。
二、配置
1、修改/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:210.13.218.*:allow
sshd:222.77.15.*:allow
all:218.24.129.110 #表示接受110这个ip的所有请求!
in.telnetd:140.116.44.0/255.255.255.0
in.telnetd:140.116.79.0/255.255.255.0
in.telnetd:140.116.141.99
in.telnetd:LOCAL
smbd:192.168.0.0/255.255.255.0 #允许192.168.0.网段的IP访问smbd服务
#sendmail:192.168.1.0/255.255.255.0
#pop3d:192.168.1.0/255.255.255.0
#swat:192.168.1.0/255.255.255.0
pptpd:all EXCEPT 192.168.0.0/255.255.255.0
httpd:all
vsftpd:all
以上写法表示允许210和222两个ip段连接sshd服务(这必然需要hosts.deny这个文件配合使用),当然:allow完全可以省略的。
ALL要害字匹配所有情况,EXCEPT匹配除了某些项之外的情况,PARANOID匹配你想控制的IP地址和它的域名不匹配时(域名伪装)的情况。
2、修改/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
in.telnet:ALL
ALL:ALL EXCEPT 192.168.0.1/255.255.255.0,192.168.1.21,
202.10.5.0/255.255.255.0
注意看:sshd:all:deny表示拒绝了所有sshd远程连接。:deny可以省略。
3、启动服务。
注意修改完后:
#service xinetd restart
才能让刚才的更改生效。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-02-28
将想要禁止的IP添加到/etc/hosts.deny中。格式: sshd:IP
第2个回答  2012-11-24
用comodo ,可以禁止你不希望连接的端口,很强大来自:求助得到的回答
第2个回答  2012-11-24
iptable 禁止外面ip的访问你http服务端口。具体的策略命令网上很多,自己找下影像深一点本回答被提问者采纳
第3个回答  2012-11-17
iptable 这个防火墙有这个功能。
怎么设置我就不知道了。追问

linux 防火墙么 那个是 禁止的

追答

iptable 写规则,这个需要自己找教程了,我没用过。
我记得 iptable 有一些图形化的前台程序可以用。不过现在大家基本都是靠命令……
貌似目前禁止 IP 访问,只能靠 iptable 写规则了。

相似回答