Programação, linux e afins. Thu, 23 Feb 2017 12:57:47 +0000 en-US hourly 1 What is Iptables, what it’s for, and how to use? Sat, 01 Nov 2014 22:00:52 +0000 […]

O post What is Iptables, what it’s for, and how to use? apareceu primeiro em


After a long time, I finally had some time to write again, and this time I intend to keep a periodicity. The reason for my absence? Well now I have Dom

Without further ADO, let’s get to the point, what is Iptables, to that server, and where do I use it?

What is Iptables?

According to the simple description of the creator of this package ( NetFilter ), Iptables is a tool to create and administer rules and filter network packets.

The iptables can work based on address, source port, destination of the package, priority. It works by comparing rules to determine whether a packet is allowed to pass or not. In more restrictive firewalls, the packet is blocked and logged so that the system administrator has knowledge about what’s going on in your system.

To that server?

With Iptables, you can redirect ports , change a Protocol (such as ssl3 for tls1), Redirect servers, and services. You can create rules to block users on the network, blocking access, services for certain ips, among many other services.

Directions for use

The most common way of using the command is:

iptables [-t table] chain rule-specification

among the options you can use:

  • -P = Defines a default rule;
  • -A = Add a new rule existing ones. This takes precedence over the-P;
  • -D = Delete a rule;
  • -L = List the existing rules;
  • -S = List the existing rules, the way was saved by iptables;
  • -E = Renames a chain (chain)
  • -F = clears all the rules;
  • -I = insert a new rule;
  • -h = Displays the help;
  • -R = replace a rule;
  • -C = Makes the checking of existing rules;
  • -Z = Resets a specific rule;
  • -N = Creates a new rule with a name;
  • -X = Deletes a specific rule by name.

Each has its specific use, and a way to use. To see all just use:

man iptables

Common commands of Iptables

Delete rule


Block an IP

iptables-A INPUT-s ""-j DROP

If you want to block for a specific interface, simply pass the parameter-i , staking so:

iptables-A INPUT-i eth0-s ""-j DROP

Open door to specific ips

In this example I used the door of ssh as an example, but it could be used any

iptables-A INPUT-i eth0-p tcp-s 22-m state--state NEW, ESTABLISHED-j ACCEPT-


Balancing the 443 port between 3 different ips

iptables-A PREROUTING-i eth0-p tcp--dport 443-m state-state NEW-m-nth--counter-0-every 3-0-packet-j DNAT--to-destination 443
iptables-A PREROUTING-i eth0-p tcp--dport 443-m state-state NEW-m-nth--counter-0-every 3-1-packet-j DNAT--to-destination 443
iptables-A PREROUTING-i eth0-p tcp--dport 443-m state-state NEW-m-nth--counter-0-every 3--2-j DNAT-packet-to-destination 443

Enable Access to mysql by local network

iptables-A INPUT-i eth0-p tcp-s 3306-m state-state NEW-, ESTABLISHED-j ACCEPT
iptables-A OUTPUT-o eth0-p tcp--sport-3306-m state-state ESTABLISHED-j ACCEPT

Blocking DDOS attacks

iptables-A INPUT-p tcp--dport 80-m limit-limit 25/minute-100 no limit-burst-j ACCEPT

Redirecting port

iptables-t nat-A PREROUTING-p tcp-d DNAT--dport-422--to 22


The Geek Stuff
Server Fault

O post What is Iptables, what it’s for, and how to use? apareceu primeiro em

]]> 0
How to send a POST request without form Wed, 12 Feb 2014 20:45:05 +0000 […]

O post How to send a POST request without form apareceu primeiro em

There are ways to send a POST request to a page, between the more usual HTML submit a form

Assuming that you want to send information to another page, you would do the following:

PHP Code

<form name='ViniciusTest' method='POST' action='make_action.php'>
<input type='hidden' name='field1' value='Value1'>
<input type='text' name='field2'>
<input type='text' name='field3'>
<input type='submit'>

But what if you wanted to send it directly by PHP without passing it by the user accessing the application?

I’ve seen a lot of “ workaround ” to do such a simple thing, the company where I am now (Netmake ), it’s incredible imagination to do so.

