Linux practical iptables block ip address some common commands: block a single IP address command is: iptables-IINPUT-s211.1.0.0-jDROP block IP address command is: iptables-IINPUT-s211.1.0.0/16-jDROPiptables-IINPUT-s211.2.0.0/16-jDROPiptables-II
Practical in linuxIptablesSome common commands for sealing ip segments:
The command to block a single IP address is:
Iptables-I INPUT-s 211.1.0.0-j DROP
The command to block IP segments is:
Iptables-I INPUT-s 211.1.0.0/16-j DROP
Iptables-I INPUT-s 211.2.0.0/16-j DROP
Iptables-I INPUT-s 211.3.0.0/16-j DROP
The command to block the entire segment is:
Iptables-I INPUT-s 211.0.0.0/8-j DROP
The command for sealing several segments is:
Iptables-I INPUT-s 61.37.80.0/24-j DROP
Iptables-I INPUT-s 61.37.81.0/24-j DROP
There are three methods to start self-running on the server:
1. add it to/etc/rc. local.
2. iptables-save>;/etc/sysconfig/iptables can put your current iptables rules into/etc/sysconfig/iptables, which is automatically executed when the system starts iptables.
3. service iptables save can also put your current iptables rules in/etc/sysconfig/iptables. The system automatically runs iptables when it starts.
The last two are better. Generally, the iptables service is enabled before the network service, which is safer.
To unseal:
Iptables-d input 3 means to delete 3rd rules.
Iptables-d input-s IP address-j REJECT
Iptables-F cleared
-A: Adds A rule to the last row;
-I: add the first rule;
INPUT: the packet is the direction of the INPUT host;
OUTPUT: the direction of the OUTPUT host;
FORWARD: The direction in which packets are transmitted outside the host;
-I: inbound Nic interface
-O: outbound Nic interface
Interface: network card interface, such as ppp0, eth0, eth1 ....
-P: Please note that this is in lower case! Packet protocol!
TCP: a TCP packet;
UDP: UDP packets;
-S: the IP address or Network (domain) of the source packet );
-- Sport: port number of the source packet;
-D: IP address or Network (domain) of the target host );
-- Dport: the port number of the target host;
-J: action. you can perform the following actions;
ACCEPT: ACCEPT this packet
DROP: discard packets