Tuesday, February 26, 2013

Cum parolezi directoarele in Windows 7

Windows 7 vine cu o noua optiune de criptare care iti ofera posibilitatea de a parola fisierele si respectiv directoarele .Aceasta optiune blocheaza accesul la fisierele tale celor care nu au parola corespunzatoare.

Aceasta optiune e foarte buna pentru cei care au mai multi utilizatori la acelasi calculator.

Cum pui parole la fisiere sau directoare in Windows 7 ?

1. Intrati in My Computer si navigati pana la fisierul/directorul pe care il doriti parolat.

2. Right-click pe folderul care il doriti parolat, si selectati  "Properties" .  Click pe tabul  "General" pentru a vizuliza proprietatile, apoi click pe butonul  "Advanced"

3. Click pe optiunea(checkbox) numita  "Encrypt contents to secure data." Click  pe "OK" .

4. Se va fixa automat o parola pe directorul respectiv, care este parola cu care va logati la calculator.

Alti utilizatori care se logheaza in pc-ul dvs, vor fi obligati sa stie userul si parola pentru a putea accesa acest folder.

Cel mai simplu ca sa verificati,e sa va conectati/logati cu un alt utilizator si veti observa ca veti fi interogati de user si parola.

Continue Reading »

Tuesday, February 5, 2013

Cum scapi de “Politia Romana” mai exact de virusul “Politia Romana”

Daca la pornirea calculatorului primesti mesajul de mai jos:

Calculatorul Dvs este blocat
Dvs sunteţi contravenientul acţiunile căruia sunt ilegale şi duc la răspundere penală
Lucrul calculatorului Dvs este suspendat din cauza ciber-activităţii nesancţionate.
Mai jos sunt enumerate încălcările posibile:
Articolul – 174. Drept de autor
închisoare de la 2 pînă la 5 ani (Utilizarea sau distribuirea operelor de autor). Amenda de la 65 000 RON pînă la 70 000 RON.

…………….

Prima încălcare nu atrage răspunderea penală, ci doar achitarea amenzii în legătură cu legea de loialitate faţă de populaţie, adoptată la 04 decembrie 2012. La încălcările repetate răspunderea penală este inevitabilă.
Pentru a debloca
calculatorul şi a evita alte consecinţe juridice sunteţi obligat să achitaţi o amendă de 400 RON.
Articolul- 104. Ajutor acordat terorismului
închisoare pînă la 25 ani fără drept la apel (Vizitarea sit-urilor grupărilor teroriste). Amenda de la 120 000 pînă la 155 000 RON cu confiscarea averii.
Articolul- 68. Răspîndirea programelor virusate
închisoare pînă la 2 ani (Crearea sau răspîndirea programelor virusate care au cauzat prejudicii altor calculatoare). Amenda de la 55 ooo RON pînă la 85 ooo RON.
Articolul- 113. Utilizarea software-ului fără licenţă
închisoare pînă la 2 ani (Utilizarea software-ului fără licenţă). Amenda de la 35 000 RON pînă la 75 000 RON.
Puteţi obţine Ukash de la sute de mii de site-uri din intreaga lume, portofolii oniine, chioşcuri şi ATM-uri.
Articolul- 99. Fraude cu cârduri de plată, carding
închisoare pînă la 5 ani (Operaţiunea cu utilizarea cârdului de plată sau rechizitelor lui, neiniţiată sau neconfirmată de posesorul ei). Amenda de la 90 000 RON pînă la 140 000 RON cu confiscarea averii.”

Atunci mai mult ca sigur ai fost infectat cu Trojan.Ransom.IcePol (W32/Reveton; Trojan.Win32.Ransirac) si care are ca rezultat mesajul de mai sus numit si

Virusul Politia Romana

 

Desktopul dvs e blocat de mesajul de mai sus.

Responsabile sunt niste dll-uri care pe Windows XP se gasesc in %USERPROFILE%\\Start Menu\\Programs\\Startup\\<reveton_filename>.dll.lnk iar pe Windows 7 in %USERPROFILE%\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\<reveton_filename>dll.lnk

Cum scapi foarte simplu de virusul Politia Romana

  • Copiezi pe un stick utilitarul care ti-l voi da la download mai jos, bootezi computerul  in Safe Mode with Command Prompt si te loghezi cu userul afectat.
  • Utilitarul trebuie sa il rulezi din command prompt.
  • Dupa ce termina restarteaza calculatorul si porneste-l normal.Ar trebui sa fie ok daca ai facut pasii exact cum am spus.

DOWNLOAD Removal Tool Politia Romana Virus pentru computer-ul tau

Continue Reading »

Friday, January 25, 2013

Cum restarurezi MBR-ul in Windows 7 sau cum scapi de eroarea “Operating system not found"

Sunt cazuri in care, in urma incercarilor de instalare a unui alt sistem de operare Windows MBR (Master Boot Record) devine corupt iar calculatorul  dvs. nu mai porneste si trebui dat un fix la MBR. Eroarea curenta care apare in mod frecvent e "Operating system not found"

Pentru a scapa de aceasta eroare ai nevoie de un utilitar numit MbrFix.exe care il puteti rula de pe un floppy disk,un CD/VD sau de pe un stick USB.

Instructiuni pentru a rula MBRFIX de pe DVD(de pe floppy sau usb conceptul e acelasi):

  • Inserati  DVD-ul de instalare Windows 7 si bootati de pe DVD. E posibil sa fie necesar sa schimbati ordinea de bootare din BIOS pentru a boota de pe CD/DVD.

  • Alegeti default "Language," "Time" si "Keyboard Input"  corespunzatoare si dati click "Next."

  • Click pe "Repair Your Computer" care va continua cu fereastra System Recovery . Apoi alegeti "Command Prompt" pentru a rula utilitarul Bootsect.exe. Bootsect e localizat in folderul de boot folder asa ca va trebui sa schimbati directorul in boot.

  • Acum rulati  "bootsect /nt60 C:\" (fara ghilimele) daca aveti Windows 7 instalat in partitia C.

  • Pentru usurinta puteti rula "bootsect /nt60 SYS" sau "bootsect /nt60 ALL" (fara ghilimele)  pentru a repara toate partitile sistem sau toate partitile.

  • Scoateti DVD-ul si restartati calculatorul.

  • Windows  7 ar trebui sa starteze.

V-a mers ? Ce probleme ati avut ?

Continue Reading »

Friday, November 9, 2012

Castiga GRATUIT un laptop HP Pavilion G6-2230sq, SonyVaio sau Acer Aspire V5

Windows 8 in colaborare cu Emag.ro deruleaza un concurs cu premii pe masura.

Poti castiga oricare dintre cele 16 premii oferite de Microsoft :

- 1 x HP Pavilion G6-2230sq care e un laptop super atractiv, simplu si usor de folosti pentru activitati de zi cu zi cu familia si prietenii.
- 2 x Sony Vaio E15 cu un design prietenos, simplu dar distinct, confortabil la utilizare
- 3 x Acer Aspire V5 , un laptop din seria Aspire V5 ,foarte atractiv, ergonomic si durabil si cu un profil subtire, accent estetic elegant  si texturi incantatoare care confera seriei Aspire un aspect solid si de unicitate.
- 10 x Microsoft ArcTouch

Ce trebuie sa faci ?

Tot ce trebuie sa faci e sa folosesti aplicatia Win 8@eMAG si intri automat in tragerea la sorti pentru unul din cele 16 premii oferite de Microsoft.

Toti participantii beneficiaza automat de un cover photo personalizat pentru profilul de Facebook,dar cel mai important e ca esti introdus automat in tragerea la sorti pentru cele 16 premii.

Participa.

Continue Reading »

Tuesday, November 6, 2012

Cum configurezi Windows Firewall in Windows 7

