November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

CentOS / RHEL 7 : How to open a port in the firewall with firewall-cmd?

Question: How to open a port in RHEL 7 using the firewall-cmd command?

Solution:

To begin with check the firewalld status using the systemctl command :

# systemctl status firewalld
? firewalld.service – firewalld – dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2016-10-29 21:47:04 IST; 1 weeks 4 days ago
Main PID: 1055 (firewalld)
CGroup: /system.slice/firewalld.service
??1055 /usr/bin/python -Es /usr/sbin/firewalld –nofork –nopid

Oct 29 21:46:50 localhost.localdomain systemd[1]: Starting firewalld – dynamic firewall daemon…
Oct 29 21:47:04 localhost.localdomain systemd[1]: Started firewalld – dynamic firewall daemon.
Execute these commands to add a port to the firewall:
The command below will open the port effective immediately, but will not persist across reboots:

# firewall-cmd –add-port=[YOUR PORT]/tcp
For example, to open TCP port 2222 :

# firewall-cmd –add-port=2222/tcp
The following command will create a persistent rule, but will not be put into effect immediately:

# firewall-cmd –permanent –add-port=[YOUR PORT]/tcp
For Example, to open TCP port 2222 :

# firewall-cmd –permanent –add-port=2222/tcp

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>