Sunday, November 26, 2023

Saturday, November 25, 2023

How to open SSH port 22

 

https://linuxconfig.org/how-to-open-ssh-port-22-on-rehdat-7-linux-server

How to open SSH port 22 on Rehdat 7 Linux server

The SSH protocol operates on port 22 by default. In order to accept incoming connections on your Red Hat 7 Linux SSH server, you will need to ensure that port 22 is allowed through the firewall. This will involve opening the port in firewalld, the default firewall interface for Red Hat.

In this tutorial, you will learn how to open SSH port 22 on Red Hat Enterprise Linux version 7. The only prerequisite is that you must already have SSH installed.

In this tutorial you will learn:

  • How to open SSH port 22 on RHEL 7
  • How to view configured firewall rules in firewalld and iptables
Opening SSH port 22 on Red Hat 7 Linux
Opening SSH port 22 on Red Hat 7 Linux
Software Requirements and Linux Command Line Conventions
CategoryRequirements, Conventions or Software Version Used
SystemRed Hat 7 Linux
SoftwareOpenSSH
OtherPrivileged access to your Linux system as root or via the sudo command.
Conventions# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to open SSH port 22 on Red Hat 7 step by step instructions



  1. Start by opening a open a command line terminal. Then, execute the following command to open SSH port 22 on your Red Hat 7 Linux server:
    # firewall-cmd --zone=public --permanent --add-service=ssh
    
  2. To apply your new firewall settings you need to reload firewalld:
    # firewall-cmd --reload
    
  3. You can verify the new change by listing all configured rules for firewalld:
    # firewall-cmd --list-all
    

    Alternatively check the iptables rules directly:

    # iptables-save | grep dport\ 22
    
  4. In case you need to remove this rule later, thus closing SSH port 22 again:
    # firewall-cmd --zone=public --remove-service=ssh --permanent
    # firewall-cmd --reload
    

Open port in rhel7

 https://linuxconfig.org/how-to-open-http-port-80-on-redhat-7-linux-using-firewall-cmd


Open port 80 on RHEL

By default, the port 80 for http connection is filtered on Redhat 7 and 8 as you can only access this port from the actual localhost and not from any other public host. To open a port 80 on RHEL 7 and 8 Linux we need to add an iptables rule. For this RHEL uses firewall-cmd.

  1. First add your port 80 rule with the following linux command:
    # firewall-cmd --zone=public --add-port=80/tcp --permanent
    
  2. Once you add the above firewall rule, reload the firewall service with this command:
    # firewall-cmd --reload
    
  3. And check whether the port was added to iptables rule:
    # iptables-save | grep 80
    -A IN_public_allow -p tcp -m tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT
    
  4. If you decide to block/remove http port 80 firewall rule you can again use the firewall-cmd command:
    # iptables-save | grep 80
    -A IN_public_allow -p tcp -m tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT
    # firewall-cmd --zone=public --remove-port=80/tcp --permanent
    success
    # firewall-cmd --reload
    success
    # iptables-save | grep 80