Chapter 8. Securing network services


Harden and monitor network services to protect your system against various risks. Turning off unused services helps limit exposure.

Red Hat Enterprise Linux supports many different types of network servers. Their network services can expose the system to various kinds of attacks. These include denial-of-service (DoS), distributed denial-of-service (DDoS), script vulnerability, and buffer overflow attacks.

To increase system security against attacks, it is crucial to monitor the active network services you use. For example, when a network service runs on a machine, its daemon listens for connections on network ports. This can reduce security. To limit network exposure to attacks, turn off all unused services, ports, and networking capabilities.

8.1. Securing the rpcbind service

You can secure rpcbind by restricting access to all networks and defining specific exceptions by using firewall rules on the server.

The rpcbind service is a dynamic port-assignment daemon for remote procedure calls (RPC) services such as Network Information Service (NIS) and Network File System (NFS). Because it has weak authentication mechanisms and can assign a wide range of ports for the services it controls, secure rpcbind.

Note
  • The rpcbind service is required on NFSv3 servers.
  • The rpcbind service is not required on NFSv4.

Prerequisites

  • The rpcbind package is installed.
  • The firewalld package is installed and the service is running.

Procedure

  1. Add firewall rules, for example:

    • Limit TCP connection and accept packages only from the 192.168.0.0/24 host on port 111:

      # firewall-cmd --add-rich-rule='rule family="ipv4" port port="111" protocol="tcp" source address="192.168.0.0/24" invert="True" drop'
    • Limit TCP connection and accept packages only from local host on port 111:

      # firewall-cmd --add-rich-rule='rule family="ipv4" port port="111" protocol="tcp" source address="127.0.0.1" accept'
    • Limit UDP connection and accept packages only from the 192.168.0.0/24 host on port 111:

      # firewall-cmd --permanent --add-rich-rule='rule family="ipv4" port port="111" protocol="udp" source address="192.168.0.0/24" invert="True" drop'

      To make the firewall settings permanent, use the --permanent option when adding firewall rules.

  2. Reload the firewall to apply the new rules:

    # firewall-cmd --reload

Verification

  • List the firewall rules:

    # firewall-cmd --list-rich-rule
    rule family="ipv4" port port="111" protocol="tcp" source address="192.168.0.0/24" invert="True" drop
    rule family="ipv4" port port="111" protocol="tcp" source address="127.0.0.1" accept
    rule family="ipv4" port port="111" protocol="udp" source address="192.168.0.0/24" invert="True" drop

Troubleshooting

  • If NFS clients cannot connect after applying the firewall rules, verify that the client IP addresses are within the allowed subnet:

    # firewall-cmd --list-all

    Check that the rich rules allow the client’s source address.

  • If clients from the allowed subnet still cannot connect, verify that the rpcbind service is running:

    # systemctl status rpcbind
  • If firewall changes are not taking effect, verify that the rules were made permanent:

    # firewall-cmd --permanent --list-rich-rules

    If the rules are missing, re-add them with the --permanent option and reload the firewall.

  • If you added rules without --permanent and then reloaded, the rules are lost. Use --runtime-to-permanent to save current runtime rules:

    # firewall-cmd --runtime-to-permanent

8.2. Securing the rpc.mountd service

The rpc.mountd daemon implements the server side of the NFS mount protocol. The NFS mount protocol is used by NFS version 3 (RFC 1813).

You can secure the rpc.mountd service by adding firewall rules. Restrict access to all networks and define specific exceptions.

Prerequisites

  • The rpc.mountd package is installed.
  • The firewalld package is installed and the service is running.

Procedure

  1. Add firewall rules with the --permanent option to make them persistent across reboots.

    Examples:

    • Drop mountd connections from the 192.168.0.0/24 network:

      # firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" service name="mountd" source address="192.168.0.0/24" invert="True" drop'
    • Accept mountd connections from the local host:

      # firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source address="127.0.0.1" service name="mountd" accept'
  2. Reload the firewall to apply the new rules:

    # firewall-cmd --reload

Verification

  • List the firewall rules:

    # firewall-cmd --list-rich-rule
    rule family="ipv4" service name="mountd" source address="192.168.0.0/24" invert="True" drop
    rule family="ipv4" source address="127.0.0.1" service name="mountd" accept

