In Linux, the iptables firewall releases the port to reject the port and view the opened port.

Source: Internet
Author: User

In Linux, the iptables firewall releases the port to reject the port and view the opened port.

I use fedora 14.

1. view the port enabled by iptables firewall:/etc/init. d/iptables status

[Root @ hzswtb2-mpc ~] #/Etc/rc. d/init. d/iptables status or service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
Num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 3306

Chain FORWARD (policy ACCEPT)
Num target prot opt source destination

Chain OUTPUT (policy ACCEPT)
Num target prot opt source destination

 

2. Enable tcp port 8080

/Sbin/iptables-I INPUT-p tcp -- dport 8080-j ACCEPT

/Etc/rc. d/init. d/iptables save or service iptables save # save the configuration/etc/rc. d/init. d/iptables restart or service iptables restart # restart the service

[Root @ hzswtb2-mpc ~] #/Sbin/iptables-I INPUT-p tcp -- dport 8080-j ACCEPT
[Root @ hzswtb2-mpc ~] #/Etc/rc. d/init. d/iptables save
Iptables: Saving firewall rules to/etc/sysconfig/iptables: [OK]
[Root @ hzswtb2-mpc ~] #/Etc/rc. d/init. d/iptables restart
Iptables: Flushing firewall rules: [OK]
Iptables: Setting chains to policy ACCEPT: filter [OK]
Iptables: Unloading modules: [OK]
Iptables: Applying firewall rules: [OK]

[Root @ hzswtb2-mpc ~] # Service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
Num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 8080
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 3306

3. Delete chain INPUT and specify Rule 1;

[Root @ hzswtb2-mpc ~] # Iptables-d input 1
[Root @ hzswtb2-mpc ~] # Service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
Num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 3306

Chain FORWARD (policy ACCEPT)
Num target prot opt source destination

Chain OUTPUT (policy ACCEPT)
Num target prot opt source destination

4. Reject specifies the port;

[Root @ hzswtb2-mpc ~] #/Sbin/iptables-I INPUT-p tcp -- dport 8080-j REJECT
[Root @ hzswtb2-mpc ~] # Service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
Num target prot opt source destination
1 REJECT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 8080 reject-with icmp-port-unreachable
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 3306

Chain FORWARD (policy ACCEPT)
Num target prot opt source destination

Chain OUTPUT (policy ACCEPT)
Num target prot opt source destination

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.