如何修改hosts.deny和hosts.allow?

我想阻止Ubuntu中的一些主机,所以我怎么能编辑hosts.deny文件来阻止像example.com这样的主机。

还有一件事我在Ubuntu中安装了dnsmasq ,那么我可以查看dnsmasq缓存的dns的条目吗? 如果是,那怎么样?

提前致谢。

hosts.deny示例:

 ALL: 192.168.1.2 ALL: example.org 

这拒绝了对192.168.1.2和example.org的所有服务。 有关详细信息,请查看此处: http : //linux.about.com/od/commands/l/blcmdl5_hostsde.htm

dnsmasq -d应该给你缓存的条目,但我不太确定。

— UPDATE —

使用iptables阻止IP地址:

 iptables -A INPUT -s 11.22.33.44 -j DROP 

解锁:

 iptables -D INPUT -s 11.22.33.44 -j DROP 

不推荐使用hosts.allowhosts.deny 。 它们由TCP Wrappers使用,基于主机的访问控制, http://en.wikipedia.org/wiki/TCP_Wrapper

如果要阻止对服务的访问,则需要查找是否已使用TCP Wrappers编译该服务。 我非常怀疑Ubuntu服务仍然使用TCP Wrappers。

TCP Wrappers库位于/lib/libwrap.so.0如果要检查lighttpd (Web服务器)是否支持TCP Wrappers,请运行

 > ldd /usr/sbin/lighttpd linux-vdso.so.1 => (0x00007fff2a5ff000) libpcre.so.3 => /lib/libpcre.so.3 (0x00007f69af837000) libdl.so.2 => /lib/libdl.so.2 (0x00007f69af633000) libattr.so.1 => /lib/libattr.so.1 (0x00007f69af42d000) libssl.so.0.9.8 => /lib/libssl.so.0.9.8 (0x00007f69af1db000) libcrypto.so.0.9.8 => /lib/libcrypto.so.0.9.8 (0x00007f69aee4b000) libfam.so.0 => /usr/lib/libfam.so.0 (0x00007f69aec42000) libc.so.6 => /lib/libc.so.6 (0x00007f69ae8bf000) /lib64/ld-linux-x86-64.so.2 (0x00007f69afa90000) libz.so.1 => /lib/libz.so.1 (0x00007f69ae6a8000) > _ 

它没有提到libwrap ,所以至少这个服务不支持TCP Wrappers,并且会忽略/etc/hosts.{allow, deny}

您希望使用防火墙来阻止对其他站点的访问。 我相信ufw是默认安装的。 命令man ufw应提供有关如何使用它的信息。 将192.0.2.15替换为要阻止的地址。

命令

  sudo ufw enable
 sudo ufw否认192.0.2.15