• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How To Open A Port In CentOS / RHEL 7

by admin

A TCP/IP network connection may be either blocked, dropped, open, or filtered. These actions are generally controlled by the IPtables firewall the system uses and is independent of any process or program that may be listening on a network port. This post will outline the steps to open a port required by a application. For this post example, we will be opening Application Specific (Apache) Port 55555.

Server details are as below:

# uname -a
Linux geeklab 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)

1. Check Port Status

Check that the port is not open and Apache is not showing that port:

# netstat -na | grep 55555
# lsof -i -P |grep http
httpd     5823   root    4u  IPv6  42212      0t0  TCP *:80 (LISTEN)

2. Check Port Status in iptables

Check that iptables are not showing that port open:

# iptables-save | grep 55555

3. Add the port

Add the test port in /etc/services file and allow the port to accept packets. Test port can be added by editing /etc/services file in below format:

# vi /etc/services
service-name  port/protocol  [aliases ...]   [# comment]
# vi /etc/services
testport        55555/tcp   # Application Name

4. Open firewall ports

Add Firewall rule to allow the port to accept packets:

# firewall-cmd --zone=public --add-port=55555/tcp --permanent
success
# firewall-cmd --reload
success
# iptables-save | grep 55555
-A IN_public_allow -p tcp -m tcp --dport 55555 -m conntrack --ctstate NEW -j ACCEPT

5. Check newly added port status

After adding the port for httpd and reloading httpd services, notice now httpd is also listening to newly added port 55555:

# lsof -i -P |grep http
httpd     6595   root    4u  IPv6  43709      0t0  TCP *:80 (LISTEN)
httpd     6595   root    6u  IPv6  43713      0t0  TCP *:55555 (LISTEN)
# netstat -na |grep 55555
tcp6       0      0 :::55555                :::*                    LISTEN
CentOS / RHEL : How to find if a network port is open or not?
CentOS / RHEL 7 : How to open a port in the firewall with firewall-cmd?

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. How to (Correctly) Change the UID and GID of a user/group in Linux
  2. acountry Command Examples in Linux
  3. dumpe2fs Command Examples in Linux
  4. CentOS / RHEL 5 : How to use the faillog command to track failed login attempts
  5. How to configure CentOS/RHEL 6 system to not used last 3 passwords used
  6. How to create a Python Dictionary
  7. CentOS / RHEL 7 : How to set udev rules for ASM on multipath disks
  8. ioping: command not found
  9. latte-dock Command Examples in Linux
  10. gradle: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • ncat Command Examples in Linux
  • ncat: command not found
  • nautilus Command Examples in Linux
  • namei: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright