Add port (1) allow hosts with the source address x. x/x to pass through 22 (ssh) port. iptables-AINPUT-ptcp-sx.x.x.x/x? Dport22-jACCEPT (2) allow packets on port 80 (http) to enter iptables-AINPUT-ptcp? Dport80-jACCEPT (3) data that allows Port 110 (pop3)
Add port
(1) allow hosts with the source address x. x/x to use port 22 (ssh.
Iptables-A input-p tcp-s x. x/x? Dport 22-j ACCEPT
(2) allow inbound packets from Port 80 (http)
Iptables-a input-p tcp? Dport 80-j ACCEPT
(3) allow incoming packets from Port 110 (pop3). If this rule is not added, emails can only be received through web pages (OE or Foxmail cannot be used)
Iptables-a input-p tcp? Dport 110-j ACCEPT
(4) allow incoming packets from port 25 (smtp). If this rule is not added, emails can only be sent through web pages (OE or Foxmail cannot be used)
Iptables-a input-p tcp? Dport 25-j ACCEPT
(5) allow inbound data packets from Port 21 (ftp)
Iptables-a input-p tcp? Dport 21-j ACCEPT
(6) allow data packets on port 20 (ftp) to enter (execute ftp commands, such as dir)
Iptables-a input-p tcp? Dport 20-j ACCEPT
(7) allow 53 (dns) port data packets to enter (tcp)
Iptables-a input-p tcp? Dport 53-j ACCEPT
(8) allow 53 (dns) port data packets to enter (udp)
Iptables-a input-p udp? Dport 53-j ACCEPT
(9) allow ICMP packets to pass, that is, allow ping
Iptables-a input-p icmp-j ACCEPT
(10) support for connection status using iptables
Iptables-a input-m state? State ESTABLISHED, RELATED-jACCEPT
(11) set the default rule of the INPUT chain to DROP
Iptables-P INPUT DROP
Iptables limits IP addresses to access specific ports
7.1 allow SSH connection to a machine with an IP address (192.168.6.100:
[Root @ singledb ~] # Iptables-a input-s 192.168.6.100-p tcp? Dport 22-j ACCEPT
[Root @ singledb ~] # Iptables-L-n
Chain INPUT (policy ACCEPT)
Target protopt source destination
ACCEPT tcp? 192.168.6.100 0.0.0.0/0 tcpdpt: 22
7.2 allow a certain segment of IP address to access SSH
[Root @ singledb ~] # Iptables-d input-s 192.168.6.100-p tcp? Dport 22-j ACCEPT
[Root @ singledb ~] # Iptables-a input-s 192.168.6.0/24-p tcp? Dport 22-j ACCEPT
[Root @ singledb ~] # Iptables-L-n
Chain INPUT (policy ACCEPT)
Target prot optsource destination
ACCEPT tcp? 192.168.6.0/24 0.0.0.0/0 tcpdpt: 22
Because this port has been added before, the configuration of 22 is deleted first and then added. here we use 192.168.6.0/24. it indicates that all IP addresses of 192.168.6.1-192.168.6.254 can be accessed.
7.3 restrict access to SSH from an IP address
[Root @ singledb ~] # Iptables-a input-p tcp-s! 192.168.6.100? Dport 22-j ACCEPT? Note! There is a space
[Root @ singledb ~] # Iptables-L-n
Chain INPUT (policy ACCEPT)
Target prot optsource destination
ACCEPT tcp? 192.168.6.0/24 0.0.0.0/0 tcpdpt: 22