Troubleshooting

  • If NFS clients cannot mount file systems after applying the firewall rules, verify that the client IP addresses are within the allowed subnet:

    # firewall-cmd --list-all

    Check that the rich rules allow the client’s source address.

  • If clients from the allowed subnet still cannot mount, verify that the rpc.mountd service is running:

    # systemctl status nfs-mountd
  • If firewall changes are not taking effect, verify that the rules are applied with the --permanent option and the firewall is reloaded.
  • To debug firewall blocking, temporarily enable logging for dropped packets:

    # firewall-cmd --set-log-denied=all
    # journalctl -f -u firewalld

    Attempt the NFS mount from the client and check the logs for dropped packets. Disable logging after troubleshooting:

    # firewall-cmd --set-log-denied=off

8.3. Securing the NFS service

Secure Network File System (NFS) by using Kerberos authentication and encryption for file system operations. Proper security configuration helps protect remote hosts mounting file systems over a network.

When using NFSv4 with Network Address Translation (NAT) or a firewall, you can turn off the delegations by modifying the /etc/default/nfs file. Delegation is a technique by which the server delegates the management of a file to a client. In contrast, NFSv3 do not use Kerberos for locking and mounting files.

The NFS service sends the traffic using TCP in all versions of NFS. The service supports Kerberos user and group authentication, as part of the RPCSEC_GSS kernel module.

NFS allows remote hosts to mount file systems over a network and interact with those file systems as if they are mounted locally. You can merge the resources on centralized servers and additionally customize NFS mount options in the /etc/nfsmount.conf file when sharing the file systems.

8.3.1. Export options for securing an NFS server

Use export options in the /etc/exports file to define which hosts can access exported file systems and the permissions they hold. This helps control access and limits security risks.

Configure which file systems to export and which hosts can access them in the /etc/exports file.

You can use the following export options on the /etc/exports file:

ro
Exports the NFS volume as read-only.
rw
Controls permission for read and write requests on the NFS volume. Use this option cautiously, as granting write access increases the risk of attacks. If your scenario requires mounting the directories with the rw option, make sure they are not writable for all users to reduce possible risks.
root_squash
Maps requests from uid/gid 0 to the anonymous uid/gid. This does not apply to any other UIDs or GIDs that might be equally sensitive, such as the bin user or the staff group.
no_root_squash
Turns off root squashing. By default, NFS shares change the root user to the nobody user, which is an unprivileged user account. This changes the owner of all the root-created files to nobody, which prevents the uploading of programs with the setuid bit set. When using the no_root_squash option, remote root users can change any file on the shared file system and leave applications infected by trojans for other users.
secure
Restricts exports to reserved ports. By default, the server allows client communication only through reserved ports. However, it is easy for anyone to become a root user on a client on many networks, so it is rarely safe for the server to assume that communication through a reserved port is privileged. Therefore, restricting to reserved ports is of limited value; it is better to rely on Kerberos, firewalls, and limiting exports to particular clients.

See the exports(5) and nfs(5) man pages on your system for more information.

You can check the shared directories on your system by entering the showmount -e <hostname> command.

Warning

Extra spaces in the syntax of the /etc/exports file can lead to significant changes in the configuration.

In the following example, the /tmp/nfs/ directory is shared with the bob.example.com host and has read and write permissions:

/tmp/nfs/     bob.example.com(rw)

The following example is the same as the previous one, but shares the same directory to the bob.example.com host with read-only permissions and shares it to the world with read and write permissions due to a single space character after the hostname:

/tmp/nfs/     bob.example.com (rw)

Additionally, consider the following best practices when exporting an NFS server:

  • Exporting home directories is a risk because some applications store passwords in plain text or in a weakly encrypted format. You can reduce the risk by reviewing and improving the application code.
  • Some users do not set passwords on SSH keys, which again leads to risks with home directories. You can reduce these risks by enforcing the use of passwords or using Kerberos.
  • Restrict the NFS exports only to required clients. Use the showmount -e command on the NFS server to review what the server is exporting. Do not export anything that is not specifically required.
  • Do not allow unnecessary users to log in to a server to reduce the risk of attacks. You can periodically check who and what can access the server.
Warning

Export an entire file system because exporting a subdirectory of a file system is not secure. An attacker might access the unexported part of a partially-exported file system.

8.3.2. Mount options for securing an NFS client

You can apply mount options when configuring an NFS client to help enforce stronger security. These settings ensure that the client/server communication uses required security protocols such as Kerberos.

