linux firewall command example

you can use linux firewall to open a port.
Linux operating systems using firewall utility ‘Iptables’ service is built for Linux operating systems(centos 5.x ~ 6.x).
In Centos 7.x, The default firewall system has changed.
CentOS 7, a firewall system called ‘firewalld’ was installed by default.

[example - iptables command for centos5.x ~ 6.x.    as root user]
1) iptables configuration for mariadb or mysql 

    iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT 
    service iptables save
    service iptables restart

2) iptables configuration for apatch http 

    iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT 
    service iptables save 
    service iptables restart 

[example - firewalld command for centos7.x]
1) stop firewalld 

    systemctl stop firewalld

2) prevent the firewall from running when rebooting 

    systemctl disable firewalld

3) open ports 

    firewall-cmd --zone=public --add-port=3306/tcp --permanent 
    firewall-cmd --zone=public --add-port=80/tcp --permanent 
    firewall-cmd --reload 

4) check list of opened ports 

    firewall-cmd --list-ports