how to open port 80 in linux iptables

Here we have linux tutorial for, how to open port 80 in linux iptables. Many times we need to open 80 port on linux box. Through command line opening the 80 or any port that is easy. In this tutorial I will how you can open the port 80.

how to open port 80 in linux iptables

how to open port 80 in linux iptables
how to open port 80 in linux iptables

Using following you can check the firewall setting of Linux.


[root@sonyk-pc project]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:domain
ACCEPT     udp  --  anywhere             anywhere            udp dpt:bootps
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:bootps
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:domain
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http state NEW
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:vnc-server
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:vnc-server
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:patrol-snmp state NEW
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:61613 state NEW
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             192.168.122.0/24    state RELATED,ESTABLISHED
ACCEPT     all  --  192.168.122.0/24     anywhere
ACCEPT     all  --  anywhere             anywhere
REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable
REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Using following command you can open the port 80. using following command use 80 port will be open for 192.168.2.0 to 192.168.2.68 ip addresses.


[root@sonyk-pc project]# iptables -A INPUT -s 192.168.2.0/68 -d 192.168.2.16 -p tcp --dport 80 -j ACCEPT

using following command you can save the setting in iptables.


[root@sonyk-pc project]# restorecon -R /etc/sysconfig/iptables

[root@sonyk-pc project]# service iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

Than restart the firewall using following command

[root@sonyk-pc project]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: nat mangle filte[  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules: Using intrapositioned negation (`--option ! this`) is deprecated in favor of extrapositioned (`! --option this`).
Using intrapositioned negation (`--option ! this`) is deprecated in favor of extrapositioned (`! --option this`).
 [  OK  ]