iptables的常用参数使用

0 30
       Common parameters of iptables usageiptables The main function is to contr...

       Common parameters of iptables usageiptables

 The main function is to control the entry and exit of network packets on the device and forwarding. When packets need to enter the device, leave the device, or be forwarded and routed by the device, they can be controlled by iptables.Install iptables

iptables的常用参数使用

#yum install iptables-services

Image.png0x02:Turn off firewall

#systemctl stopfirewalld.service

Image.png#systemctl disablefirewalld.service

Image.png0x03:View the existing iptables rules

#iptables -L

Image.png0x04:Clear all default rules

#iptables -F

Image.pngClear all custom rules

#iptables -X

Image.pngReset all counters

#iptables -Z

Image.png0x05:Allow local access to packets from the lo interface

#iptables -A INPUT -I lo -jACCEPT

Image.png0x06:Specify the opening of port 22

#iptables -A INPUT -p tcp–dport 22 -j ACCEPT

Image.png0x07:Ban access from IP address 123.23.1.2

#iptables -A INPUT -p tcp-dport 22 -j DROP

Image.png0x08:Open fixed IP access to port 8080

#iptables -I INPUT -s111.101.90.110 -p tcp –dport 8080 -j ACCEPT

Image.png0x08:Ban ping

#iptables -A INPUT -p icmp--icmp-type 8 -s 0/0 -j DROP

Image.png0x09:Add the internal IP address to the trusted list

#iptables -A INPUT -p tcp -s10.0.0.3 -j ACCEPT

Image.png0x10:Allow receiving return data RELATED after accepting requests from the local machine

#iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

Image.png0x11:Limit traffic

#iptables -A INPUT -I eth0 -m limit --limit 5/m --limit-burst 15 -j ACCEPT

Image.png0x12:Match within specific time periods

#iptables -A INPUT -i eth0 -m time --weekdays 1,3,5 -j ACCEPT

Image.png0x13:Match packets with TTL values that meet the rules

#iptables -A OUTPUT -m ttl --ttl-eq 51 -j ACCEPT

Image.png0x14:Match packets with the specified state

#iptables -A INPUT -m state --stateNEW,ESTABLISHED -j ACCEPT

Image.png0x15:Match packets with the specified mark value

#iptables -t mangle -A INPUT -m mark --mark 1 -j DROP

Image.png0x16:Match the specified MAC address

#iptables -A FORWARD -m mac --mac-source00:0C:22:38:49:61 -j DROP

Image.png0x17:Port mapping (map the default mysql port 3306 to 1306 for external service)

#iptables -t mangle -IPREROUTING -p tcp -dport 1306 -j MARK --set-mark 3306

Image.png0x18:Filter all requests that are not above the rules

#iptables -P INPUT DROP

Image.png0x19:Save iptables rules

#service iptables save

Image.png0x20:Automatically enable iptables service

#systemctl enableiptables.service

Image.png0x21:Check status

#systemctl status iptables.service

Image.png      Summary: The function of iptables is very powerful. Familiar with commonly used parameter combinations, it can meet the protection needs of different scenarios. Understanding the structure of iptables can better use firewall rules to control incoming and outgoing traffic and speed limit processing.

你可能想看:
最后修改时间:
admin
上一篇 2025年03月30日 13:22
下一篇 2025年03月30日 13:45

评论已关闭