Use iptables to count traffic

Source: Internet
Author: User

Use iptables to count traffic

# Add inbound/outbound iptables rules

1. $ iptables-I INPUT-d 192.168.1.100

2. $ iptables-I OUTPUT-s 192.168.1.100

# View traffic

1. $ iptables-nvx-L

# Clearing rules

1. $ iptables-F

1. $ iptables-I FORWARD-s 192.168.1.100-j ACCEPT

2. $ iptables-I FORWARD-d 192.168.1.100-j ACCEPT

1. $ sudo iptables-t filter-a input-p all-s 174.121.79.132-j ACCEPT

2. $ sudo iptables-t filter-a output-p all-d 174.121.79.132-j ACCEPT

How to delete a rule

Method 1 Syntax:

Iptables-D chain rulenum [options]

Here, chain indicates the chain, that is, input forward, and so on. rulenum indicates the rule number. From 1, you can use -- line-numbers to list the rule numbers. For example, to list all the rules of the INPUT chain:

1. $ iptables-l input -- line-numbers

2.

3. num target prot opt source destination

4. 1 REJECT tcp -- anywhere tcp dpt: microsoft-ds reject-with icmp-port-unreachable

5. 2 REJECT tcp -- anywhere tcp dpt: 135 reject-with icmp-port-unreachable

6. 3 REJECT tcp -- anywhere tcp dpt: netbios-ssn reject-with icmp-port-unreachable

7. 4 REJECT udp -- anywhere udp dpt: microsoft-ds reject-with icmp-port-unreachable

8. 5 REJECT udp -- anywhere udp dpt: 135 reject-with icmp-port-unreachabl

Delete a specified row rule:

1. $ iptables-d input 4

If you want to delete multiple rules consecutively, remember to delete the NUM number from large to small because the row number changes after each deleted entry. It is safe to delete a row and confirm the row number by iptables-L.

Method 2:-A command ing, replace-A with-D. This is useful when the rules in your chain are complex and you do not want to calculate their numbers. That is to say, if you define A rule using the iptables-A... statement, replace-A with-D When deleting the rule, and the rest will remain unchanged.

For more iptables tutorials, see the following:

Disable the default firewall in CentOS 7.0 and enable the iptables firewall.

Iptables examples

Linux Firewall iptables

Basic use of iptables backup, recovery, and firewall scripts

Detailed description of firewall iptables usage rules in Linux

Iptables firewall settings in Linux

This article permanently updates the link address:

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.