The following options to the mount command might increase the security of NFS-based clients:

nosuid
Use the nosuid option to disable the set-user-identifier or set-group-identifier bits. This prevents remote users from gaining higher privileges by running a setuid program, and you can use this option in opposition to setuid option.
noexec
Use the noexec option to disable all executable files on the client. Use this to prevent users from accidentally executing files placed in the shared file system.
nodev
Use the nodev option to prevent the client’s processing of device files as a hardware device.
resvport
Use the resvport option to restrict communication to a reserved port, and you can use a privileged source port to communicate with the server. The reserved ports are reserved for privileged users and processes such as the root user.
sec
Use the sec option on the NFS server to choose the RPCGSS security method for accessing files on the mount point. Valid security methods are none, sys, krb5, krb5i, and krb5p.
Important

The MIT Kerberos libraries provided by the krb5-libs package do not support the Data Encryption Standard (DES) algorithm in new deployments. DES is deprecated and disabled by default in Kerberos libraries because of security and compatibility reasons. Use newer and more secure algorithms instead of DES, unless your environment requires DES for compatibility reasons.

8.3.3. Securing NFS with firewall

To secure the firewall on an NFS server, keep only the required ports open. Do not use the NFS connection port numbers for any other service.

Prerequisites

  • The nfs-utils package is installed.
  • The firewalld package is installed and running.

Procedure

  1. Configure static ports for NFS services to simplify firewall rules. The rpcbind service assigns NFS ports dynamically by default. Specify static ports in the /etc/nfs.conf file:

    For NFSv3, configure these services:

    1. Set TCP and UDP port for mountd (rpc.mountd) in the [mountd] section in port=<value> format.
    2. Set TCP and UDP port for statd (rpc.statd) in the [statd] section in port=<value> format.
    3. Set TCP port for the lock manager in the [lockd] section in port=<value> format. Alternatively, use the nlm_tcpport option in the /etc/modprobe.d/lockd.conf file.
    4. Set UDP port for the lock manager in the [lockd] section in udp-port=<value> format. Alternatively, use the nlm_udpport option in the /etc/modprobe.d/lockd.conf file.

    For NFSv4, only port 2049 is required.

  2. Open the required ports in the firewall:

    For NFSv4:

    # firewall-cmd --permanent --add-port=2049/tcp

    For NFSv3, also open the ports you configured in step 1:

    # firewall-cmd --permanent --add-port=2049/tcp
    # firewall-cmd --permanent --add-port=<mountd_port>/tcp
    # firewall-cmd --permanent --add-port=<mountd_port>/udp
    # firewall-cmd --permanent --add-port=<statd_port>/tcp
    # firewall-cmd --permanent --add-port=<statd_port>/udp
    # firewall-cmd --permanent --add-port=<lockd_tcp_port>/tcp
    # firewall-cmd --permanent --add-port=<lockd_udp_port>/udp
  3. Reload the firewall to apply the changes:

    # firewall-cmd --reload

Verification

  1. List the active ports and RPC programs on the NFS server:

    $ rpcinfo -p
  2. Verify the firewall rules:

    # firewall-cmd --list-ports

8.4. Securing the FTP service

You can use the File Transfer Protocol (FTP) to transfer files over a network. Because all FTP transactions with the server, including user authentication, are unencrypted, make sure it is configured securely.

Red Hat Enterprise Linux provides two FTP servers:

Red Hat Content Accelerator (tux)
A kernel-space web server with FTP capabilities.
Very Secure FTP Daemon (vsftpd)
A standalone, security-oriented implementation of the FTP service.

The following security guidelines are for setting up the vsftpd FTP service.

8.4.1. Securing the FTP greeting banner

When a user connects to the FTP service, the server displays a greeting banner that, by default, includes version information. Attackers might use this information to identify vulnerabilities in the system. You can hide this information by changing the default banner.

You can define a custom banner by editing the /etc/banners/ftp.msg file to either directly include a single-line message, or to refer to a separate file, which can contain a multi-line message.

Procedure

  • To define a single line message, add the following option to the /etc/vsftpd/vsftpd.conf file:

    ftpd_banner=Hello, all activity on ftp.example.com is logged.
  • To define a message in a separate file:

    • Create a .msg file which contains the banner message, for example /etc/banners/ftp.msg:

      ######### Hello, all activity on ftp.example.com is logged. #########

      To simplify the management of multiple banners, place all banners into the /etc/banners/ directory.

    • Add the path to the banner file to the banner_file option in the /etc/vsftpd/vsftpd.conf file:

      banner_file=/etc/banners/ftp.msg

