Skip to content

Instantly share code, notes, and snippets.

@BenMorel
Forked from LouWii/iptables-config-script
Created October 17, 2019 22:57

Revisions

  1. BenMorel revised this gist Oct 17, 2019. 1 changed file with 5 additions and 38 deletions.
    43 changes: 5 additions & 38 deletions iptables-config-script
    Original file line number Diff line number Diff line change
    @@ -4,58 +4,25 @@
    sudo iptables -t filter -F
    sudo iptables -t filter -X

    # Bloc everything by default
    # Set up default rules
    sudo iptables -t filter -P INPUT DROP
    sudo iptables -t filter -P FORWARD DROP
    sudo iptables -t filter -P OUTPUT DROP
    sudo iptables -t filter -P OUTPUT ACCEPT

    # Authorize already established connexions
    sudo iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    sudo iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

    # Authorize loopback
    sudo iptables -t filter -A INPUT -i lo -j ACCEPT
    sudo iptables -t filter -A OUTPUT -o lo -j ACCEPT

    # ICMP (Ping)
    sudo iptables -t filter -A INPUT -p icmp -j ACCEPT
    sudo iptables -t filter -A OUTPUT -p icmp -j ACCEPT

    # SSH
    sudo iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
    sudo iptables -t filter -A OUTPUT -p tcp --dport 22 -j ACCEPT

    # DNS
    sudo iptables -t filter -A OUTPUT -p tcp --dport 53 -j ACCEPT
    sudo iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 53 -j ACCEPT
    sudo iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT

    # HTTP
    sudo iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT

    #HTTPS
    sudo iptables -t filter -A OUTPUT -p tcp --dport 443 -j ACCEPT
    # HTTPS
    sudo iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT

    # FTP
    sudo iptables -t filter -A OUTPUT -p tcp --dport 20:21 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 20:21 -j ACCEPT

    # Git
    sudo iptables -t filter -A OUTPUT -p tcp --dport 9418 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 9418 -j ACCEPT

    # Mail SMTP
    iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT

    # Mail POP3
    iptables -t filter -A INPUT -p tcp --dport 110 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp --dport 110 -j ACCEPT

    # Mail IMAP
    iptables -t filter -A INPUT -p tcp --dport 143 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp --dport 143 -j ACCEPT

    # NTP (server time)
    sudo iptables -t filter -A OUTPUT -p udp --dport 123 -j ACCEPT
  2. @LouWii LouWii revised this gist Apr 18, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions iptables-config-script
    Original file line number Diff line number Diff line change
    @@ -41,6 +41,10 @@ sudo iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
    sudo iptables -t filter -A OUTPUT -p tcp --dport 20:21 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 20:21 -j ACCEPT

    # Git
    sudo iptables -t filter -A OUTPUT -p tcp --dport 9418 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 9418 -j ACCEPT

    # Mail SMTP
    iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT
  3. @LouWii LouWii renamed this gist Mar 18, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @LouWii LouWii renamed this gist Mar 18, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @LouWii LouWii renamed this gist Mar 18, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @LouWii LouWii created this gist Mar 18, 2014.
    57 changes: 57 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    #!/bin/sh

    # Empty all rules
    sudo iptables -t filter -F
    sudo iptables -t filter -X

    # Bloc everything by default
    sudo iptables -t filter -P INPUT DROP
    sudo iptables -t filter -P FORWARD DROP
    sudo iptables -t filter -P OUTPUT DROP

    # Authorize already established connexions
    sudo iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    sudo iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    sudo iptables -t filter -A INPUT -i lo -j ACCEPT
    sudo iptables -t filter -A OUTPUT -o lo -j ACCEPT

    # ICMP (Ping)
    sudo iptables -t filter -A INPUT -p icmp -j ACCEPT
    sudo iptables -t filter -A OUTPUT -p icmp -j ACCEPT

    # SSH
    sudo iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
    sudo iptables -t filter -A OUTPUT -p tcp --dport 22 -j ACCEPT

    # DNS
    sudo iptables -t filter -A OUTPUT -p tcp --dport 53 -j ACCEPT
    sudo iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 53 -j ACCEPT
    sudo iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT

    # HTTP
    sudo iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT

    #HTTPS
    sudo iptables -t filter -A OUTPUT -p tcp --dport 443 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT

    # FTP
    sudo iptables -t filter -A OUTPUT -p tcp --dport 20:21 -j ACCEPT
    sudo iptables -t filter -A INPUT -p tcp --dport 20:21 -j ACCEPT

    # Mail SMTP
    iptables -t filter -A INPUT -p tcp --dport 25 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT

    # Mail POP3
    iptables -t filter -A INPUT -p tcp --dport 110 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp --dport 110 -j ACCEPT

    # Mail IMAP
    iptables -t filter -A INPUT -p tcp --dport 143 -j ACCEPT
    iptables -t filter -A OUTPUT -p tcp --dport 143 -j ACCEPT

    # NTP (server time)
    sudo iptables -t filter -A OUTPUT -p udp --dport 123 -j ACCEPT