Iptables firewall command

Source: Internet
Author: User
1. define the default policy iptables [-tnat]-P [INPUT, OUTPUT, FORWARD, PREROUTING, OUTPUT, POSTROUTING] [ACCEPT, DROP]-P: defines the default policy. ACCEPT, DROP: ACCEPT or discard. -t: specifies the defined type. the default value is the filter table.-tnat indicates that the nat table is defined. INPU

1. define preset policies

Iptables[-T nat]-P [INPUT, OUTPUT, FORWARD, PREROUTING, OUTPUT, POSTROUTING] [ACCEPT, DROP]

-P: defines the preset policy.

ACCEPT, DROP: ACCEPT or discard.

-T: specifies the defined type. the default value is the filter table.-tnat indicates that the nat table is defined.

INPUT, OUTPUT, FORWARD: chain in the filter table.

PREROUTING, OUTPUT, and POSTROUTING: links in the nat table.

2. restrict ip addresses and protocols

Iptables [-AI chain] [-io Nic] [-p protocol] [-s source ip address/domain] [-- sport port range] [-d Target ip address/domain] [-- dport range]-j [ACCEPT, DROP]

A: add A policy at the end.

I: Insert the policy to the first entry.

I: the network card that receives the datagram.

O: The Nic that sends the datagram.

P: specifies the protocol used. tcp, udp, icmp, all.

S: the source of the Datagram, IP: 192.168.1.1 or domain: 192.168.1.0/24

Sport: The range of the source port of the datagram. specifying indicates starting from 1 to 1023.

D: target of the Datagram, IP: 192.168.1.1 or domain: 192.168.1.0/24

Dport: the range of the destination port of the datagram. specify to indicate the range from 1 to 1023.

J: specifies the action that occurs when the condition is met. the main actions include ACCEPT, DROP, and LOG.

For example, iptables-a input-I eth0-p tcp-s192.168.1.0/24-d 192.168.1.1

-- Dport 53-j DROP // refuse to provide dns Service to 192.168.1.0/24

3. set the datagram status

Iptables-a input-m state -- state-j [ACCEPT, DROP, LOG]

-- State: the status of the received datagram:

INVALID: INVALID Datagram

ESTABLISHED: connection ESTABLISHED successfully

NEW: request to establish a connection

RELATED: indicates that the datagram is RELATED to the outbound datagram.

Example:

Iptables-a input-m state -- stateRELATED, ESTABLISHED-j ACCEPT // ACCEPT the datagram states as RELATED and ESTABLISHED datagram.

4. set the MAC address

Iptables-a input-m mac -- mac-sourceaa: bb: cc: dd: ee: ff-j [ACCEPT, DROP, LOG]

5. restrict icmp

Iptables-a input-p icmp -- icmp-type-j [ACCEPT, DROP, LOG]

6. backup and recovery settings

Iptables-save> bkfile

Iptables-restore

7. View existing firewall settings

Iptables [-t tables]-L-nv

T: Used to specify the table. if not specified, the default value is filter.

-L: display the current table settings

-N: do not reverse resolve the IP address to the host name

-V: list the number of passed data packets

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.