Verification

  • Display the modified banner:

    $ ftp localhost
    Trying ::1…
    Connected to localhost (::1).
    Hello, all activity on ftp.example.com is logged.

Configure anonymous FTP access to allow uploads. Prevent read access to increase security.

By default, the vsftpd package creates the /var/ftp/ directory tree. Anonymous users have read-only permissions. Configure a write-only directory where anonymous users can upload files. They cannot read or modify existing content.

Procedure

  1. Create a write-only directory in the /var/ftp/pub/ directory:

    # mkdir /var/ftp/pub/upload
    # chmod 730 /var/ftp/pub/upload
    # ls -ld /var/ftp/pub/upload
    drwx-wx---. 2 root ftp 4096 Nov 14 22:57 /var/ftp/pub/upload
  2. Add the following lines to the /etc/vsftpd/vsftpd.conf file:

    anon_upload_enable=YES
    anonymous_enable=YES
  3. Optional: Enable SELinux boolean attributes allow_ftpd_anon_write and allow_ftpd_full_access if your system has SELinux enabled and enforcing.

    Warning

    Configuring directories for anonymous read and write access increases risk. The server might become a repository for stolen software.

8.4.3. Security tips for FTP user accounts

FTP transmits usernames and passwords unencrypted over insecure networks for authentication. You can improve the security of FTP by denying system users access to the server from their user accounts.

Perform as many of the following configuration steps as applicable for your configuration:

  • Disable all user accounts in the vsftpd server, by adding the following line to the /etc/vsftpd/vsftpd.conf file:

    local_enable=NO
  • Disable FTP access for specific accounts or specific groups of accounts, such as the root user and users with sudo privileges, by adding the usernames to the /etc/pam.d/vsftpd PAM configuration file.
  • Disable user accounts, by adding the usernames to the /etc/vsftpd/ftpusers file.

8.5. Securing HTTP servers

Harden your HTTP servers, such as Apache and Nginx, to mitigate security risks. This involves configuring security options in the main configuration files and checking that scripts run correctly.

8.5.1. Security enhancements in httpd.conf

You can enhance the security of the Apache HTTP server by configuring security options in the /etc/httpd/conf/httpd.conf file.

In the /etc/httpd/conf/httpd.conf file, you can configure the following options:

FollowSymLinks
This directive is enabled by default and follows symbolic links in the directory.
Indexes
This directive is enabled by default. Disable this directive to prevent visitors from browsing files on the server.
UserDir
This directive is disabled by default because it can confirm the presence of a user account on the system. To activate user directory browsing for all user directories other than /root/, use the UserDir enabled and UserDir disabled root directives. To add users to the list of disabled accounts, add a space-delimited list of users on the UserDir disabled line.
ServerTokens

This directive controls the server response header field which is sent back to clients. You can use the following parameters to customize the information:

ServerTokens Full

Provides all available information such as web server version number, server operating system details, installed Apache modules, for example:

Apache/2.4.37 (Red Hat Enterprise Linux) MyMod/1.2
ServerTokens Full-Release

Provides all available information with release versions, for example:

Apache/2.4.37 (Red Hat Enterprise Linux) (Release 41.module+el8.5.0+11772+c8e0c271)
ServerTokens Prod / ServerTokens ProductOnly

Provides the web server name, for example:

Apache
ServerTokens Major

Provides the web server major release version, for example:

Apache/2
ServerTokens Minor

Provides the web server minor release version, for example:

Apache/2.4
ServerTokens Min / ServerTokens Minimal

Provides the web server minimal release version, for example:

Apache/2.4.37
ServerTokens OS

Provides the web server release version and operating system, for example:

Apache/2.4.37 (Red Hat Enterprise Linux)

Use the ServerTokens Prod option to reduce the risk of attackers gaining any valuable information about your system.

Important

Do not remove the IncludesNoExec directive. By default, the Server Side Includes (SSI) module cannot run commands. Changing this can allow an attacker to enter commands on the system.

8.5.1.1. Securing CGI and script directories

Ensure that only the root user has write permissions to directories containing scripts or Common Gateway Interfaces (CGI):

