How to enable or disable a specified port through iptables firewall in Linux

Source: Internet
Author: User

Generally, iptables is included in the Linux release.
Run iptables -- version to check whether iptables is installed.

Start iptables:
Service iptables start

View the iptables rule set:
Iptables -- list

The following figure shows the iptables when no planning is defined:
Chain input (Policy accept)
Target prot opt source destination
Chain forward (Policy accept)
Target prot opt source destination
Chain output (Policy accept)
Target prot opt source destination

How to enable/disable a specified port, for example:
Enable port 81:
Iptables-I input-I eth0-P TCP -- dport 81-J accept
Iptables-I output-O eth0-P TCP -- Sport 81-J accept
Close port 81:
Iptables-I input-I eth0-P TCP -- dport 81-J Drop
Iptables-I output-O eth0-P TCP -- Sport 81-J Drop
Then save:
/Etc/rc. d/init. d/iptables save

Restart Firewall:

Service iptables restart

View port status:

Service iptables status

You can use the lsof command to check whether a port is open. Check whether the port can be used in this way.
Take port 81 as an example:
Lsof-I: 81
If there is a display description, it is already open. If there is no display description, it is not open.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.