🐧
Linux
  • Introduction
  • 🖇️general
    • essentials
    • other commands
    • Superuser-do (sudo)
    • SUID, SGID, sticky bit
    • /dev/null
    • environment variables
    • special variables
    • shebang
  • spool
  • 🔧bash
    • overview
    • redirection
    • loop
    • .bashrc
  • text processing
    • grep
    • sed
    • awk
  • xxd/hexdump
  • text editors
    • nano
    • vi/vim
  • 📂filesystem & directories
    • Filesystem Hierachy Standard (FHS)
      • /etc
        • hosts, hosts.allow, hosts.deny
        • /cron.d
        • /httpd
        • /samba.d
        • hostname
        • crontab
        • shadow
        • passwd
        • profile
        • services
      • /dev
      • /proc
        • version
      • /mnt
      • /opt
      • /sbin
      • /lib
      • /usr
      • /tmp
      • /var
      • /bin
      • /run
    • chroot
  • find
  • locate
  • ⌚processes & jobs
    • cronjob
    • daemon
  • ⛓️system
    • systemctl
    • hostname
    • systemd
  • 🗃️media
    • ffmpeg
    • pdftk
  • 🔒Security
    • ufw
  • firejail
  • apparmor
  • 📦Package management
    • dpkg
    • apt/apt-get
  • Storage
    • lsblk
    • mount/umount
  • df/du
  • user management
    • chsh
  • Networking
    • Introduction
    • routing table/interface management
    • /etc/hosts, /etc/hosts.allow, /etc/hosts.deny
Powered by GitBook
On this page
  • /etc/hosts
  • /etc/hosts.allow and /etc/hosts.deny
  1. Networking

/etc/hosts, /etc/hosts.allow, /etc/hosts.deny

/etc/hosts

The /etc/hosts file acts as a local database to provide information for DNS resolutions, in the form of mapping hostnames (or fully qualified domain names - FQDN) to IP address values.

The following is the general format for each line in the file

[IP_addr_to_resolve] [hostname_1] [optional_hostname_2]

Eg. Mapping hostname jarrettgxz.com to the IP address value of 8.8.8.8

Multiple hostnames can be included for each IP address value

  • The second line maps the hostnames example.com and example2.com to the IP address 10.10.10.10.

8.8.8.8 jarrettgxz.com
10.10.10.10 example1.com example2.com 

/etc/hosts.allow and /etc/hosts.deny

The /etc/hosts.allow and /etc/hosts.deny files are used to allow or restrict access to local services for specific IP addresses or hostnames.

General format of entry

service: host/network

Note that /etc/hosts.allow takes precedence over the /etc/hosts.deny file

Eg. Allow or deny access all traffic to the sshd service

sshd: ALL

Eg. Allow or deny access to all traffic from *.example.com: test.example.com, 1.example.com, etc. to the sshd service

sshd: .example.com 

Eg. Allow or deny access to all traffic from 192.168.1.*: 192.168.1.1, 192.168.1.88, etc. to the sshd service

sshd: 192.168.1. 
Previousrouting table/interface management

Last updated 2 months ago

hosts.allow format and example on LinuxLinuxConfig
Logo