Skip to content

Instantly share code, notes, and snippets.

@reanim8ed
Last active March 27, 2022 19:01
Show Gist options
  • Save reanim8ed/41a7d1e5c8e3be5f9fe439683637d9d5 to your computer and use it in GitHub Desktop.
Save reanim8ed/41a7d1e5c8e3be5f9fe439683637d9d5 to your computer and use it in GitHub Desktop.
[DirectAdmin - Only allow access for specific IPs] #directAdmin #linux

Only allow DirectAdmin access for specific IPs

Our VPSs with DirectAdmin use 'firewalld' as a firewall by default. In firewalld, you can choose to allow only specific IPs to connect to port 2222. Port 2222 is the port you connect to in order to log in to DirectAdmin.

  • First close port 2222 with the command below (i.e. in reality remove port 2222 from the list of open ports):
firewall-cmd --permanent --zone=public --remove-port=2222/tcp
  • With the commands below, you create an exception for your own IP address so that only your own IP can connect to port 2222.
firewall-cmd --permanent --zone=public --add-rich-rule='
rule family="ipv4" 
source address="1.2.3.4" 
port protocol="tcp" port="2222" accept'

Replace 1.2.3.4 with your actual IP address. You can repeat these steps to give access to more IPs.

  • Reload firewalld to process the changes:
firewall-cmd --reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment