Difference between revisions of "Iptables"

From HackerNet
Jump to: navigation, search
(Created page with "Källa och väldigt bra läsning: http://www.lysator.liu.se/~kjell-e/tekla/linux/security/iptables/ Sätt upp en brandvägg för att begränsa och blockera oönskad inkommand...")
 
m
Line 4: Line 4:
  
 
Exempel
 
Exempel
  cat<<'__EOF__'>>/etc/iptables.firewall.rules
+
  sudo dd of=/etc/iptables.firewall.rules << EOF
 
  *filter
 
  *filter
 
   
 
   
Line 24: Line 24:
 
   
 
   
 
  COMMIT
 
  COMMIT
  __EOF__
+
  EOF
  
 
Rules activate!
 
Rules activate!
Line 32: Line 32:
  
 
'''Behåll regler efter omstart, Debian/Ubuntu'''
 
'''Behåll regler efter omstart, Debian/Ubuntu'''
  cat<<'__EOF__'>>/etc/network/if-pre-up.d/firewall
+
  sudo dd of=/etc/network/if-pre-up.d/firewall << EOF
 
  #!/bin/sh
 
  #!/bin/sh
 
  /sbin/iptables-restore < /etc/iptables.firewall.rules
 
  /sbin/iptables-restore < /etc/iptables.firewall.rules
  __EOF__
+
  EOF
 
  sudo chmod +x /etc/network/if-pre-up.d/firewall
 
  sudo chmod +x /etc/network/if-pre-up.d/firewall

Revision as of 16:14, 8 April 2015

Källa och väldigt bra läsning: http://www.lysator.liu.se/~kjell-e/tekla/linux/security/iptables/

Sätt upp en brandvägg för att begränsa och blockera oönskad inkommande trafik till din server, detta är valfritt men rekommenderat.

Exempel

sudo dd of=/etc/iptables.firewall.rules << EOF
*filter

# Standard
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Portar och protokoll
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
-A INPUT -p icmp --icmp-type echo-request -j ACCEPT

# Catch all
-A INPUT -j DROP
-A FORWARD -j DROP
-A OUTPUT -j ACCEPT

COMMIT
EOF

Rules activate!

sudo iptables-restore < /etc/iptables.firewall.rules
sudo iptables -L


Behåll regler efter omstart, Debian/Ubuntu

sudo dd of=/etc/network/if-pre-up.d/firewall << EOF
#!/bin/sh
/sbin/iptables-restore < /etc/iptables.firewall.rules
EOF
sudo chmod +x /etc/network/if-pre-up.d/firewall