Well, there are several ways to do this, not saying that there is the right and wrong … but there are certainly simple.

Simple Shapes

The same as the above HTML code would submit, you could use the code:

$content = http_build_query (array (
'field1' => 'Value1',
'field2' => 'Value2',
'field3' => 'Value3'

$context = stream_context_create (array (
'http' => array (
'method' => 'POST',
'content' => $content,

$result = file_get_contents('http://exemplo/make_action.php', null, $context);

Explaining the code

The first line code

$content = http_build_query(array(
, the http_build_query says as php Gera’s own documentation the query string (query) in URL format , in short, the function will transform an array of data, in a form of query, in case it would be something like:


In the sixth line we find the stream_context_create , we will create a streaming context, ie the request will prepare the same way as is done by the browser before sending to php when we submit the form.

And finally the file_get_contents , one of my favorite features in php (already swept much to her site). She will make the request for the page, in case http://exemplo/make_action.php , sending the generated context in stream_context_create , and will take the output of the page and putting in $ variable result;

Simple huh? This is my favorite way, however there are others, if you are interested search for curl

If you wish to receive more information and tips on PHP and linux, subscribe to our list here ! In the next post to learn some tips on writing and reading files with only two functions and a very easy way. If liked, like the one on the page, and / or comment below.

O post How to send a POST request without form apareceu primeiro em

]]> 3
TTY: How to reduce the number of terminals and increase performance Fri, 07 Feb 2014 20:26:34 +0000 […]

O post TTY: How to reduce the number of terminals and increase performance apareceu primeiro em

As we saw in the last article TTY: What is? What’s the use? . If you think you do not need as many TTY as those available by default in your environment. I agree, and it affects a little performance of your linux .. but rather it. Certainly for those who need the full potential of a machine that will make a difference.

There are ways you can decrease the amount of TTY of their distribution here will decline to 3 the device files , if you want to you can change as you wish, just following the logic, and steps.


To get access to the console root and edit the file /etc/default/console-setup. I like to use the nano to edit files on the command line. But the use of your own, if you do not have nano, try the pico.

+5 nano /etc/default/console-setup

The +5 is already to begin with the cursor on line 5, which on ubuntu (at least in my ubuntu 13.10 ) is the line that we will edit. If it is not in his use ctrl + w to find, and good luck!


You’ll find something like:

ACTIVE_CONSOLES = "/dev/tty[1-6]"

Change to:

ACTIVE_CONSOLES = "/dev/tty[1-3]"

Thus altered the amount of TTY 3.

Then go to the directory /etc/init/, and move the files to another tty place, or rename them.

mv tty4.conf tty4.conf.bkp
mv tty5.conf tty5.conf.bkp
mv tty6.conf tty6.conf.bkp

Restart your operating system, and it will load the settings now, or will not load … Everything depends on your point of view, call your grandmother explains to her everything you read … and make an brainstorm with her.

I hope you and your grandmother enjoyed the post, and if you want to get more news about linux, php, and other related topics. Give a like page on facebook here , and sign up for our list here , and comment if you liked and did not like it too!

O post TTY: How to reduce the number of terminals and increase performance apareceu primeiro em

]]> 0
TTY: What is? What’s the use? How to use it? Mon, 03 Feb 2014 23:27:54 +0000 […]

O post TTY: What is? What’s the use? How to use it? apareceu primeiro em

Very simple, TTY is an abbreviation for teletypewriter. Do not understand? You for sure have used .. If you use linux .. if you do not close that uses your internet explorer .. and look for a window to play. If you use MAC makeup and go for this PC formats. Jokes aside, TTY is when you use the shortcut key

CTRL + ALT + F #

, or even when you open a terminal on your OS.

Yes! TTY is simply a terminal to which you are connected. An interface from which you can give text commands to a machine.

In the case of terminal initiated within its interface like this:


It is a virtual TTY, which simulates a direct command interface to the OS.

Command TTY

$ tty

This command tells you what the file name connected to standard input. The term pts is the abbreviation for pseudo. If you run the command directly on a real TTY you have the following:

$ tty

The number in the command output indicates that the machine it ran on standard input is associated with that number. If you open other terminals, they are numbered sequentially 6,7 … In some distributions few tty are blocked because they are associated with a manager like modem-manager or LightDM .

Beauty and serving me? Imagine that you are using more than one terminal in its distribution, common, and you want the result of a command from a tty appears in another tty. For example the listing of a directory appears in another terminal, you can use:

ls /home > /dev/pts/6

For more on the tty command, use on your tty command:

man tty


tty - help



Subscribe to blog here to receive news and details about linux and other related software. In the next post to learn to conserve your pc memory TTY removing your computer’s unnecessary.

O post TTY: What is? What’s the use? How to use it? apareceu primeiro em

]]> 1
How to iterate through multidimensional array with php Tue, 28 Jan 2014 19:14:29 +0000 […]

O post How to iterate through multidimensional array with php apareceu primeiro em

One more tip for those who are starting in php , continuing the previous tutorial. Let us understand how to sweep a multidimensional array with php


It is much simpler than in other languages. Which you would have to put two is like talking about … In php you have the foreach , which scans the array, and iterates automatically.

Running array

assuming a return of bank that has several arrays into one another, we access to all items of that array would do the following:

 array (
foreach ($ arr_result the $ data)
 if (is_array ($ data))
   foreach ($ data as $ other_data)
    echo $ other_data, '
'; } } else { echo $ date, '
'; } }

Explaining the code

The first lines are the definition of a array , so we can make the iterations.

The online foreach parameters are the array, and $ data is the variable that will receive the value of the iteration time.

The function is_array checks if the passed parameter is either not a array .

The function echo it displays on screen the value in the near variável.Nos chapters of this novel posts, I explain why to use a comma, not concatenation. Beforehand you advise to use this form.

Recursive Function

This code would be very efficient for an array that we know the definition of size, and a small sweep.

However for a huge array with many dimensions would be an immense source, so we can use recursion.

function recursive_show_array ($ arr)
 foreach ($ arr the $ value)
  if (is_array ($ value))
    recursive_show_array ($ value);
    echo $ value;

Thus if it is array, it will call the function again and do the loop “sub-array”, thus all levels will be achieved.

You can check the functions in the php documentation:

O post How to iterate through multidimensional array with php apareceu primeiro em

]]> 0
Starting in PHP simple and easy way Tue, 28 Jan 2014 19:10:32 +0000 […]

O post Starting in PHP simple and easy way apareceu primeiro em


When I announced this blog as a technology blog. And in order to pass a piece of programming, I just never have time. For this reason, I spent this time preparing a programming related material to make up for lost time. As for reviewing’m releasing at least one post a week, with tips php javascript jquery .. among others.

Well .. without further ado, let’s start .. the beginning.

What is PHP?

There has to be a story right .. but this will be my point of view.

For me, it is an extremely useful programming language, easy to learn and a lot of processing. That despite successful applications have not had an application that uses its maximum. And on the other hand, was used in negative ways, with various “hacks” with much spaghetti code, and many logic errors, which among other things, caused her a great reputation as unsafe.

What do I need to run php?

To run it, you need a web server as apache nginx , lighttpd. A connector, which will make this web server processes the PHP code. And the php package.

Do not know how to install the web server? You can check out some tips here:

PHP for beginners

PHP among its facilities, which are many. Can be mixed in half HTML of shell script … Not to get your started in PHP (“get your started” was good!), With the right foot. Try to separate the most of the php code from other technologies.

Example separated php code:

Obviously this is a pattern that I try to follow, but not necessarily be correct. The PHP does not obligate you in writing a standard code, such as Java, which can be a facility if you know how to use it, or a disaster if not.

Do not understand any of the above code right? Take it easy .. explain more below.

The server tells you that those lines are php? The delimiter “” ends.

As is common in most languages, the “;” concludes a command. For those who know c or c + + , will realize that there is a great similarity between these languages ??with PHP. This occurs because the php is written in C , and based on the same.

The PHP has many functions, and a great mix and the lack of standard arguments. To facilitate learning php. Always use the official website of php . Use to find functions that do not know, like foreach simply login / foreach


As promised, the explanation of the code. The foreach is the simplest way to go a array , it is composed as follows, the first variable is the array to be traversed, and the second variable that will receive the data at each iteration of the [3×1001 ] foreach , can use the foreach iteration getting the key:

$ Arr_number = array (1 => 'one', 2 => 'two', 4 => 'four');
foreach ($ arr_number as $ key => $ value)
echo $ key, '::', $ value, '
'; } / * * Check out the above: * 1 :: one * 2 :: two Four * 4 :: * * /

That way you can control which key, and make direct changes to the array traversed using is key in the proper array .

Until next time! In the next post, I will describe some ways to read and write files. Super simple shapes, the classic form of the inherited code in c. And the facilities of php.

O post Starting in PHP simple and easy way apareceu primeiro em

]]> 0
Correcting mysql.sock connection error Tue, 28 Jan 2014 18:48:37 +0000 […]

O post Correcting mysql.sock connection error apareceu primeiro em

Resolvendo problema de socket no mysql

The problem

For Several times this has happened to me, always install a new server, or personal machine. I install mysql , and time to connect:

Can not connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)

The solution

Simple and easy, look for the configuration file, my.cnf, make sure it is the same configuration file.

Make a backup of it, to avoid any problem. My use is as ubuntu /etc/mysql/my.cnf

cd /etc/mysql/
cp my.cnf my.cnf.bkp

Edit the uncompensated you will get the following lines:

# * Basic Settings
socket = /var/run/mysqld/mysqld.sock
port = 3306

Ensure that the user that is experiencing the error, allowed reading /var/run/mysqld/mysqld.sock

If it does not give permission.


If you are trying to connect with php. And is getting the error, it may be that in your php.ini is set, an socket .

To resolve just open php.ini

nano /etc/php5/cgi/php.ini

This path may vary according to the php you are using, in my case I use lighttpd with php-cgi , and this is the default path.

For those who do not know is how to use php or lighttpd not know, you can take a look here: Enabling PHP on lighttpd without difficulties . Enable it, and see how the fastcgi can be much faster.

After opening the file, search for mysql.default_socket put the correct path, or leave blank.

What’s the use?

The speed difference between the connection is quite large, if you pass the direct path of the socket connects much faster, especially if the socket is in tmpfs.

For those who do not know what is tmpfs, you can learn more at this link: Improving performance of linux


mysql –
php –
php – stackoverflow

O post Correcting mysql.sock connection error apareceu primeiro em

]]> 0
Installing lighttpd on linux easily Tue, 28 Jan 2014 18:20:08 +0000 […]

O post Installing lighttpd on linux easily apareceu primeiro em

Instalando lighttpd

Instalando lighttpd

There is always a doubt, and a great discussion about the best web server . I think it’s complete nonsense .. all (those who pay) always have an application which does well.

I own a great tendency to apply the lighttpd around what I use, because I find it lighter and faster than anyone else.

Lighttpd on Ubuntu

The easiest way to install ubuntu impossible, simply:

apt-get update
apt-get upgrade
apt-get install lighttpd


Lighttpd, for those who do not use ubuntu

Simple also install ubuntu!

Joking! Just compile! When it speaks, Granny in the corner already crawled.

But it is easy, do not be afraid! Grandma calls to learn too!

First of all, visit the lighttpd ( ), on the part of downloads Get the latest version. At the time of this post the latest version is 1.4.31.

If you have a newer version on the site, and the procedure does not work, Grandma says to not cry, talk to me, that we solve!

Download the lighttpd.

wget wget


tar zxvf lighttpd-1.4.32.tar.gz

Now just compile

cd lighttpd-1.4.32 /

-prefix=/usr \
-exec-prefix=/usr \
-bindir=/usr/bin \
-sbindir=/usr/sbin \
-sysconfdir=/etc \
-datadir=/usr/share \
-includedir=/usr/include \
-libdir=/usr/lib \
-libexecdir=/usr/libexec \
-localstatedir=/var \
-sharedstatedir=/usr/com \
-mandir=/usr/share/man \
-infodir=/usr/share/info \
-with-openssl \
-with-pcre \
-with-zlib \
-with-bzip2 \
-disable-ipv6 \
-with-PACKAGE=mod_redirect \
-with-rewrite \
-with-redirect \

Much of al things, could be removed. But I believe that’s just the basics.

If you have any questions, or want to add something, you can check with the command:

. /configure - help

Now just install

make install


O post Installing lighttpd on linux easily apareceu primeiro em

]]> 0
Enabling PHP on lighttpd without difficulties Tue, 28 Jan 2014 18:08:55 +0000 […]

O post Enabling PHP on lighttpd without difficulties apareceu primeiro em

lighttpd pagina padrao

lighttpd pagina padrao

To enable php on lighttpd, is very simple.

The facility is geared to ubuntu -. , but in other distributions, is basically the same thing

We use the fastcgi- for this connection between the two. Remembering that php has to be CGI.

If you have not yet installed lighttpd can follow a tutorial I did on this installation here .

Knowing more lighttpd

Assuming that you already have lighttpd installed and running, as well as php-cgi, let’s continue. Lighttpd has two commands for installing modules, which greatly facilitate the life of anyone, they are the lighttpd-enable-mod and lighttpd-disable-mod , respectively, to enable and disable modules.

To find out which modules are available for activation with the command just type the command, you will have the list of possibilities.

vinicius @ Absinthe: ~ $ lighty-enable-mod
Available modules: auth accesslog cgi fastcgi evasive evhost expire FLV streaming on-www proxy rrdtool simple-vhost ssi ssl status userdir usertrack fastcgi-php debian-doc
Already enabled modules: simple-vhost fastcgi fastcgi-php

Enable module:

Installing the module in lighttpd

After entering the command, you simply enter the module to which you want to install.

Or in our case, as we have already sure that we will install, just enter the following command in the terminal.

fastcgi lighty-enable-mod
lighty-enable-mod fastcgi-php

Remember to do this as root , but will not do anything.

Finally, reload the settings of lighttpd, so they take effect

/etc/init.d/lighttpd reload


service lighttpd reload

To test create a simple php in the server folder, commonly /var/www with the code:

echo "" > /var/www/info.php

And go http://localhost/info.php

If you have any questions, or anger, or just want to scold me for lack of what to do, contact. Until next time!

O post Enabling PHP on lighttpd without difficulties apareceu primeiro em

]]> 0
zend framework 2 with lighttpd Tue, 28 Jan 2014 18:05:08 +0000 […]

O post zend framework 2 with lighttpd apareceu primeiro em

Configuring Zend Framework 2 with lighttpd

As a basis we use the ubuntu , but serves to any distribution, just know locate the configuration file lighttpd (lighttpd.conf)

Accessing lighttpd.conf

In ubuntu the file is located in / etc / lighttpd in other distributions.

Run command:

find / -name lighttpd.conf

Make sure that the mod_rewrite is active.

server.modules = (
# "Mod_rewrite"

Remove the ‘#’ back of the “mod_rewrite”, and voila! Ready a part.

Configuring mod_rewrite

On my server I use the mod_simple_vhost , but for those who do not use, simply remove the portion of the $ HTTP ..

This is the configuration of a personal project

As the Zend Framework, you need everything to be redirected to the index.php, as it is used to make friendly url

HTTP ["host"] = ~ "(^|\.)" {
server.document-root = "/home/hoo/public_html/demo/public"
server.errorlog = "/var/log/lighttpd/websites/hoo_error.log"
accesslog.filename = "/var/log/lighttpd/websites/hoo_access.log"
setenv.add-environment = (
"APPLICATION_ENV" => "development",
"ZF2_PATH" => "/home/hoo/public_html/zf/library"
url.rewrite-once = (
".*\(.*)$" => "/index.php? $ 1"
".*\(js|ico|gif|jpg|png|css|html).$" => "$0",
"" => "/index.php"

The part that really matters is to set the folder with server.document-root , if it is not in default, and the part of url.rewrite-once

First things first. Explaining the url.rewrite-once:

On the line below, it redirects everything we been through GET to index.php like GET

. "*\(.*)$" => "/index.php?$1"

In this he avoids the redirect of static files, all directed to the actual file.

"*\(js|ico|gif|jpg|png|css|html).. $" => "$0"

Here, everything is called will be redirected to index.php

"" => "/index.php"


For those who do not know should know!

O post zend framework 2 with lighttpd apareceu primeiro em

]]> 0