# chown root <directory_name>
# chmod 755 <directory_name>

Always verify that all scripts work correctly before putting them into production.

8.5.1.2. Removing httpd modules

You can remove the httpd modules to limit the functionality of the HTTP server. To do so, edit configuration files in the /etc/httpd/conf.modules.d/ or /etc/httpd/conf.d/ directory. For example, to remove the proxy module:

echo '# All proxy modules disabled' > /etc/httpd/conf.modules.d/00-proxy.conf

8.5.2. Nginx server configuration hardening

Harden your Nginx HTTP and proxy server configuration by adjusting security options. This helps protect your system against common web application vulnerabilities.

Configure the following security options to protect against common web application vulnerabilities:

  • To disable version strings, modify the server_tokens configuration option:

    server_tokens off;

    This option stops displaying additional details such as server version number. This configuration displays only the server name in all requests served by Nginx, for example:

    $ curl -sI http://localhost | grep Server
    Server: nginx
  • Add security headers in your server or location blocks within /etc/nginx/nginx.conf or /etc/nginx/conf.d/*.conf files:

    • For example, the X-Frame-Options header option denies any page outside of your domain to frame any content served by Nginx, mitigating clickjacking attacks:

      add_header X-Frame-Options "SAMEORIGIN";
    • For example, the x-content-type header prevents MIME-type sniffing in certain older browsers:

      add_header X-Content-Type-Options nosniff;
    • For example, the X-XSS-Protection header enables Cross-Site Scripting (XSS) filtering, which prevents browsers from rendering potentially malicious content included in a response by Nginx:

      add_header X-XSS-Protection "1; mode=block";
  • You can limit the services exposed to the public and limit what they do and accept from the visitors, for example:

    limit_except GET {
        allow 192.168.1.0/32;
        deny  all;
    }

    The snippet will limit access to all methods except GET and HEAD.

  • You can disable HTTP methods, for example:

    # Allow GET, PUT, POST; return "405 Method Not Allowed" for all others.
    if ( $request_method !~ ^(GET|PUT|POST)$ ) {
        return 405;
    }
  • Configure TLS to protect data served by your Nginx web server. Serve content over HTTPS only. You can generate a secure configuration profile for enabling TLS in your Nginx server using the Mozilla SSL Configuration Generator. The generated configuration ensures that known vulnerable protocols, ciphers, and hashing algorithms are disabled. Use the SSL Server Test to verify that your configuration meets modern security requirements.

Secure your PostgreSQL database by configuring client authentication. Limit access to authenticated local users only. This reduces unauthorized access and attack risks.

PostgreSQL is an object-relational database management system (DBMS). The postgresql-server package provides PostgreSQL in Red Hat Enterprise Linux.

The pg_hba.conf configuration file specifies client authentication settings. This file is stored in the database cluster’s data directory. Configure PostgreSQL for host-based authentication using this procedure.

Procedure

  1. Install PostgreSQL:

    # dnf install postgresql-server
  2. Initialize a database storage area using one of the following options:

    1. Use the initdb utility:

      $ initdb -D /home/postgresql/db1/

      This directory contains all database data. It also contains the client authentication configuration file.

    2. Use the postgresql-setup script:

      $ postgresql-setup --initdb

      By default, the script uses the /var/lib/pgsql/data/ directory. This script helps with basic database cluster administration.

  3. Configure local authentication in the pg_hba.conf file. By default, the file contains:

    local   all             all                                     trust

    This trust authentication allows any local user to access any database. To require authentication, change trust to another method. Use peer to authenticate based on system username. Use md5 for password authentication:

    local   all             all                                     peer

    You can disable local socket connections entirely. Remove the local line entry if you use layered applications that create database users without corresponding local users.

  4. Restart the database to apply the changes:

    # systemctl restart postgresql

    This command updates the database. It also verifies the syntax of the configuration file.

Verification

  1. Verify the authentication setting in the configuration file:

    $ grep "^local" /var/lib/pgsql/data/pg_hba.conf
    local   all             all                                     peer
  2. Test the authentication by attempting to connect as a local user with a matching database user:

    $ psql -U postgres -d postgres
    psql (16.4)
    Type "help" for help.
    
    postgres=#

    The connection succeeds because the local system user matches the database user.

  3. Test that unauthorized users cannot connect by attempting to connect as a non-existent database user:

    $ psql -U nonexistent -d postgres
    psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  Peer authentication failed for user "nonexistent"

    The connection is rejected because peer authentication requires a matching system user.

8.7. Securing the Memcached service

Secure the Memcached caching service against denial-of-service (DoS) attacks and unauthorized access. Configure it to accept only local traffic. Enable user authentication. This prevents DDoS amplification. Only authorized clients can access stored data.

Memcached is an open source, high-performance, distributed memory object caching system. It improves the performance of dynamic web applications by lowering database load.

Memcached is an in-memory key-value store for small data chunks such as strings and objects. It stores results from database calls, API calls, or page rendering. Memcached assigns memory from underutilized areas to applications that need more memory.

In 2018, DDoS amplification vulnerabilities were discovered in Memcached servers exposed to the public internet. These attacks exploited Memcached communication when using the UDP protocol for transport. The attack was effective due to the high amplification ratio. A request of a few hundred bytes could generate a response of a few megabytes or hundreds of megabytes.

Do not expose the memcached service to the public internet in most situations. Public exposure causes security problems. Remote attackers can leak or modify information stored in Memcached.

8.7.1. Memcached hardening against DDoS attacks

Harden Memcached against distributed denial-of-service (DDoS) attacks to prevent attackers from overwhelming the service.

Perform these steps as applicable to your configuration:

  • Limit access to your local network. Configure your firewall to block external traffic. Remove the default port 11211:

    # firewall-cmd --remove-port=11211/udp
    # firewall-cmd --runtime-to-permanent
  • Limit Memcached to local connections only. Edit the OPTIONS value in /etc/sysconfig/memcached:

    OPTIONS="-l 127.0.0.1,::1"
  • Enable Simple Authentication and Security Layer (SASL) authentication:

    1. Create /etc/sasl2/memcached.conf and set the SASL database path:

      sasldb_path: /path.to/memcached.sasldb
    2. Add an account in the SASL database:

      # saslpasswd2 -a memcached -c cacheuser -f /path.to/memcached.sasldb
    3. Set permissions for the memcached user and group:

      # chown memcached:memcached /path.to/memcached.sasldb
    4. Enable SASL support. Add -S to OPTIONS in /etc/sysconfig/memcached:

      OPTIONS="-S"
    5. Restart Memcached:

      # systemctl restart memcached
    6. Add the SASL username and password to your application’s Memcached client configuration.
  • Encrypt communication between Memcached clients and servers with TLS:

    1. Enable TLS encryption. Add -Z to OPTIONS in /etc/sysconfig/memcached:

      OPTIONS="-Z"
    2. Add the certificate chain file path. Append -o ssl_chain_cert=/path/to/cert.pem to OPTIONS:

      OPTIONS="-Z -o ssl_chain_cert=/path/to/cert.pem"
    3. Add the private key file path. Append -o ssl_key=/path/to/key.pem to OPTIONS:

      OPTIONS="-Z -o ssl_chain_cert=/path/to/cert.pem -o ssl_key=/path/to/key.pem"

8.8. Securing the Postfix service

Secure the Postfix mail transfer agent by configuring it to use encryption and applying settings that mitigate risks from various attacks. This involves configuring SMTP Authentication (AUTH) using SASL and setting limits to reduce vulnerability to denial-of-service (DoS) attacks.

Postfix is a mail transfer agent (MTA) that uses the Simple Mail Transfer Protocol (SMTP) to deliver electronic messages between other MTAs and to email clients or delivery agents. Although MTAs can encrypt traffic between one another, they might not do so by default.

You can limit denial-of-service (DoS) attacks by configuring certain Postfix options. This involves setting strict rate and message-size limits to protect the server from being flooded with traffic.

An attacker can flood the server with traffic or send information that triggers a crash, causing a denial-of-service (DoS) attack. You can configure your system to reduce the risk of such attacks by setting limits in the /etc/postfix/main.cf file. You can change the value of the existing directives, or you can add new directives with custom values in the <directive> = <value> format.

Use the following list of directives for limiting DoS attacks:

smtpd_client_connection_rate_limit
Limits the maximum number of connection attempts any client can make to this service per time unit. The default value is 0, which means a client can make as many connections per time unit as Postfix can accept. By default, the directive excludes clients in trusted networks.
anvil_rate_time_unit
Defines a time unit to calculate the rate limit. The default value is 60 seconds.
smtpd_client_event_limit_exceptions
Excludes clients from the connection and rate limit commands. By default, the directive excludes clients in trusted networks.
smtpd_client_message_rate_limit
Defines the maximum number of message deliveries from client to request per time unit (regardless of whether or not Postfix actually accepts those messages).
default_process_limit
Defines the default maximum number of Postfix child processes that provide a given service. You can ignore this rule for specific services in the master.cf file. By default, the value is 100.
queue_minfree
Defines the minimum amount of free space required to receive mail in the queue file system. The directive is currently used by the Postfix SMTP server to decide if it accepts any mail at all. By default, the Postfix SMTP server rejects MAIL FROM commands when the amount of free space is less than 1.5 times the message_size_limit. To specify a higher minimum free space limit, specify a queue_minfree value that is at least 1.5 times the message_size_limit. By default, the queue_minfree value is 0.
header_size_limit
Defines the maximum amount of memory in bytes for storing a message header. If a header is large, it discards the excess header. By default, the value is 102400 bytes.
message_size_limit
Defines the maximum size of a message, including the envelope information, in bytes. By default, the value is 10240000 bytes.

8.8.3. Configuring Postfix to use SASL

You can configure the Postfix mail transfer agent to use Simple Authentication and Security Layer (SASL). This strengthens authentication when sending and receiving electronic messages.

Postfix supports SASL-based SMTP Authentication (AUTH). SMTP AUTH is an extension of the Simple Mail Transfer Protocol. Currently, the Postfix SMTP server supports the SASL implementations in the following ways:

Dovecot SASL
The Postfix SMTP server can communicate with the Dovecot SASL implementation by using either a UNIX-domain socket or a TCP socket. Use this method if Postfix and Dovecot applications are running on separate machines.
Cyrus SASL
When enabled, SMTP clients must authenticate with the SMTP server by using an authentication method supported and accepted by both the server and the client.

Prerequisites

  • The dovecot package is installed on the system

Procedure

  1. Configure Dovecot:

    1. Include the following lines in the /etc/dovecot/conf.d/10-master.conf file:

      service auth {
        unix_listener /var/spool/postfix/private/auth {
          mode = 0660
          user = postfix
          group = postfix
        }
      }

      The previous example uses UNIX-domain sockets for communication between Postfix and Dovecot. The example also assumes default Postfix SMTP server settings, which include the mail queue located in the /var/spool/postfix/ directory, and the application running under the postfix user and group.

    2. Optional: Configure Dovecot to listen for Postfix authentication requests through TCP:

      service auth {
        inet_listener {
            port = <port_number>
        }
      }
    3. Specify the method that the email client uses to authenticate with Dovecot by editing the auth_mechanisms parameter in /etc/dovecot/conf.d/10-auth.conf file:

      auth_mechanisms = plain login

      The auth_mechanisms parameter supports different plain text and non-plain text authentication methods.

  2. Configure Postfix by modifying the /etc/postfix/main.cf file:

    1. Enable SMTP Authentication on the Postfix SMTP server:

      smtpd_sasl_auth_enable = yes
    2. Enable the use of Dovecot SASL implementation for SMTP Authentication:

      smtpd_sasl_type = dovecot
    3. Provide the authentication path relative to the Postfix queue directory. Note that the use of a relative path ensures that the configuration works regardless of whether the Postfix server runs in chroot or not:

      smtpd_sasl_path = private/auth

      This step uses UNIX-domain sockets for communication between Postfix and Dovecot.

      To configure Postfix to look for Dovecot on a different machine in case you use TCP sockets for communication, use configuration values similar to the following:

      smtpd_sasl_path = inet: <IP_address> : <port_number>

      In the previous example, replace the <IP_address> with the IP address of the Dovecot machine and <port_number> with the port number specified in Dovecot’s /etc/dovecot/conf.d/10-master.conf file.

    4. Specify SASL mechanisms that the Postfix SMTP server makes available to clients. Note that you can specify different mechanisms for encrypted and unencrypted sessions.

      smtpd_sasl_security_options = noanonymous, noplaintext
      smtpd_sasl_tls_security_options = noanonymous

      The previous directives specify that during unencrypted sessions, no anonymous authentication is allowed, and no mechanisms that transmit unencrypted user names or passwords are allowed. For encrypted sessions that use TLS, only non-anonymous authentication mechanisms are allowed.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top