Installing node.js on Fedora
Hi,
Today I tried to install node.js on my Fedora and I got stuck after issuing ./configure command:
[..]error: could not configure a cxx compiler!
I have to admit that I was rather surprised because I have already installed gcc and cpp packages. What was actually missing was this: gcc-c++.
You can get it with:
yum install gcc-c++
Running ./configure again and... next stop:
error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are installed. Use configure --without-ssl to disable this message.
This time it was fixed by installing openssl-devel package with
yum install openssl-devel
That's it, now you should have working node.js
Go nuts! ;)
(archive) GitLab installation on Fedora 16 (with gitolite)
This is old version of my tutorial. Most recent version can be found here
GitLab is a wonderful piece of software made by these guys and I'd like to try and install it on Fedora 16 system, as it is most recent Fedora OS at the time I am writnig this. I will base my tutorial on on found here by Déja. Also on my way to successful install I've stumbled upon this description, so I might have gain some experience from it too.
GitLab is Ruby on Rails application and it takes some experience to get it all working because of many, many, many dependencies and packages it needs. It's nothing like simple PHP on Apache installation. But it works and it's worth it, I assure you :)
Let's begin! (by the way: I perform all as root user - again: test environment)
small edit: For people who only want this to work and not necessarily wish to know how and why, I have prepared easy installation scripts in here
- First of all: I am working on virtual machine with brand new and fresh Fedora 16 installed. Minimal installation, just to make sure nothing messes with GitLab. Consider this a test environment.
- Once you have your OS ready, update it with yum update and also install some packages you will need on the way:
yum install make openssh-clients gcc libxml2 libxml2-devel \ libxslt libxslt-devel python-devel
- Check what version of ruby is available via yum. GitLab needs at least version 1.9.2
yum info ruby
on mine it says that the only available version for me is 1.8.7.35 so I have to get it somewhere else.
- Method #1.
I will do as it says here. I have tried it before and it works flawlessly. With one or two catches of course ;)Mentioned catches and tips:- you need wget, if you don't have it already use
yum install -y wget
- other needed packages (plus few dependencies) can be obtained by typing:
yum install -y readline-devel ncurses-devel gdbm-devel \ glibc-devel tcl-devel openssl-devel db4-devel byacc
- if you are using virtual machine, like me, you can first make a snapshot of it, then build ruby RPM package, copy it to you host machine (or network share or whatever place outside virtual machine) and then go back in time to you snapshot. Voila! Clean system ready for further installing GitLab. All you need to do is install earlier created ruby RPM. Anyway this is what I'm gonna do today. Keep it clean.
- last step - your RPM will end up somewhere in ~/rpmbuilds/RPMS directory. It will reside in folder named after your system architecture, in my case: i386
And here is how:
yum install -y rpm-build rpmdevtools rpmdev-setuptree cd ~/rpmbuild/SOURCES wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz cd ~/rpmbuild/SPECS curl https://raw.github.com/imeyer/ruby-1.9.2-rpm/master/ruby19.spec > ruby19.spec rpmbuild -bb ruby19.spec rpm -Uvh ~/rpmbuild/RPMS/x86_64/ruby-1.9.2p290-2.ruby-1.9.2p290-2.i386.rpm
I took my VM about 4 minutes to compile and prepare RPM. Not so bad.
Now I go back in time in my VM and install newly created RPM withrpm -Uvh ruby-1.9.2p290-2.fc16.i386.rpm
- you need wget, if you don't have it already use
- Method #2. ( I prefer this one so far)
EDIT: I have switched to ruby 1.9.3p0 - it works and starts a lot faster, you can use it instead of 1.9.2-p290 in this guide.
I will use RVM, which stands for Ruby Version Manager - brilliant tool, which you can use to install and manage your Ruby with ease. Let's check it out, shall we?
sudo bash -s stable < <(curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) source /etc/profile.d/rvm.sh rvm install ruby-1.9.2-p290 rvm use ruby-1.9.2-p290 --default
Done. Just like that we have operational Ruby 1.9.2-p290. No RPMs, bo going back in time.. nice, huh? :)
- Good. Small (nice) surprise: our RPM installed ruby gems for us, so now we only have to get rails gem.
first, just to make sure everything is up to date, execute:gem update --system
now install rails with:
gem install rails
- Now we will install apache2 as a webserver and Passenger for ruby apps deployment. I know that most GitLab tutorials use nginx but I really like apache ;)
yum install -y httpd
gem install passenger
as I mentioned: I use apache, so I will need passenger module for it:
first some required packages:yum install gcc-c++ curl-devel openssl-devel zlib-devel \ httpd-devel apr-devel apr-util-devel
an then use
passenger-install-apache2-module
in order to install it.it gives you 2 information on how to proceed with apache configuration:
- add following lines to /etc/httpd/conf/httpd.conf (at the very end):
LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11 PassengerRuby /usr/bin/ruby
- and then create file named default.conf (or gitlab.conf, or something other you fancy) in /etc/httpd/conf.d/ containing these lines (remember to change to fit your environment):
<VirtualHost *:80> ServerName www.yourhost.com DocumentRoot /somewhere/public <Directory /somewhere/public> AllowOverride all Options -MultiViews </Directory> </VirtualHost>
(don't worry, we'll come back to this one later)
- add following lines to /etc/httpd/conf/httpd.conf (at the very end):
- Now it is time for gitolite. I won't use gitosis because it is not actively developed any more and I found that new GitLab works better with gitolite.install it with
yum install -y gitolite
now, wasn't that quick? :)
- Now we will need to create new gitolite server configuration and in order to do that we have to generate SSH key-pair. But first things first.
To get us started su into gitolite user withsu - gitolite
now try to log into localhost via SSH -> it's small thing which will make our life easier in the future.
ssh localhost
Just make it add localhost to list of known host - no need to actually authenticate. SSH created for us ~/.ssh directory. That's nice.SSH key generation is as easy as:
ssh-keygen -t rsa
use default path for saving key-pair (/var/lib/gitolite/.ssh/id_rsa) and no paraphrase. Test environment. Just a reminder.as for initialization of gitolite repository:
gl-setup .ssh/id_rsa.pub
next hit ENTER and edit will open, change value of
$REPO_UMASK to 0007
as mentioned hereLook like we are done here. Exit gitolite user shell and return to being almighty root himself ;)
- OK, time for next requirements: python Pip, I will go with method from original post and NOT use yum for that.
curl http://python-distribute.org/distribute_setup.py | python
and then
easy_install pip
- Database. We need it. We have it already - it was installed on the way as a dependency. Just to make sure check if you have SQLite at list version 3.6 with:
yum info sqlite
I have 3.7.7.1. All we need is SQLite development package, get it with:
yum install sqlite-devel
-
And now the main event! GitLabHQ!
I like install web apps in /var/www so we will go there and git clone GitLab:
cd /var/www git clone git://github.com/gitlabhq/gitlabhq.git cd gitlabhq/
we need to use pip to install some python dependencies:
pip install pygments
and bundler gem so it can later on do most of the work for us:
gem install bundler
finally (remember to be in GitLab directory):
bundle install
(go get yourself a coffee or other treat - it takes w while)
- DB setup:
EDIT: For GitLab version 2.1 install Redis - without it rake will fail.:
yum install redis libicu-devel service redis start
And now database setup and import:
RAILS_ENV=production rake db:setup RAILS_ENV=production rake db:seed_fu
TIP: if you get errors here, check if you don't have 2 versions of rake installed (I had somehow): 0.8.7 and 0.9.2. If you do, remove older with:
gem uninstall rake
and choose appropriate version. If you still have problems try:
gem install rake
-> don't know why, but if it installs again same version of rake, it works.
- Apache virtual host configuration should look something like this (I told you, we will get back to that):file: /etc/httpd/conf.d/gitlab.conf
<VirtualHost *:80> ServerName www.yourhost.com DocumentRoot /var/www/gitlabhq/public <Directory /var/www/gitlabhq/public> AllowOverride all Options -MultiViews </Directory> </VirtualHost>
- set correct settings in /var/www/gitlabhq/config/gitlab.yml
in my case:# Git Hosting configuration
git_host: system: gitolite admin_uri: gitolite@localhost:gitolite-admin base_path: /var/lib/gitolite/repositories/ host: localhost git_user: gitolite # port: 22
- enable apache user, co you can su into this account:
usermod -s /bin/bash -d /var/www/ apache
also give him permissions to his own home directory with:
chown -R apache:apache /var/www/
(I know this kinda overrides last chown command...)
- do:
su - apache && ssh localhost
(same thing as in step 8. with know_hosts file. )
exit apache's shell and as root copy id_rsa private key from /var/lib/gitolite/.ssh/ to /var/www/.ssh/ and make apache it's owner with:cp -f /var/lib/gitolite/.ssh/id_rsa /var/www/.ssh/ \ && chown apache:apache /var/www/.ssh/id_rsa \ && chmod 600 /var/www/.ssh/id_rsa
- add apache user to gitolite group with:
usermod -a -G gitolite apache
- check if repositories directory has correct permissions, it should be 770. You can set it with
chmod 770 /var/lib/gitolite/repositories/
- double check your firewall (for example iptables) if it allows connections on port 80 to your server.
- start apache server with:
service httpd start
- Now it all should work. Fingers crossed.. go to http://www.yourhost.com
- Now you should be able to log in using these credentials:
user: admin@local.host
pass: 5iveL!feand you're in :)
It wasn't so hard, wasn't it? ;)
Troubleshooting:
- I get error 500 when I enter particular project and try to get into it's "Admin" section. Don't know how to fix it yet.To fix it, check if repositories directory has correct permissions, it should be 770. You can set it with
chmod 770 /var/lib/gitolite/repositories/
- If Passenger insists, that we don't have or he can't see grit library (gem actually, as far as I know) even though we have it.
https://github.com/gitlabhq/grit.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError)
I didn't have gem grit installed, do:
gem install grit
also it won't hurt to update all gems with:
gem update
Only resolution to this problem I have found is to run bundle again as a user who runs apache server: apache.Su into apache account with
su - apache
and try:
gem install grit
you'll get error:
You don't have write permissions into the /usr/lib/ruby/gems/1.9.1 directory.
As root change it's ownership to apache user with:
chown apache:root -R /usr/lib/ruby/gems
I know that is not great resolution but it worked for me. If you'll happen to know better way - please let me know, so I can update this tutorial and my knowledge of course ;)
Edit
I found another solution (instead of changing permissions): after first
bundle install
edit Gemfile and in lines containing "git:" remove everything after first comma, for example:
gem "grit", :git => "https://github.com/gitlabhq/grit.git"
should be
gem "grit"
then do again
bundle install
and now passenger shouldn't complain any more.
dnsmasq – DNS and DHCP server
Dnsmasq is a simple server providing the DNS and DHCP services for a local area network (LAN) and as its creator say - it will be working very well on home networks and small business environments, up to roughly 1000 workstations. More information about it in the author's website: http://www.thekelleys.org.uk/dnsmasq/doc.html
- But why?
Good question. As a rule, if you already have a local network at home, then your are probably used to moving around it either by using computer's IP addresses using the local environment of Windows and the names of workstations in the work group. The latter is quite comfortable, but will work only in networks with Windows operating systems, maybe also with different Unix's or Linux's, but this in turn requires the configuration of the Samba server, which is beyond the scope of this text.
Now let's think how beautiful it would have been if, instead of IP addresses, each computer was recognized by its unique name, just like web pages. This would also include network printers, routers and other devices. This is what dnsmasq can do for us. It will allow us to find any of network devices receiving IP addresses automatically via DHCP or statically added to server configuration.Instead of seeking to enter the network share:
\\192.168.0.4\share
Type:
\\our.server.domain\shareEasier to remember, right? Now, if the address of a machine identified as "our.server" changes, we do not even need to know present IP address, because dnsmasq will guide us to him flawlessly.
Now that we know what we might use it for... let's get started! :)
- Installation
Installation depends on the environment in which we work, I will focus on Linux, and specifically on the two most popular distributions: Fedora (as well as Red Hat, Centos) and Debian (Ubuntu and other Debian like). For installation you will need root privileges. You can either log on as root, or add before each following command: sudo
For example: sudo yum update- Fedora
use command:
yum update (in case there are updated packages for our system)
yum install dnsmasq - Debian
use command:
aptitude update && aptitude safe-upgrade (in case there are updated packages for our system)
aptitude install dnsmasq
- Fedora
- The configuration file is called dnsmasq.conf and is located in /etc directory.
In addition, dnsmasq uses /etc /hosts as a source of information about the hosts with statically assigned IP addresses, that is those not assigned by the DHCP and /etc /resolv.conf - thus receives information about DNS servers, which it will use.
It is very well documented in the configuration file comments, so I'll skip the detailed instructions, but I will focus on several options that are needed to start with.- domain-needed - means that dnsmasq will forward only dns queries that have a domain name in the address
- bogus-priv - means that dnsmasq will forward only dns queries that are in routable IP ranges
- interface = {eth0, eth1, ...} - if you have more than one network interface, you can make dnsmasq listen only on one of them
- except-interface = {eth0, eth1, ...} as well as earlier but dnsmasq should listen on all interfaces except the specified
- expand-hosts - tells dnsmasq to add your domain to the host's name and works in conjunction with variable domain
- domain - your domain name
- dhcp-range = 192.168.0.30,192.168.0.40,24 h - used to activate the DHCP server and setting the scope of the assigned addresses to 192.168.0.30-40 and time of lease (rent) for 24 hours. If we have two subnets (VLANs or two network cards), we can define the variables twice, provided that dnsmasq is configured to listen on both interfaces
- dhcp-host = 00:11:22:33:44:55,192.168.0.36 - definition of the host, which on each connection should have the same IP address. Host authentication is done using the hardware address of network adapter MAC. In our case, the host with MAC address 00:11:22:33:44:55 will always receive the address of 192.168.0.36
- Setting these values will allow us to start using dnsmasq on our network and enjoy host names instead of IP addresses.
- Additional Information
- entries in /etc/hosts look as follows:
IP_address hostname
For example: 192.168.0.21 Server - entries in /etc/resolv.conf look like:
nameserver IP_address
For example: nameserver 194.204.152.34 - in case of dnsdomainname errors while restarting dnsmasq service you should check the file /etc/hosts.
The entry for 127.0.0.1 localhost should contain additionally your_server.your_domain entry, for example:
127.0.0.1 localhost server.domain.com
After that you may need the restart of the system or network services. - in the case of Fedora, and other Red Hat like: in /etc/sysconfig/network should be an entry:
HOSTNAME = your_serever.your_domain.com - if hosts with IP addresses statically defined could also use dnsmasq DNS server, you must replace their existing DNS servers to the IP address of our server that is running dnsmasq.
- entries in /etc/hosts look as follows:
Zadania Cron wszystkich użytkowników
Czasem pojawia się potrzeba wyświetlenia zadań Cron wszystkich użytkowników w systemie.
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done |
A dla konkretnego użytkownika można zastosować polecenie:
for user in $(cut -f1 -d: /etc/passwd | grep USER); do crontab -u $user -l; done |
gdzie, USER = nazwa szukanego użytkownikaCzasem pojawia się potrzeba wyświetlenia zadań Cron wszystkich użytkowników w systemie.
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done |
A dla konkretnego użytkownika można zastosować polecenie:
for user in $(cut -f1 -d: /etc/passwd | grep USER); do crontab -u $user -l; done |
gdzie, USER = nazwa szukanego użytkownika
Squid transparent proxy
Squid ( http://www.squid-cache.org ) jest oprogramowaniem umożliwiającym filtrowanie ruchu sieciowego, ale nie był to początkowy zamysł jego twórców. Z założenia Squid miał umożliwić tworzenie pamięci podręcznej treści ( grafik itp. ) pobieranych z Internetu przez użytkowników w czasie serfowania po nim.
Jedną z możliwości oferowanych przez Squid jest filtrowanie stron jakie moga odwiedzać użytkownicy znajdujący się w naszej sieci.
Więc po kolei :)
Zwyczajowo, to znaczy domyślnie, Squid korzysta z portu 3128, ale na nasze potrzeby to nie jest wystarczające. Dlaczego? Oznacza to, że jak już wszystko skonfigurujemy, ustawimy i będzie działało to i tak niewiele nam po tym, bo użytkownicy naszej sieci będą musieli dobrowolnie ustawić w swoich przeglądarkach ustawienia adresu naszego serwera Squid oraz portu. Przyznam szczerze, że jakoś nie widzę u nich zachwytu, kiedy zorientują się, że owocuje to niczym więcej poza ograniczeniami nałożonymi przez nas. I tutaj nadchodzi czas na wytłumaczenie drugiego słowa z tytułu niniejszego artykułu: transparent. Jest to magiczne słowo oznaczające "przezroczysty". Co to oznacza dla nas? W największym uproszczeniu cały ruch sieciowy WWW zostanie domyślnie przekierowany tak, aby przechodził przez nasz serwer proxy Squid i to w dodatku bez potrzeby żadnej konfiguracji po stronie użytkowników, a co więcej - nie będą mogli nic na to poradzić :)
Oczywiście można ustawić proxy korzystając wyłącznie z domyślnego trybu Squid'a i wymusić na użytkownikach korzystanie z niego ( czyli przymus konfiguracji przeglądarki ) na zasadzie: nie skonfigurujesz - nie masz dostępu do stron WWW. Uważam, że takie rozwiązanie jest nieeleganckie i dużo bardziej kłopotliwe w praktyce. O wiele łatwiej sterować dostępem centralnie, na naszym serwerze, w konfiguracji Squid'a.
Po tym przydługim wstępie zabieramy się do pracy :)
1. Usługę Squid proxy stawiamy najlepiej na serwerze pełniącym rolę bramy ( ang. Gateway ) ale nie koniecznie. Na potrzeby tego artykułu przyjmę, że będzie ona zainstalowana właśnie na serwerze - bramie. Dodam, że
2. Instalacja odbywa się w sposób standardowy, z paczek binarnych właściwych dla naszej dystrybucji Linux'a lub ewentualnie ( czego osobiście nie praktykuję ) dla Windows'a. Instalacja opisana jest dokładnie tutaj i nie wchodzi w zakres tego artykułu, chyba, że zaistnieje taka potrzeba, żeby go o te informacje wzbogacić.
3. Konfiguracja usługi Squid odbywa się poprzez edycje pliku /etc/squid/squid.conf ( dla Debian'a, lub analogicznie w przypadku innych dystrybucji Linux'a ).
UWAGA: opcje są wczytywane po kolei od początku pliku konfiguracyjnego do końca!
Jest to ważne, ponieważ można się łatwo pogubić i doszukiwać przyczyny nie działania zdefiniowanych przez nas filtrów, ale to wyjdzie w praktyce.
Najpierw należy definiować zasady szczegółowe, a potem ogólne, ponieważ Squid bierze pod uwagę pierwszą regułę jaką napotka i nie szuka dalej, więc jeśli najpierw umieścimy pozwolenie na dostęp dla wszystkich, a potem zasady szczegółowe, to zostaną one zignorowane, ponieważ Squid "zadowoli" się regułką ogólną, którą napotkał wcześniej w pliku konfiguracyjnym.
4. Pierwszą rzeczą jaką należy ustawić jest kto z naszej sieci będzie miał dostęp do usługi Squid, czyli inaczej mówiąc czyj ruch będzie filtrowany i kto nie zostanie zablokowany całkowicie :)
acl moja_siec src X.X.X.0/24 http_access allow moja_siec |
gdzie X.X.X.0/24 to nasza sieć, np. 10.0.1.0/24
Ten zapis pozwoli wszystkim komputerom w naszej sieci na korzystanie ze Squid'a. To nie do końca jest nasz cel, ponieważ na tym etapie konfiguracji wszystko będzie śmigało bez żadnych ograniczeń w tę i z powrotem bez żadnej kontroli.
5. Teraz pora na kilka ograniczeń :)
Najlepiej ustawiać ograniczenia za pomocą odpowiednich plików konfiguracyjnych z listami domen WWW, np:
domeny zabronione: /etc/squid/domeny_zabronione
domeny w tym pliku umieszczamy po jednej w każdej linijce.
w pliku konfiguracyjnym Squid przed ( czyli wyżej, jak kto woli ) poprzednimi wpisami definiującymi dostęp dla całej sieci, dodajemy linijki:
acl domeny_zabronione dstdomain -i "/etc/squid/domeny_zabronione" http_access denydomeny_zabronione |
to spowoduje, że żaden komputer w naszej sieci nie będzie mógł otworzyć stron zdefiniowanych w tym pliku.
6. A teraz troszkę dokładniejszej konfiguracji :)
Załóżmy, że mamy w sieci jakiś komputer, który ma mieć inne zasady dostępu do sieci niż pozostałe, np. nie móc wejść na konkretną stronę, powiedzmy www.strona1.com, wtedy jeszcze wcześniej niż poprzednia definicja należy dodać:
acl blokowany_komputer src X.X.X.21 acl lista_domen dstdomain -i "/etc/squid/lista_domen" http_access deny blokowany_komputer lista_domen |
a adres www.strona1.com umieścić w pliku /etc/squid/lista_domen
i już :)
przypominam jeszcze raz o kolejności wpisów w pliku konfiguracyjnym Squid'a.
7. Ostatnie szlify ( prawie )
Aby sprawić by Squid zachowywał się jako transparent, czyli przezroczysty należy dopisać jeszcze te opcje:
http_port 127.0.0.1:3128 transparent http_port X.X.X.X:3128 transparent |
gdzie X.X.X.X jest adresem naszego serwera, na którym zainstalowany jest Squid
8. Teraz już naprawdę ostatnie ustawienia :)
Pozostało ustawienie reguły iptables, tak aby kierowała cały ruch z portu 80 i 443, domyślnych dla stron WWW, na port 3128 Squid'a.
W moim przypadku trzeba skonfigurować ShoreWall, który zarządza regułami iptables:
w /etc/shorewall/rules
ACCEPT $FW net tcp www REDIRECT loc 3128 tcp www |
w przypadku zwykłego iptables:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128 iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 3128 |
9. No i restart usługi: /etc/init.d/squid restart ( lub analogicznie dla innych dystrybucji )
iptables i blokowanie stron WWW
Dzisiaj zajmiemy się kwestią czasem bardzo potrzebną, to znaczy blokowaniem użytkownikom sieci lokalnej dostępu do konkretnych serwisów internetowych. Chodzi o sytuację, kiedy chcemy zablokować możliwość "wchodzenia" tylko na niektóre strony a nie odwrotnie, to znaczy zezwolić tylko na niektóre, a zablokować domyślnie wszystkie.
Dodatkowym założeniem naszego projektu będzie to, że ruch zostanie przekierowany i użytkownik zamiast trafić na stronę typu chomikuj.pl trafi na inną, zdefiniowaną przez nas, np. google.pl lub naszą stronę firmową.
Można to osiągnąć za pomocą tablicy PREROUTING w iptables:
iptables -t nat -A PREROUTING -p tcp -s JAKAŚ_SIEĆ_LOKALNA \ -d ADRES_DOCELOWY --dport 80 -j DNAT --to ADRES_PRZEKIEROWANIA:80 |
i teraz tak:
JAKAŚ_SIEĆ_LOKALNA - nasza siec lokalna, np. 192.168.1.0/24
ADRES_DOCELOWY - adres IP strony, na która chce wejść użytkownik
ADRES_PRZEKIEROWANIA - adres IP, na jaki dostanie się użytkownik w wyniku działania naszej regułki
Wszystko pięknie i w ogóle, ale jak to zrobić jeśli adres, np rapidshare.com ma więcej niż jeden adres IP? tutaj z pomocą przychodzi BASH i skrypt w nim napisany, który wykonuje 2 rzeczy:
- zamienia adres domeny ( taki słowny ) na adres IP ( lub więcej adresów, jeśli takowe występują ). Czyni tę magię za pomocą polecenia host -t a NAZWA_DOMENY oraz pętli FOR
- dla każdego odnalezionego adresu stosuje regułkę, którą opisałem wcześniej, również za pomocą pętli FOR
Żeby Was nie męczyć postanowiłem taki skrypt w BASH'u przygotować. Nie jest może perfekcyjny, ale z pewnością spełnia swoje przeznaczenie i jest wygodny w użyciu :) ( dla chętnych skrypt można ściągnąć tutaj ). Skrypt zamieszczam do wglądu poniżej, ale radzę nie kopiować ( albo robić to rozważnie), ponieważ mogą powstać nieścisłości wynikające z operacji kopiuj/wklej...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #!/bin/bash TRYB=$1 #zmienne skryptu SIEC="192.168.1.0/24" #siec lokalna, ktora ma nie meic dostepu do nizej wymienionych stron PORT="80" #port 80 = WWW PRZEKIEROWANIE_NA="209.85.135.147" #ustawilem domyslne przekierowanie na strone Google PORT_NA="80" #jak wyzej LISTA_STRON="chomikuj.pl wrzuta.pl rapidshare.com megaupload.com" #lista oddzielona spacjami #domyslnie nie sa wyswietlane reguly w czasie dzialania programu VERBOSE="0" if [ -n $2 ]; then VERBOSE=$2 fi case $TRYB in "on") if [ -n "$LISTA_STRON" ]; then for STRONY in ${LISTA_STRON}; do if [ "$VERBOSE" = "1" ]; then echo $STRONY fi ADRESY=$(host -t a $STRONY | awk '{ printf "%s ", $4 }') if [ -n "$ADRESY" ]; then for STRONY_IP in ${ADRESY}; do if [ "$VERBOSE" = "1" ]; then echo "iptables -t nat -A PREROUTING -p tcp -s $SIEC -d $STRONY_IP --dport $PORT -j DNAT --to $PRZEKIEROWANIE_NA:$PORT_NA" fi iptables -t nat -A PREROUTING -p tcp -s $SIEC -d $STRONY_IP --dport $PORT -j DNAT --to $PRZEKIEROWANIE_NA:$PORT_NA done fi if [ "$VERBOSE" = "1" ]; then echo "" fi done fi ;; "info") iptables --list PREROUTING -t nat ;; "off") iptables --flush PREROUTING -t nat ;; "-h") echo "Program przyjmuje zmienne: " echo "-h pomoc" echo "on wlaczenie regul" echo "off wylaczenie regul" echo "info informacje o regulach" echo "0/1 w trybie 'on' ukrywanie/wyswietlanie komunikatow" echo "usage: ./blokowanie_stron on 1" ;; *) echo "Nie podano zmiennej trybu. (on/off/info)" exit ;; esac |