iptables configuration example

Edit rules vi /etc/sysconfig/iptables
*filter
-P INPUT DROP
-P OUTPUT ACCEPT

-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -s 112.28.32.2 -j ACCEPT
-A INPUT -s 221.130.130.0/24 -j ACCEPT

COMMIT

Restart the firewall service iptables restart

to check the effect of the rules iptables -L -v

Explanation:
-P INPUT DROP All inbound requests outside the rules are discarded.
-P OUTPUT ACCEPT Unlimited outbound requests
-A INPUT -i lo -j ACCEPT Allow all local loopback requests
-A INPUT -p icmp -j ACCEPT Enable icmp requests such as ping, which can be disabled according to the situation.
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT maintain existing connections and dependent connections, must have this bottom line
-A INPUT -p tcp --dport 80 -j ACCEPT Allow all TCP/80 requests
-A INPUT -s 112.28.32.2 -j ACCEPT Allow all requests of the specified IP
-A INPUT -s 221.130.130.0/24 -j ACCEPT Allow all requests of the specified IP segment


[Port forwarding]
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
service iptables save
service iptables restart

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326278984&siteId=291194637