Iptables rule
To delete existing rules:
# iptables -F
To list existing rules:
# iptables -L
To whitelist an IP address:
# iptables -A INPUT -s <IP> -j ACCEPT
# iptables -A OUTPUT -s <IP> -j ACCEPT
# service iptables save
To blacklist an IP address:
# iptables -I INPUT -j DROP -s <IP>
# iptables -I OUTPUT -j DROP -s <IP>
# service iptables save
To unblock an IP address:
# iptables -D INPUT -s <IP> -j DROP
# iptables -D INPUT -s <IP> -j DROP
# service iptables save
To open a port range(like 3000 to 5000):
# iptables -A INPUT -p tcp --destination-port 3000:5000 -j ACCEPT
# iptables -A OUTPUT -p tcp --source-port 3000:5000 -j ACCEPT
# service iptables save
To redirect all traffic from one IP address to another IP address:
# iptables -t nat -A PREROUTING -d <FIRST IP> -j DNAT --to-destination <ANOTHER IP>
# service iptables save
To allow TCP port 25 for all:
# iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT
Note:
-A -> Append,
-I -> Insert,
-D -> Delete,
-j -> Jump to target,
-i eth0 -> interface eth0,
-p tcp -> protocol TCP,
–dport -> destination port
Thank you.
# iptables -F
To list existing rules:
# iptables -L
To whitelist an IP address:
# iptables -A INPUT -s <IP> -j ACCEPT
# iptables -A OUTPUT -s <IP> -j ACCEPT
# service iptables save
To blacklist an IP address:
# iptables -I INPUT -j DROP -s <IP>
# iptables -I OUTPUT -j DROP -s <IP>
# service iptables save
To unblock an IP address:
# iptables -D INPUT -s <IP> -j DROP
# iptables -D INPUT -s <IP> -j DROP
# service iptables save
To open a port range(like 3000 to 5000):
# iptables -A INPUT -p tcp --destination-port 3000:5000 -j ACCEPT
# iptables -A OUTPUT -p tcp --source-port 3000:5000 -j ACCEPT
# service iptables save
To redirect all traffic from one IP address to another IP address:
# iptables -t nat -A PREROUTING -d <FIRST IP> -j DNAT --to-destination <ANOTHER IP>
# service iptables save
To allow TCP port 25 for all:
# iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT
Note:
-A -> Append,
-I -> Insert,
-D -> Delete,
-j -> Jump to target,
-i eth0 -> interface eth0,
-p tcp -> protocol TCP,
–dport -> destination port
Thank you.
Comments
Post a Comment