Eu sunt unul dintre acei utilizatori de Windows 7 care nu simte nevoia unui firewall extra: ceea ce îmi oferă implicit Windows-ul e mai mult decât suficient. Pentru ce să îmi complic existența cu un alt firewall?
Și spun asta în condițiile în care orice alt firewall aș folosi aș fi capabil să îl configurez în doar câteva minute. Merg pe principiul conform căruia un produs care funcționează nu are de ce să fie schimbat. E cazul de față, unde Windows Firewall își face treaba.
Știu că utilizatorii de Windows primesc de la început un mesaj clar: asigurați-vă că aveți PC-ul protejat. Transmit în mod frecvent informația asta, însă mă refer exclusiv la partea antimalware. Cred că nu are rost să pui un firewall suplimentar numai pentru că în pachetul antimalware pe care îl folosești și se livrează și așa ceva. De câte ori nu ați avut probleme de conectare la rețea/internet imediat ce ați pus un firewall terț? Și au început să curgă ferestrele de atenționare în care vi se cerea acordul pentru aproape orice acțiune?
Sau, la polul opus, nu primiți niciun mesaj, dar nici nu aveți cum să folosiți anumite produse. Din cauza asta m-am gândit că e cazul să fac puțină lumină vizavi de firewall-ul din Windows și cu ocazia asta să răspund și numeroaselor mesaje pe care le-am primit pe email privitor la configurarea Windows Firewall.

E suficient firewall-ul din Windows?

Da. Pentru marea majoritate a utilizatorilor de Windows, ceea ce oferă Microsoft implicit în sistemul de operare e mai mult decât suficient. Aveți doar grijă ca el să fie activ – verificați asta dând clic pe butonul Start și scriind acolo firewall și apoi selectând din listăWindows Firewall.
1
Sper să nu aveți imaginea de mai jos pentru că înseamnă că firewall-ul nu e pornit – în situația în care aveți deja un alt firewall pornit, atunci e în regulă. Vedeți cum Windows Firewall state este Off.
image
Ca să fie activat din nou trebuie să dați clic pe TurnWindows Firewall
on or off ca să ajungeți în fereastra de configurare a firewall-ului din Windows. Observați că există două zone: Home or work și Public networks.
image
Situația apare datorită faptului că Windows-ul asociază automat o stare (home, work, public) pentru fiecare conexiune la rețea pe care o aveți. Primele două: home și work sunt tratate ca și private în ideea că ele sunt mai de încredere și ca atare setarea firewall-ului va avea reguli mai relaxate care să permită mai multe conexiuni de la PC și înspre el – ex: în rețeaua internă aveți de exemplu nevoie să schimbați fișiere cu alte sisteme și drept urmare firewall-ul e preconfigurat să permită așa ceva.
În partea cealaltă- în zona publică - Windows Firewall știe că trebuie să protejeze maxim și ca urmare sunt filtrate majoritatea conexiunilor, doar cele standard: browsing, ftp, mail etc. sunt lăsate să treacă dinspre PC către exterior și invers.
Folosind cele două stări, putem foarte ușor să jonglăm cu protecția firewall pe conexiunile pe care le avem, mutându-le din zona publică în cea privată în funcție de locul în care ne găsim.

Cum se activează Windows Firewall?

Primul pas este acela în care din Control Panel, Windows Firewall și apoi Customize Settings bifăm Turn on Windows Firewall pentru ambele tipuri de rețea: publică și privată.
image
Înainte de a aplica setările asigurați-vă și că ați bifat opțiunea de notificare la blocarea unui anumit program – când Windows Firewall nu știe cum să trateze o anumită conexiune veți fi întrebați ce să se întâmple cu ea și puteți alege să o lăsați să treacă.
image
Acum aveți activ firewall-ul din Windows și puteți să stați liniștiți. Atacurile din rețea vor fi respinse și nu veți fi deranjați cu mesaje inutile.
SFAT: ori de câte ori sunteți cu laptop-ul pe o rețea WiFi publică, treceți firewall-ul de pe conexiunea Wifi pe setările publice.
Faceți asta mergând în Control Panel, Network and Sharing Center și aici o să vedeți că sub View your active networks apare conexiunea de care sunteți interesați. Se poate da clic pe tipul de rețea ca să se facă trecerea din public în privată.
imageimage

Cum las un anume program să treacă prin firewall?

Se mai întâmplă să vă găsiți în situația în care Windows Firewall să nu știe cum să trateze un anumit program și din cauza setărilor generice să îi blocheze conexiunile la internet. Puteți foarte ușor să creați o regulă nouă, care să fie aplicată automat din acest moment.
Acțiunea cea mai simplă constă în clic pe butonul Start și scrieți firewall. Din lista oferită dați acum clic pe Allow  program through Windows Firewall.
image
Vi se va deschide o fereastră unde apar toate programele și serviciile care sunt cunoscute că se conectează la internet sau care au încercat să se conecteze și Windows Firewall a creat deja o regulă pentru ele. Parcurgeți-o.
Dacă găsiți acolo aplicația dorită nu trebuie decât să bifați tipul de rețea (Private sau Public) unde vreți să aibă dreptul de a se conecta la internet – înainte ați apăsat butonul Change Settings.
Am luat ca exemplu modulul Remote Desktop și am activat manual opțiunea de conectare la internet pe ambele tipuri de rețea. De acum Windows Firewall va ști cum să trateze Remote Desktop.
image
Când nu e afișat aici îl veți adăuga manual: clic pe Allow another program și selectați-l din listă sau adăugați manual calea către executabil folosindu-vă de butonul Browse.  Apoi Add și gata. L-ați lăsat să treacă prin firewall și ați creat o regulă pentru el.
image
Vă întrebați probabil ce se ascunde în spatele Network location types … Dați clic pe buton și găsiți rapid semnificația: de aici alegeți pe care tip de rețea se aplică regula.

Avansat: consultarea logului de activitate. Ce evenimente au fost?

Ultimul aspect pe care vreau să îl mai discut e legat de log-urile de activitate. Unii utilizatori au nevoie să știe ce evenimente s-au întâmplat în rețea: au fost atacați? E ceva ce nu a mers bine?
Majoritatea aplicațiilor terțe de fip firewall sau modulele dedicate din suitele de securitate pun la dispoziție opțiuni avansate pentru așa ceva. E unul din motivele pentru care anumiți utilizatori preferă să lucreze cu firewall-uri terțe în dezavantajul celui inclus în Windows.
Vreau să vă spun că și în Windows 7, pentru firewall-ul implicit, se poate consulta log-ul de activitate. E drept că informațiile sunt prezentate mai degrabă criptic, dar cred că e foarte important să știți că există și de unde se consultă.
E necesar să aveți datele de conectare pentru contul de administrator al sistemului dumneavoastră. Apăsați pe butonul Start și scrieți event. Clic pe Event Viewer și apoi mergeți către Applications and Services Logs, Microsoft, Windows, Windows Firewall with Advanced Security. Se deschid patru zone în care sunt informaii: ConnectionSecurity, ConnectionSecurityVerbose, Firewall, FirewallVerbose. Clic pe fiecare în parte și vedeți evenimentele asociate.
image
Asta e tot ce trebuie să știți ca să începeți să folosiți Windows Firewall dacă nu o faceți deja. Mie îmi e suficient. Cred că și vouă.
Continue Reading »

Monday, October 29, 2012

Basic iptables howto

Iptables is a firewall, installed by default on all official Ubuntu distributions (Ubuntu, Kubuntu, Xubuntu). When you install Ubuntu, iptables is there, but it allows all traffic by default. Ubuntu 8.04 Comes with ufw - a program for managing the iptables firewall easily.

There is a wealth of information available about iptables, but much of it is fairly complex, and if you want to do a few basic things, this How To is for you.

Basic Commands

Typing

sudo iptables -L


lists your current rules in iptables. If you have just set up your server, you will have no rules, and you should see



Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination


Basic Iptables Options



Here are explanations for some of the iptables options you will see in this tutorial. Don't worry about understanding everything here now, but remember to come back and look at this list as you encounter new options later on.





  • -A - Append this rule to a rule chain. Valid chains for what we're doing are INPUT, FORWARD and OUTPUT, but we mostly deal with INPUT in this tutorial, which affects only incoming traffic.





  • -L - List the current filter rules.





  • -m conntrack - Allow filter rules to match based on connection state. Permits the use of the --ctstate option.





  • --ctstate - Define the list of states for the rule to match on. Valid states are:




    • NEW - The connection has not yet been seen.


    • RELATED - The connection is new, but is related to another connection already permitted.


    • ESTABLISHED - The connection is already established.


    • INVALID - The traffic couldn't be identified for some reason.





  • -m limit - Require the rule to match only a limited number of times. Allows the use of the --limit option. Useful for limiting logging rules.





    • --limit - The maximum matching rate, given as a number followed by "/second", "/minute", "/hour", or "/day" depending on how often you want the rule to match. If this option is not used and -m limit is used, the default is "3/hour".







  • -p - The connection protocol used.





  • --dport - The destination port(s) required for this rule. A single port may be given, or a range may be given as start:end, which will match all ports from start to end, inclusive.





  • -j - Jump to the specified target. By default, iptables allows four targets:





    • ACCEPT - Accept the packet and stop processing rules in this chain.





    • REJECT - Reject the packet and notify the sender that we did so, and stop processing rules in this chain.





    • DROP - Silently ignore the packet, and stop processing rules in this chain.





    • LOG - Log the packet, and continue processing more rules in this chain. Allows the use of the --log-prefix and --log-leveloptions.







  • --log-prefix - When logging, put this text before the log message. Use double quotes around the text to use.





  • --log-level - Log using the specified syslog level. 7 is a good choice unless you specifically need something else.





  • -i - Only match if the packet is coming in on the specified interface.





  • -I - Inserts a rule. Takes two options, the chain to insert the rule into, and the rule number it should be.





    • -I INPUT 5 would insert the rule into the INPUT chain and make it the 5th rule in the list.







  • -v - Display more information in the output. Useful for if you have rules that look similar without using -v.





  • -s --source - address[/mask] source specification





  • -d --destination - address[/mask] destination specification





  • -o --out-interface - output name[+] network interface name ([+] for wildcard)





Allowing Established Sessions



We can allow established sessions to receive traffic:



sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT



  • The above rule has no spaces either side of the comma in ESTABLISHED,RELATED



If the line above doesn't work, you may be on a castrated VPS whose provider has not made available the extension, in which case an inferior version can be used as last resort:



sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT


Allowing Incoming Traffic on Specific Ports



You could start by blocking traffic, but you might be working over SSH, where you would need to allow SSH before blocking everything else.



To allow incoming traffic on the default SSH port (22), you could tell iptables to allow all TCP traffic on that port to come in.



sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT


Referring back to the list above, you can see that this tells iptables:




  • append this rule to the input chain (-A INPUT) so we look at incoming traffic


  • check to see if it is TCP (-p tcp).


  • if so, check to see if the input goes to the SSH port (--dport ssh).


  • if so, accept the input (-j ACCEPT).



Lets check the rules: (only the first few lines shown, you will see more)



sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh


Now, let's allow all incoming web traffic



sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT


Checking our rules, we have



sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:www


We have specifically allowed tcp traffic to the ssh and web ports, but as we have not blocked anything, all traffic can still come in.



Blocking Traffic



Once a decision is made to accept a packet, no more rules affect it. As our rules allowing ssh and web traffic come first, as long as our rule to block all traffic comes after them, we can still accept the traffic we want. All we need to do is put the rule to block all traffic at the end.



sudo iptables -A INPUT -j DROP
sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:www
DROP all -- anywhere anywhere


Because we didn't specify an interface or a protocol, any traffic for any port on any interface is blocked, except for web and ssh.



Editing iptables



The only problem with our setup so far is that even the loopback port is blocked. We could have written the drop rule for just eth0 by specifying -i eth0, but we could also add a rule for the loopback. If we append this rule, it will come too late - after all the traffic has been dropped. We need to insert this rule before that. Since this is a lot of traffic, we'll insert it as the first rule so it's processed first.



sudo iptables -I INPUT 1 -i lo -j ACCEPT
sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:www
DROP all -- anywhere anywhere


The first and last lines look nearly the same, so we will list iptables in greater detail.



sudo iptables -L -v


Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- lo any anywhere anywhere
0 0 ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:ssh
0 0 ACCEPT tcp -- any any anywhere anywhere tcp dpt:www
0 0 DROP all -- any any anywhere anywhere


You can now see a lot more information. This rule is actually very important, since many programs use the loopback interface to communicate with each other. If you don't allow them to talk, you could break those programs!



Logging



In the above examples none of the traffic will be logged. If you would like to log dropped packets to syslog, this would be the quickest way:



sudo iptables -I INPUT 5 -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7


