iptables 101

How to do things with iptables. Safety first: How to reset everything.

sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
Also, safety first: Don’t just copy something and run it on your server. You better understand what you are doing.
How to block a service?
Instead of using “DROP” you should use “REJECT –reject-with tcp-reset”. If you want to be able to access that service from the inside, you have to add an allow rule first.
sudo iptables -A INPUT -p tcp -s localhost --dport 3306 -j ACCEPT #mysql allow local
sudo iptables -A INPUT -p tcp --dport 3306 -j REJECT --reject-with tcp-reset #mysql

The “REJECT –reject-with tcp-reset” looks to the outside like there is no service running. A “DROP” will show that there is a firewall / iptables working.

Blocking an IP range

sudo iptables -A bannedDownloader -s 14.120.0.0/16 -j DROP

Disallow NTP queries

sudo iptables -A INPUT -p udp -s localhost --dport 123 -j ACCEPT #ntp allow local
sudo iptables -I INPUT -p udp --dport 123 -j REJECT #ntp

Block timestamp

sudo iptables -I INPUT 1 -p ICMP --icmp-type timestamp-request -j DROP
sudo iptables -I INPUT 1 -p ICMP --icmp-type timestamp-reply -j DROP
sudo iptables -A INPUT -p icmp --icmp-type 13 -j DROP

Internet = Internet!

Woooow! So etwas hatte ich lange nicht mehr. Ich bin seit ein paar Tagen bei einem Kunden vor Ort so weit nichts außergewöhnliches. Laptop ans LAN angeklemmt und dann Firmennetzwerk ausgewählt als mein Win7 danach fragte. Ich bin ja immer ein wenig neugierig was neue Netze angeht. Deshalb habe ich erst mal das gute ipconfig /all angeguckt. Als ich dann auf wieistmeineip de geguckt habe, mußte ich erst ein mal schlucken. Internet = im Internet. Meine lokale LAN IP war gleich der IP die im Internet war. Kurz beim Admin nachgefragt, der konnte das so bestätigen. Danach habe ich erst mal schnell das Netzwerk auf öffentliches Netzwerk gestellt. Kurz vorher habe ich noch einen Blick auf das Windowsnetzwerk geworfen. Wow, viele tolle PCs ohne Firewall und auch direkt aus dem Internet zu erreichen! Win Win Situation. Also für potenzielle Hacker von außen, aber auch für mich, da hier wohl keiner den Netzwerkverkehr so einfach mitschneiden kann oder doch? Ein schnelles tracert zeigte dann aber doch, dass die Route ins Internet dann doch über 2 Router oder 2 Level-3 switche geht. Lieber Admin, wie wäre es mit NAT?!?! O_o Und einer schönen Firewall inklusive? Zu mindest könnte ich jetzt wenn ich denn wollte dort direkt einen server meine Wahl betreiben.

Nach dem ich meine Netzwerkkonfiguration geändert hatte, hatte ich mich gleich noch mal per SSH auf einem meiner server eingeloggt und von dort aus einen nmap scan gemacht. Alles zu :) Zum test noch mal kurz auf Firmemnetzwerk zurück geändert. Autsch, da waren sie die schönen offennen Port. Und wieder öffentliches Netzwerk eingestellt. Da soll mal einer sagen, dass die Windows Firewall unnütz ist. Zu mindest bei meinem Win7 ultimate kann ich hier nicht klagen.

Posts Tagged Firewall

Archives by Month: