Using iptables in CentOS

Source: Internet
Author: User
Run the following command to generate the/etc/sysconfig/iptables list [root @ centos ~] #/Etc/init. d/iptablesrestart after this operation is completed, the system will automatically generate a ChainRH-Firewall-1-INPUT linked list, but the system default INPUT, OUTPUT, FORWARD linked list is ACCEPT, you need

Run the following command to generate/etc/sysconfig/IptablesColumn table

[Root @Centos~] #/Etc/init. d/iptables restart

After this operation is complete, the system will automatically generate a Chain RH-Firewall-1-INPUT linked list

However, the system's default INPUT, OUTPUT, and FORWARD linked lists are all ACCEPT. you need to DROP the INPUT chain

The command is as follows:

[Root @ centos ~] # Iptables-P INPUT DROP

Then save the rule.

[Root @ centos ~] # Service iptables save

[Root @ centos ~] # Vim/etc/sysconfig/iptables

# Firewall configuration written bysystem-config-securitylevel

# Manual customization of this file is not recommended.

* Filter

: Input accept [0: 0]

: Forward accept [0: 0]

: Output accept [0: 0]

: RH-Firewall-1-INPUT-[0: 0]

-A input-j RH-Firewall-1-INPUT

-A forward-j RH-Firewall-1-INPUT

-A RH-Firewall-1-INPUT-I lo-j ACCEPT

-A RH-Firewall-1-INPUT-p icmp -- icmp-type any-j ACCEPT

-An RH-Firewall-1-INPUT-p 50-j ACCEPT

-An RH-Firewall-1-INPUT-p 51-j ACCEPT

-A RH-Firewall-1-INPUT-p udp -- dport 5353-d 224.0.0.20.- jACCEPT

-A RH-Firewall-1-INPUT-p udp-m udp -- dport 631-j ACCEPT

-A RH-Firewall-1-INPUT-p tcp-m tcp -- dport 631-j ACCEPT

-A RH-Firewall-1-INPUT-m state -- state ESTABLISHED, RELATED-jACCEPT

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 21-j ACCEPT

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT

-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 443-j ACCEPT

-A RH-Firewall-1-INPUT-j REJECT -- reject-withicmp-host-prohibited

COMMIT

Edit/etc/sysconfig/iptables

Add one row

-A RH-Firewall-1-INPUT-s 10.200.1.222-m state -- state NEW-mtcp-p tcp -- dport 22-j ACCEPT

This command restricts ssh access and only allows access to 10.200.1.222

Restart/etc/init. d/iptables after modification.

[Root @ centos ~] # Iptables-nL

Chain INPUT (policy ACCEPT)

Target prot optsource destination

RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0

Chain FORWARD (policy ACCEPT)

Target prot optsource destination

RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0

Chain OUTPUT (policy ACCEPT)

Target prot optsource destination

Chain RH-Firewall-1-INPUT (2 references)

Target prot optsource destination

ACCEPT all -- 0.0.0.0/0 0.0.0.0/0

ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmp type 255

ACCEPT esp -- 0.0.0.0/0 0.0.0.0/0

ACCEPT ah -- 0.0.0.0/0 0.0.0.0/0

ACCEPT udp -- 0.0.0.0/0 224.0.0.20.udpdpt: 5353

ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 uddpt: 631

ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 631

ACCEPT all -- 0.0.0.0/0 0.0.0.0/0

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.