See Tips section for more ideas on logging.



Saving iptables



If you were to reboot your machine right now, your iptables configuration would disappear. Rather than type this each time you reboot, however, you can save the configuration, and have it start up automatically. To save the configuration, you can use iptables-save and iptables-restore.



Configuration on startup



WARNING: Iptables and NetworkManager can conflict. Also if you are concerned enough about security to install a firewall you might not want to trust NetworkManager. Also note NetworkManager and iptables have opposite aims. Iptables aims to keep any questionable network traffic out.NetworkManager aims to keep you connected at all times. Therefore if you want security all the time, run iptables at boot time. If you want security some of the time then NetworkManager might be the right choice.



WARNING: If you use NetworkManager (installed by default on Feisty and later) these steps will leave you unable to use NetworkManager for the interfaces you modify. Please follow the steps in the next section instead.



NOTE: It appears on Hardy, NetworkManager has an issue with properly on saving and restoring the iptable rules when using the method in the next section. Using this first method appears to work. If you find otherwise, please update this note.



Save your firewall rules to a file



sudo sh -c "iptables-save > /etc/iptables.rules"


At this point you have several options. You can make changes to /etc/network/interfaces or add scripts to /etc/network/if-pre-up.d/ and /etc/network/if-post-down.d/ to achieve similar ends. The script solution allows for slightly more flexibility.



Solution #1 - /etc/network/interfaces


(NB: be careful - entering incorrect configuration directives into the interface file could disable all interfaces, potentially locking you out of a remote machine.)



Modify the /etc/network/interfaces configuration file to apply the rules automatically. You will need to know the interface that you are using in order to apply the rules - if you do not know, you are probably using the interface eth0, although you should check with the following command first to see if there are any wireless cards:



iwconfig


If you get output similar to the following, then you do not have any wireless cards at all and your best bet is probably eth0.



lo        no wireless extensions.

eth0 no wireless extensions.


When you have found out the interface you are using, edit (using sudo) your /etc/network/interfaces:



sudo nano /etc/network/interfaces


When in the file, search for the interface you found, and at the end of the network related lines for that interface, add the line:



pre-up iptables-restore < /etc/iptables.rules


You can also prepare a set of down rules, save them into second file /etc/iptables.downrules and apply it automatically using the above steps:



post-down iptables-restore < /etc/iptables.downrules


A fully working example using both from above:



auto eth0
iface eth0 inet dhcp
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-restore < /etc/iptables.downrules


You may also want to keep information from byte and packet counters.



sudo sh -c "iptables-save -c > /etc/iptables.rules" 


The above command will save the whole rule-set to a file called /etc/iptables.rules with byte and packet counters still intact.



Solution #2 /etc/network/if-pre-up.d and ../if-post-down.d


NOTE: This solution uses iptables-save -c to save the counters. Just remove the -c to only save the rules.



Alternatively you could add the iptables-restore and iptables-save to the if-pre-up.d and if-post-down.d directories in the/etc/network directory instead of modifying /etc/network/interface directly.



The script /etc/network/if-pre-up.d/iptablesload will contain:



#!/bin/sh
iptables-restore < /etc/iptables.rules
exit 0


and /etc/network/if-post-down.d/iptablessave will contain:



#!/bin/sh
iptables-save -c > /etc/iptables.rules
if [ -f /etc/iptables.downrules ]; then
iptables-restore < /etc/iptables.downrules
fi
exit 0


Then be sure to give both scripts execute permissions:



sudo chmod +x /etc/network/if-post-down.d/iptablessave
sudo chmod +x /etc/network/if-pre-up.d/iptablesload


Solution #3 iptables-persistent


Install and use the iptables-persistent package.



Configuration on Startup for NetworkManager



NetworkManager includes the ability to run scripts when it activates or deactivates an interface. To save iptables rules on shutdown, and to restore them on startup, we are going to create such a script. To begin, press Alt+F2 and enter this command:



For Ubuntu:



gksudo gedit /etc/NetworkManager/dispatcher.d/01firewall


For Kubuntu:



kdesu kate /etc/NetworkManager/dispatcher.d/01firewall


Then, paste this script into your editor, save, and exit the editor.



if [ -x /usr/bin/logger ]; then
LOGGER="/usr/bin/logger -s -p daemon.info -t FirewallHandler"
else
LOGGER=echo
fi

case "$2" in
up)
if [ ! -r /etc/iptables.rules ]; then
${LOGGER} "No iptables rules exist to restore."
return
fi
if [ ! -x /sbin/iptables-restore ]; then
${LOGGER} "No program exists to restore iptables rules."
return
fi
${LOGGER} "Restoring iptables rules"
/sbin/iptables-restore -c < /etc/iptables.rules
;;
down)
if [ ! -x /sbin/iptables-save ]; then
${LOGGER} "No program exists to save iptables rules."
return
fi
${LOGGER} "Saving iptables rules."
/sbin/iptables-save -c > /etc/iptables.rules
;;
*)
;;
esac


Finally, we need to make sure NetworkManager can execute this script. In a terminal window, enter this command:



sudo chmod +x /etc/NetworkManager/dispatcher.d/01firewall


Tips



If you manually edit iptables on a regular basis


The above steps go over how to setup your firewall rules and presume they will be relatively static (and for most people they should be). But if you do a lot of development work, you may want to have your iptables saved everytime you reboot. You could add a line like this one in/etc/network/interfaces:



  pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules


The line "post-down iptables-save > /etc/iptables.rules" will save the rules to be used on the next boot.



Using iptables-save/restore to test rules


If you edit your iptables beyond this tutorial, you may want to use the iptables-save and iptables-restore feature to edit and test your rules. To do this open the rules file in your favorite text editor (in this example gedit).



sudo sh -c "iptables-save > /etc/iptables.rules"
gksudo gedit /etc/iptables.rules


You will have a file that appears similiar to (following the example above):



# Generated by iptables-save v1.3.1 on Sun Apr 23 06:19:53 2006
*filter
:INPUT ACCEPT [368:102354]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [92952:20764374]
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
-A INPUT -j DROP
COMMIT
# Completed on Sun Apr 23 06:19:53 2006


Notice that these are iptables commands minus the iptable command. Feel free to edit this to file and save when complete. Then to test simply:



sudo iptables-restore < /etc/iptables.rules


NOTE: With iptables 1.4.1.1-1 and above, a script allow you to test your new rules without risking to brick your remote server. If you are applying the rules on a remote server, you should consider testing it with:



sudo iptables-apply /etc/iptables.rules


After testing, if you have not added the iptables-save command above to your /etc/network/interfaces remember not to lose your changes:



sudo sh -c "iptables-save > /etc/iptables.rules"


More detailed Logging


For further detail in your syslog you may want create an additional Chain. This will be a very brief example of my /etc/iptables.rules showing how I setup my iptables to log to syslog:



# Generated by iptables-save v1.3.1 on Sun Apr 23 05:32:09 2006
*filter
:INPUT ACCEPT [273:55355]
:FORWARD ACCEPT [0:0]
:LOGNDROP - [0:0]
:OUTPUT ACCEPT [92376:20668252]
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -j LOGNDROP
-A LOGNDROP -p tcp -m limit --limit 5/min -j LOG --log-prefix "Denied TCP: " --log-level 7
-A LOGNDROP -p udp -m limit --limit 5/min -j LOG --log-prefix "Denied UDP: " --log-level 7
-A LOGNDROP -p icmp -m limit --limit 5/min -j LOG --log-prefix "Denied ICMP: " --log-level 7
-A LOGNDROP -j DROP
COMMIT
# Completed on Sun Apr 23 05:32:09 2006


Note a new CHAIN called LOGNDROP at the top of the file. Also, the standard DROP at the bottom of the INPUT chain is replaced with LOGNDROPand add protocol descriptions so it makes sense looking at the log. Lastly we drop the traffic at the end of the LOGNDROP chain. The following gives some idea of what is happening:





  • --limit sets the number of times to log the same rule to syslog





  • --log-prefix "Denied..." adds a prefix to make finding in the syslog easier





  • --log-level 7 sets the syslog level to informational (see man syslog for more detail, but you can probably leave this)





Disabling the firewall


If you need to disable the firewall temporarily, you can flush all the rules using



sudo iptables -F


or create a script using text editor such as nano



sudo nano -w /root/fw.stop


echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT


Make sure you can execute the script



sudo chmod +x /root/fw.stop


You can run the script



sudo /root/fw.stop
Continue Reading »

Thursday, October 25, 2012

Routing for multiple uplinks/providers

A common configuration is the following, in which there are two providers that connect a local network (or even a single machine) to the big Internet.

                                                                 ________
+------------+ /
| | |
+-------------+ Provider 1 +-------
__ | | | /
___/ \_ +------+-------+ +------------+ |
_/ \__ | if1 | /
/ \ | | |
| Local network -----+ Linux router | | Internet
\_ __/ | | |
\__ __/ | if2 | \
\___/ +------+-------+ +------------+ |
| | | \
+-------------+ Provider 2 +-------
| | |
+------------+ \________


There are usually two questions given this setup.



4.2.1. Split access



The first is how to route answers to packets coming in over a particular provider, say Provider 1, back out again over that same provider.



Let us first set some symbolical names. Let $IF1 be the name of the first interface (if1 in the picture above) and $IF2 the name of the second interface. Then let $IP1 be the IP address associated with $IF1 and $IP2 the IP address associated with $IF2. Next, let $P1 be the IP address of the gateway at Provider 1, and $P2 the IP address of the gateway at provider 2. Finally, let $P1_NET be the IP network $P1 is in, and $P2_NET the IP network $P2 is in.



One creates two additional routing tables, say T1 and T2. These are added in /etc/iproute2/rt_tables. Then you set up routing in these tables as follows:



	  ip route add $P1_NET dev $IF1 src $IP1 table T1
ip route add default via $P1 table T1
ip route add $P2_NET dev $IF2 src $IP2 table T2
ip route add default via $P2 table T2

Nothing spectacular, just build a route to the gateway and build a default route via that gateway, as you would do in the case of a single upstream provider, but put the routes in a separate table per provider. Note that the network route suffices, as it tells you how to find any host in that network, which includes the gateway, as specified above.

Next you set up the main routing table. It is a good idea to route things to the direct neighbour through the interface connected to that neighbour. Note the `src' arguments, they make sure the right outgoing IP address is chosen.



	    ip route add $P1_NET dev $IF1 src $IP1
ip route add $P2_NET dev $IF2 src $IP2

Then, your preference for default route:

	    ip route add default via $P1

Next, you set up the routing rules. These actually choose what routing table to route with. You want to make sure that you route out a given interface if you already have the corresponding source address:

	    ip rule add from $IP1 table T1
ip rule add from $IP2 table T2

This set of commands makes sure all answers to traffic coming in on a particular interface get answered from that interface.

Warning



Reader Rod Roark notes: 'If $P0_NET is the local network and $IF0 is its interface, the following additional entries are desirable:



ip route add $P0_NET     dev $IF0 table T1
ip route add $P2_NET dev $IF2 table T1
ip route add 127.0.0.0/8 dev lo table T1
ip route add $P0_NET dev $IF0 table T2
ip route add $P1_NET dev $IF1 table T2
ip route add 127.0.0.0/8 dev lo table T2

'

Now, this is just the very basic setup. It will work for all processes running on the router itself, and for the local network, if it is masqueraded. If it is not, then you either have IP space from both providers or you are going to want to masquerade to one of the two providers. In both cases you will want to add rules selecting which provider to route out from based on the IP address of the machine in the local network.



4.2.2. Load balancing



The second question is how to balance traffic going out over the two providers. This is actually not hard if you already have set up split access as above.



Instead of choosing one of the two providers as your default route, you now set up the default route to be a multipath route. In the default kernel this will balance routes over the two providers. It is done as follows (once more building on the example in the section on split-access):



	    ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \
nexthop via $P2 dev $IF2 weight 1

This will balance the routes over both providers. The weight parameters can be tweaked to favor one provider over the other.

Note that balancing will not be perfect, as it is route based, and routes are cached. This means that routes to often-used sites will always be over the same provider.



Furthermore, if you really want to do this, you probably also want to look at Julian Anastasov's patches at http://www.ssi.bg/~ja/#routes , Julian's route patch page. They will make things nicer to work with.

Continue Reading »