Exemples De Script Iptables With Code Examples

  • Updated
  • Posted in Programming
  • 6 mins read


Exemples De Script Iptables With Code Examples

The answer to Exemples De Script Iptables shall be demonstrated utilizing examples on this article.

extra /and many others/init.d/MonFirewall

#!/bin/bash
echo Setting firewall guidelines...
#
# config de base
#

# Vider les tables actuelles
iptables -t filter -F
iptables -t filter -X
echo - Vidage : [OK]

# Autoriser SSH
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
echo - Autoriser SSH : [OK]

# Ne pas casser les connexions établies
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
echo - Ne pas casser les connexions établies : [OK]

# Interdire toute connexion entrante
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
echo - Interdire toute connexion entrante : [OK]

# Interdire toute connexion sortante
iptables -t filter -P OUTPUT DROP
echo - Interdire toute connexion sortante : [OK]

# Autoriser les requetes DNS, FTP, HTTP, NTP and many others. SORTANTES
iptables -t filter -A OUTPUT -p tcp --dport 20 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 21 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 123 -j ACCEPT
echo - Autoriser les requêtes DNS, FTP, HTTP, NTP : [OK]

# Autoriser loopback
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
echo - Autoriser loopback : [OK]

# Autoriser ping
iptables -t filter -A INPUT -p icmp -j ACCEPT
iptables -t filter -A OUTPUT -p icmp -j ACCEPT
echo - Autoriser ping : [OK]

# Gestion des connexions ENTRANTES autorisées
#
# iptables -t filter -A INPUT -p  --dport -j ACCEPT

# Autoriser HTTP, HTTPS
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
echo - Autoriser serveur Apache : [OK]

# Autoriser FTP
modprobe ip_conntrack
modprobe ip_conntrack_ftp
iptables -t filter -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
echo - Autoriser serveur FTP : [OK]

# Autoriser Mail
iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 143 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 110 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 143 -j ACCEPT
echo - Autoriser serveur Mail : [OK]

# Limiter le Syn-Flood à 1 seconde
iptables -A FORWARD -p tcp --syn -m restrict --limit 1/second -j ACCEPT
iptables -A FORWARD -p udp -m restrict --limit 1/second -j ACCEPT
echo - Limiter le Syn-Flood : [OK]

# IP à blacklister
# iptables -A INPUT -s ADRESSE_IP -j DROP
echo - Mise à jour des IP blacklistées : [OK]

# Bloquer le Spoofing
iptables -N SPOOFED
iptables -A SPOOFED -s 127.0.0.0/8 -j DROP
iptables -A SPOOFED -s 169.254.0.0/12 -j DROP
iptables -A SPOOFED -s 172.16.0.0/12 -j DROP
iptables -A SPOOFED -s 192.168.0.0/16 -j DROP
iptables -A SPOOFED -s 10.0.0.0/8 -j DROP
echo - Bloquer le Spoofing : [OK]

echo Firewall mis a jour avec succès !

Numerous real-world examples illustrate how you can take care of the Exemples De Script Iptables situation.

How do I write a firewall script in Linux?

Because these scripts are completely different for every Linux distribution, we’ll make scripts for the supported distributions accessible on Sun’s website.

  • Specify Firewall Script Parameters.
  • Load Helper Modules.
  • Prepare the Firewall.
  • Establish Logging Rules.
  • Add Anti-Spoofing Rules.
  • Add Dynamic Rules.
  • Manage Inbound Sessions.

How do I permit all ports in iptables?

Individual instructions methodology

  • Run the next command to permit site visitors on port 80: sudo iptables -I INPUT -p tcp -m tcp –dport 80 -j ACCEPT.
  • Run the next command to permit site visitors on port 443: sudo iptables -I INPUT -p tcp -m tcp –dport 443 -j ACCEPT.

How do I allow port 80 in Linux?

Open port 80 on RHEL

  • First add your port 80 rule with the next linux command: # firewall-cmd –zone=public –add-port=80/tcp –everlasting.
  • Once you add the above firewall rule, reload the firewall service with this command: # firewall-cmd –reload.

How do I allow ssh in iptables?

Firewall iptables guidelines

  • Allow SSH session to firewall 2 by utilizing the next command: iptables -A INPUT -p tcp –dport 22 -s 0/0 -j ACCEPT.
  • Allow ICMP site visitors to firewall 2 by utilizing the next command:
  • Allow all associated and established site visitors for firewall 2 by utilizing the next command:

Is iptables a firewall?

Simply put, iptables is a firewall program for Linux. It will monitor site visitors from and to your server utilizing tables. These tables include units of guidelines, known as chains, that may filter incoming and outgoing information packets.18-Jul-2022

What is distinction between iptables and firewalld?

The firewall On the one hand, iptables is a software for managing firewall guidelines on a Linux machine. On the opposite hand, firewalld can also be a software for managing firewall guidelines on a Linux machine.18-Sept-2018

How do you examine 443 port is enabled or not in Linux?

How to examine if a port is in use on Linux

  • Open the terminal software on Linux.
  • Type any one of many following command to examine if a port is in use on Linux. sudo lsof -i -P -n | grep LISTEN.
  • Search for the TCP or UDP port description in /and many others/companies file on Linux: grep -E -w ‘PORT_NUMBER_HERE/(tcp|udp)’ /and many others/companies.

How do I whitelist a port in Linux?

To specify an IP tackle that may entry the port, use this syntax: sudo ufw permit from 10.0. 0.1 to any port 22 . Replace 10.0. 0.1 with the IP tackle, and 22 with the port you need to open to that tackle.28-Aug-2022

How do I permit all ports in Linux?

Ubuntu and Debian

  • Issue the next command to open port 1191 for TCP site visitors. sudo ufw permit 1191/tcp.
  • Issue the next command to open a variety of ports. sudo ufw permit 60000:61000/tcp.
  • Issue the next command to cease and begin Uncomplicated Firewall (UFW). sudo ufw disable sudo ufw allow.

Is port 80 and 8080 the identical?

GRC | Port Authority, for Internet Port 8080. Description: This port is a well-liked different to port 80 for providing net companies. “8080” was chosen since it’s “two 80’s”, and likewise as a result of it’s above the restricted well-known service port vary (ports 1-1023, see under).

Leave a Reply