Iptables-AINPUT-ptcp -- dport22-jACCEPT02 # Allow packets from port 22 to enter 03iptables-AINPUT-ptcp -- dport22-jACCEPT04 # Allow packets from port 22 to return 05iptables-AOUTPUT-ptcp -- sport22-mstate -- stateESTABLISH
Iptables-A input-p tcp -- dport 22-j ACCEPT
| 02 |
# Allow package entry from port 22 |
| 03 |
Iptables-a input-p tcp -- dport 22-j ACCEPT |
| 04 |
# Return of packets allowed to enter from port 22 |
| 05 |
Iptables-a output-p tcp -- sport 22-m state -- stateESTABLISHED-j ACCEPT |
| 06 |
Iptables-a output-p udp -- dport 53-j ACCEPT |
| 07 |
Iptables-a input-p udp -- sport 53-j ACCEPT |
| 08 |
# Allow local access to the local machine |
| 09 |
Iptables-a input-s 127.0.0.1-d 127.0.0.1-j ACCEPT |
| 10 |
Iptables-a output-s 127.0.0.1-d 127.0.0.1-j ACCEPT |
| 11 |
# Allow all IP addresses to access port 80 |
| 12 |
Iptables-a input-p TCP/IP 0/0 -- dport 80-j ACCEPT |
| 13 |
Iptables-a output-p tcp -- sport 80-m state -- stateESTABLISHED-j ACCEPT |
| 15 |
Iptables-save>/etc/sysconfig/iptables |
Service iptables restart
1) takes effect after restart
Enable: chkconfig iptableson
Close: chkconfig iptablesoff
2) takes effect immediately and becomes invalid after restart
Enable: service iptablesstart
Disable: service iptablesstop
You can use the preceding command to enable or disable other services in Linux.
When the firewall is enabled, make the following settings to enable the relevant Port, modify the/etc/sysconfig/iptables file, and add the following content:
-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT
-A RH-Firewall-1-INPUT-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT
Open Terminal
Cd/java/tomcat
# Execution
Bin/startup. sh # start tomcat
Bin/shutdown. sh # Stop tomcat
Tail-f logs/catalina. out # View tomcat console output;
# Check whether tomcat is running
Ps-ef | grep tomcat
# If yes, use kill;
Kill-9 pid # pid is the corresponding process number
For example, the ps-ef | grep tomcat output is as follows:
------------------
Input => filter # the destination ip address is the local data packet
Forward => filter # data packets passing through the local machine
Prerouting => nat # Modify the destination address (DNAT)
Postrouting => nat # modify the source address (SNAT)
Iptables-t table operation command to be operated the chain rule number matching condition-j matched to a later command
Iptables-I INPUT-j DROP #-t: filter by default
Iptables-I INPUT 3-j DROP # insert a rule in the link (insert the third rule)
Iptables-d input 3 # delete by number matching
Iptables-d input-s 192.168.0.1-j DROP # delete by content matching
Iptables-r input 3-j ACCEPT # Change the original 3 rule to-jACCEPT
Iptables-p input drop # set default rules
Iptables-FINPUT # clear all rules in the INPUT chain of the filter table
Iptables-t nat-F PREROUTING
Iptables-t nat vxnL PREROUTING
-- # V: Display details
-- # X: disable automatic unit conversion based on v
-- # N: only the IP address and port number are displayed, and the domain name and service name are not displayed.
========= Matching condition
-I-ieth0 # inbound interface (whether to access eth0 from the network port)
-O # outbound interface
-S 192.168.1.0/24 # Source Address
-D # destination address
-P icmp -- icmp-type # protocol type
-- Sport 1000:3000 # Source port
-- Dport 1000: 3000 # destination port 1000 :( Port 1000 or above): 3000 (port 3000 or below)
-S 192.168.0.1 -dwww.sina.com-p tcp-dport 80
======================================
Iptables-a input-j ACCEPT # Allow all packets that access the local IP address to pass through
Iptables-a forward-s 192.168.0.1-jDROP # Block packets whose source address is 192.168.80.39 from the local machine
-JDNAT # destination address Conversion. DNAT can be converted to a single IP address or to an IP address pool.
Iptables-t nat-a prerouting-I ppp0-p tcp -- dport 80-j DNAT -- to 192.168.0.3: 80
# Change the IP address of the packet that comes in from ppp0 to 192.168.0.3.
-J SNAT # Source Address Conversion
Iptables-t nat-a postrouting-s 192.168.0.0/24-j SNAT -- to1.1.1.1
# Change the source address of intranet 192.168.0.0/24 to 1.1.1.1 for nat table
Iptables-t nat-a postrouting-s 192.168.0.0/24-j SNAT -- to1.1.1.1-1.1.1.10
# Change to an address pool
-J MASQUERADE # Dynamic source address conversion
Iptables-t nat-a postrouting-s 192.168.0.0/24-j MASQUERADE
# Mask the IP address of the packet whose source address is 192.168.0.0/24
=========================== Additional module
State # matching by package status
Mac # match by source mac
Limit # matching by package rate
Multiport # Multi-port matching
-- State
-M state # new, related, established, invalid
Iptables-a input-m state -- state RELATED, ESTABLISHED-jACCEPT
# Package status RELATED (derived state), ESTABLISHED (connection state), NEW (different from tcp syn), INVALID (not recognized)
Iptables-a forward-m mac -- mac-source XX: XX-jDROP
# Block packets from a MAC address from the local machine
Iptables-a forward-d 192.168.0.1-m limit -- limit 50/s-jACCEPT
# Use a certain rate to match data packets
Iptables-a input-p tcp-m multiport -- dports21, 22,25, 80,110-j ACCEPT
# Match multiple ports at a time
================================================ Instance analysis ==========================================
Single server protection:
Iptables-a input-I lo-j ACCEPT
Iptables-a input-p tcp-m multiport -- dport 22,80-jACCEPT