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.

01[root@sonyk-pc project]# iptables -L
02Chain INPUT (policy ACCEPT)
03target     prot opt source               destination
04ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
05ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:domain
06ACCEPT     udp  --  anywhere             anywhere            udp dpt:bootps
07ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:bootps
08ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
09ACCEPT     icmp --  anywhere             anywhere
10ACCEPT     all  --  anywhere             anywhere
11ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:domain
12ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:domain
13ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
14ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http state NEW
15ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:vnc-server
16ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:vnc-server
17ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:patrol-snmp state NEW
18ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:61613 state NEW
19REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
20 
21Chain FORWARD (policy ACCEPT)
22target     prot opt source               destination
23ACCEPT     all  --  anywhere             192.168.122.0/24    state RELATED,ESTABLISHED
24ACCEPT     all  --  192.168.122.0/24     anywhere
25ACCEPT     all  --  anywhere             anywhere
26REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable
27REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable
28REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited
29 
30Chain OUTPUT (policy ACCEPT)
31target     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.

1[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.

1[root@sonyk-pc project]# restorecon -R /etc/sysconfig/iptables
2 
3[root@sonyk-pc project]# service iptables save
4 
5iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

Than restart the firewall using following command

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