Linux Firewall Open specific ports (iptables)

Source: Internet
Author: User

Iptables is a firewall under Linux and is also the service name.


Service iptables Status View firewall state

Service iptables start to turn on the firewall

Service iptables Stop shutting down the firewall

Service iptables Restart Restart firewall


Firewalls Open specific ports:

① file/etc/sysconfig/iptables

② Add:

-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 8080-j ACCEPT

★ The number 8080 for open 8080 port, can also be changed to other ports ★

③ Restart the firewall


================================================================


Save settings for the firewall

Serivce iptables Save


View Iptables rules and numbers

IPTABLES-NL--line-number


Turn off all input FORWARD (forwards) output for all ports

Iptables-p INPUT DROP

Iptables-p FORWARD DROP

Iptables-p OUTPUT DROP




Open only 22 ports

Iptables-a input-p TCP--dport 22-j ACCEPT

Iptables-a output-p TCP--sport 22-j ACCEPT


Parameter explanation:

The –A parameter is seen as adding a rule

–P specifies what protocol we commonly use for the TCP protocol, and of course there are UDP, such as 53-port DNS

–dport is the destination port, when the data goes from outside to the server as the destination port

–sport data goes out of the server, it is used for the data source port

–J is designated as Accept-receive or DROP not receive


Disable an IP access

Iptables-a input-p tcp-s 192.168.1.2-j DROP

–s parameter is source (i.e. 192.168.1.2)

The back rejection is drop.



Delete Rule

Iptables-d INPUT 2

Delete the input chain number 2 rule


This article is from "_xiaohan" blog, please make sure to keep this source http://yingmeng.blog.51cto.com/5365464/1588697

Linux Firewall Open specific ports (iptables)

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.