Linux route add

Adding static routes in Linux can be troublesome, but also absolutely necessary depending on your network configuration. I call static routes troublesome because they can often be the cause of long troubleshooting sessions wondering why one server can't connect to another.
This is especially true when dealing with teams that may not fully understand or know the remote servers IP configuration.

The Default Route

Linux, like any other OS has a routing table that determines what is the next hop for every packet.

Print the routing table contents

There are numerous commands that show the routing table but today we will use the ip command as this command will be replacing the route command in future releases.
# ip route show
 10.1.6.0/26 dev eth0 proto kernel scope link src 10.1.6.21
 10.1.7.0/24 dev eth1 proto kernel scope link src 10.1.7.41
 default via 10.1.6.1 dev eth0
As you can see in the example routing table there are numerous routes however 1 route shows as the default route. This routing table tells the system that if the IP that is being communicated to does not fall into any of the other routes than send the packets to the default route defined as 10.1.6.1. The default route basically acts as a catchall for any packet that isn't being told what to do in the above routes.

Our Example System

In today's article I will be referencing an example network configuration in order to show how static routes are added, why to add them and some basic troubleshooting.

Example Interface Configuration

eth0:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.1.6.21
NETMASK=255.255.255.192
ONBOOT=yes
eth1:
# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=static
IPADDR=10.1.7.41
NETMASK=255.255.255.0
ONBOOT=yes

Example Default Route Configuration

# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=testing.example.com
GATEWAY=10.1.6.1
The GATEWAY configuration in /etc/sysconfig/network tells the system that10.1.6.1 is the default route. This configuration could also be added to/etc/sysconfig/network-scripts/ifcfg-eth0 file; However if multipleifcfg-<interface> files have a GATEWAY this may provide unexpected results as there can only be one default route.

Example Why we need a static route

For our example network configuration we have two interfaces; eth0 (10.1.6.21)for the internet, and eth1 (10.1.7.41) for the internal network. If we were to hook up to a backup server such as 10.1.5.202 we would want the connectivity to go through eth1 the internal network, rather than eth0 which is the internet network.
Since 10.1.5.202 is not in the same subnet at eth1 (10.1.7.0/24) the routing table does not automatically route the packet through eth1 and would then hit the "catchall" default route out eth0. To force all of our packets destined for10.1.5.202 out eth1 we will need to set up a static route.

Adding a Static Route

Adding the route to the current routing table

Adding the static route is a fairly simple task however before we start we must first know the gateway for the internal network; for our example the gateway is10.1.7.1.
Adding a single IP
# ip route add 10.1.5.202/32 via 10.1.7.1 dev eth1
The above command adds a route that tells the system to send all packets for10.1.5.202 and only that IP to 10.1.7.1 from device eth1.
Adding a subnet of IP's
In order to add a whole subnet than you will need to change the CIDR on the end of the IP. In this case I want to add anything in the 10.1.5.0 - 10.1.5.255 IP range. To do that I can specify the netmask of 255.255.255.0 in CIDR format(/24)at the end of the IP itself.
If a CIDR (or netmask) is not specified the route will default to a /32 (single ip) route.
# ip route add 10.1.5.0/24 via 10.1.7.1 dev eth1
The difference between these two routes is that the second will route anything between 10.1.5.0 and 10.1.5.255 out eth1 with 1 route command. This is useful if you need to communicate with multiple servers in a network and don't want to manage lengthy routing tables.

Adding the route even after a network restart

While the commands above added the static route they are only in the routing table until either the server or network service is restarted. In order to add the route permanently, the route can be added to the route-<interface> file.
# vi /etc/sysconfig/network-scripts/route-eth1
Append:
10.1.5.0/24 via 10.1.7.1 dev eth1
If the above configuration file does not already exist than simply create it and put only the route itself in the file (# comments are ok). When the interface is restarted next the system will add any valid route in the route-eth1 file to the routing table.
I highly suggest that when possible anytime you add a route to the route-<interface> files that the interface itself is restarted to validate whether the route is actually in place correctly or not. I have been on many late night calls where a static route was not added correctly to the configuration files and was removed on the next reboot, which is also long after everyone has forgotten that a static route was required.

Troubleshooting a Static Route

Check if the route is in the routing table

Before performing any deep down troubleshooting steps the easiest and first step should be to check if the routing table actually has the route you expect it to have.
# ip route show
 10.1.5.0/24 via 10.1.7.1 dev eth1
 10.1.6.0/26 dev eth0 proto kernel scope link src 10.1.6.21
 10.1.7.0/24 dev eth1 proto kernel scope link src 10.1.7.41
 default via 10.1.6.1 dev eth0

Use tcpdump to see tcp/ip communication

The easiest way that I have found to find out whether a static route is working correctly or not is to use tcpdump to look at the network communication. In our example above we were attempting to communicate to 10.1.5.202 through deviceeth1.
# tcpdump -qnnvvv -i eth1 host 10.1.5.202
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes
16:50:35.880941 IP (tos 0x10, ttl 64, id 59563, offset 0, flags [DF], proto: TCP (6), length: 60) 10.1.7.41.41403 > 10.1.5.202.22: tcp 0
16:50:35.881266 IP (tos 0x0, ttl 59, id 0, offset 0, flags [DF], proto: TCP (6), length: 60) 10.1.5.202.22 > 10.1.7.41.41403: tcp 0
The above tcpdump command will only listen on eth1 and output only results that to or from 10.1.5.202.
TCP connections require communication from both the source and the destination, to validate a static route you can simply initiate a tcp connection (telnet to port 22 in this case) from the server with the static route to the destination server. In the output above you can see communication from 10.1.7.41to 10.1.5.202 from the eth1 interface, this line alone shows that the static route is working correctly.
If the static route was incorrect or missing the tcpdump output would look similar to the following.
# tcpdump -qnnvvv -i eth1 host 10.1.5.202
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes
16:50:35.881266 IP (tos 0x0, ttl 59, id 0, offset 0, flags [DF], proto: TCP (6), length: 60) 10.1.5.202.22500 > 10.1.7.41.22: tcp 0
In the above, only the target server is communicating over eth1.

undo revert git push

http://stackoverflow.com/questions/1270514/undoing-a-git-push
You need to make sure that no other users of this repository are fetching the incorrect changes or trying to build on top of the commits that you want removed because you are about to rewind history.
Then you need to 'force' push the old reference.
git push -f origin last_known_good_commit:branch_name
or in your case
git push -f origin cc4b63bebb6:alpha-0.3.0
You may have receive.denyNonFastForwards set on the remote repository. If this is the case, then you will get an error which includes the phrase [remote rejected].
In this scenario, you will have to delete and recreate the branch.
git push origin :alpha-0.3.0
git push origin cc4b63bebb6:refs/heads/alpha-0.3.0
If this doesn't work - perhaps because you have receive.denyDeletes set, then you have to have direct access to the repository. In the remote repository, you then have to do something like the following plumbing command.
git update-ref refs/heads/alpha-0.3.0 cc4b63bebb6 83c9191dea8

mysql useful commands

Show the binary log files command
 mysql> SHOW BINARY LOGS;    
 +------------------+------------+  
 | Log_name     | File_size |  
 +------------------+------------+  
 | mysql-bin.000001 | 1074232778 |  
 | mysql-bin.000002 | 1073742234 |  
 | mysql-bin.000003 | 1073743283 |  

To delete binary logs ..001 and 002 run below command
 PURGE BINARY LOGS TO 'mysql-bin.000003';



The MariaDB server's binary log is a set of files containing "events" which represent modifications to the contents of a MariaDB database. These events are written in a binary (i.e. non-human-readable) format. The mysqlbinlog utility is used to view these events in plain text.
Example:-
 mysqlbinlog mariadb-bin.000001 > /tmp/mariadb-bin.sql  

 Change user password:  
 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');  
 Grant privileges to user:  
 CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'paSSword123';  
 mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';  
 ls -1   
 mysql-bin.000051  
 mysql-bin.000052  
 mysql-bin.000053  
 mysql-bin.000054  
 mysql-bin.000055  
 mysql-bin.000056  
 mysql-bin.000057  
 mysql-bin.000058  
  for i in `seq 51 58`;do mysqlbinlog mysql-bin.0000${i} > ${i}-log.sql ; sleep 1 ;done   

#Case Insensitive mysql table name

Open terminal and edit /etc/mysql/my.cnf
sudo nano /etc/mysql/my.cnf
Underneath the [mysqld] section.add:
lower_case_table_names = 1

apt error bad sig

Run below commands:-

 aptitude -o Acquire::http::No-Cache=True -o Acquire::BrokenProxy=true update  
 apt-get update  

apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 54422A4B98AB5139

find interface upload download bandwidth statistics

parse /proc/net/dev
OR
cat /sys/class/net/eth0/statistics/tx_bytes (or rx_bytes for the number of received bytes)

missing mcrypt php extension

apt-get install php5-mcrypt
php5enmod mcrypt

edit  /etc/php5/apache2/php.ini
 #add below line  
 extension=mcrypt.so  


ls -l  /etc/php5/apache2/conf.d

 20-mcrypt.ini -> ../../mods-available/mcrypt.ini  
 05-opcache.ini -> ../../mods-available/opcache.ini  
 10-pdo.ini -> ../../mods-available/pdo.ini  
 20-gd.ini -> ../../mods-available/gd.ini  
 20-json.ini -> ../../mods-available/json.ini  
 20-mysql.ini -> ../../mods-available/mysql.ini  
 20-mysqli.ini -> ../../mods-available/mysqli.ini  
 20-pdo_mysql.ini -> ../../mods-available/pdo_mysql.ini  
 20-readline.ini -> ../../mods-available/readline.ini  

restart apache2 with
# service apache2 restart

done

mysql optimization increase tmp_table_size and max_heap_size

"Copying to tmp table" appears in mysql process list due to low amount of tmp table size

mysql> SET GLOBAL tmp_table_size =536870912;
Query OK, 0 rows affected (0.06 sec)

mysql> SET GLOBAL max_heap_table_size =536870912;
Query OK, 0 rows affected (0.00 sec)

edit /etc/my.cnf
[mysqld]
tmp-table-size                 = 536870912  #it is in bytes or 512 MB here
max-heap-table-size            = 33554432  # increase this to same as tmp-table-size if needed

postfix header check

HEADER CHECKS
The first thing that needs to be done is to enable header checks in the Postfix main.cf configuration file. This will tell postfix where to look for the header checks file.
To do this, add the following lines to main.cf:
header_checks = regexp:/etc/postfix/maps/header_checks
mime_header_checks = regexp:/etc/postfix/maps/mime_header_checks

If you are using pcre instead of regexp, you will use:
header_checks = pcre:/etc/postfix/header_checks
mime_header_checks = pcre:/etc/postfix/mime_header_checks

The format for each line in the header_checks file is as follows:
/^HEADER: .*content_to_act_on/ ACTION
The HEADER listed can be any header available in an email. The Subject header is the most popular to reject on for key words or phrases in spam filtering, but others can be very useful as well. The X-Mailer header can be used to identify some software or mail clients that are used almost exclusively for spam. Please see the last version of the header checks file for more examples of header checks.
The content to act on is preceded by a .* which specifies that it doesn’t matter what characters were before the content to act on.
The ACTION that will be taken has a number of options available:
REJECT is the most common, and this will cause the email to be rejected by Postfix. In this case, the incoming email will be blocked before it can enter your server. As an option, you can add text after the work REJECT, whereas that text will appear in both your log and the bounce message to the sender of the email. It is a good practice to number your lines in any checks file, as you may sometimes have difficulty identifying which rule caused a particular email to be rejected. A sample reject is as follows:
/^Subject .*Free Money/ REJECT Spam Header Rule #42
This will cause any email that has the words “Free Money” in the subject line to be rejected. The bounce message to the sender and your mail log will both have the text “Spam Header Rule #42” in them. This will allow you to more efficiently find what rule is causing problems or false rejects.
IGNORE will cause that particular header to be removed from the email, and will continue to process the email as normal. This can be useful in some situations. Please seethe Header Removal Guide for more information.
WARN can be very useful when testing new spam filters. An entry will be made in your mail log with a warning on the header, as well as any text that you place after the word “WARN” like with REJECT. It is often advisable to test new filters for a day or two with WARN before implementing them in production. This especially applies to complex rules that could easily have errors.
HOLD will hold the email in a hold queue, so that the system administrator can later take action (delete or release the email).
DISCARD will cause the sending server to think that the email was sent properly, but your Postfix server will silently discard (delete) the email. This option is for instances where you don’t want the remote person or server to know that the email was deleted.
FILTER will allow you to specify another instance of postfix, filter, or server where to send the email. After the word FILTER, you will add an entry like in the transport map file of transport:nexthop. Please see the transport map documentation for more information.
As spammers have become a lot more devious in finding ways to slip their emails past filters, header_checks has become a lot more useful in defining complex filtering schemes. Following are a few examples.
/^Subject: .*        / REJECT Spam Header Many Spaces 1
In this example, any subject with more than eight spaces will be rejected. In normal circumstances, there are very few reasons for someone to put eight spaces in a subject. Many automates spam sending tools and systems will add spaces at the end of a subject, and then place a code identifying the message or some other details.
/^Date: .* 200[0-2]/ REJECT Spam Header Past Date 1
/^Date: .* 19[0-9][0-9]/ REJECT Spam Header Past Date 2

These two examples will reject emails that appear to have been sent in the past (it is currently 2003 as of the time of this writing). Many spammers use dates far in the past (or the future) to make their emails appear at the top of your list.
/^Subject: .*f[ _\.\*\-]+r[ _\.\*\-]+e[ _\.\*\-]+e/ REJECT Hidden Word 1
This example shows how some spammers use different characters in between words to slip their messages past filters. In this example, the word “free” can be disguised with various characters in between the letters, and the header check will still reject it.
MIME HEADER CHECKS
In the mime_header_checks file, you will place a restriction for any file extentsons that you do not want to have passing through your system. For example:
/name=[^>]*\.(bat|com|exe)/ REJECT
This will reject any messages that have attachments whose files end in .bat, .com, or .exe. There are many more file extensions that can be considered dangerous. Please see the latest mime_header_checks file for more information.
You will have to deal with false rejects now and again. Either when users complain that they are not getting email, or when in looking at the mail logs you find that there are apparently valid emails being rejected. In this case, it should not be difficult to find the culprit rule, as you’ve added a rule number to the end of the reject string.
As you can see, header checks are not just about the words in the subject. They can be detailed and granular enough to catch even the strangest spam headers.

postfix header check

HEADER CHECKS
The first thing that needs to be done is to enable header checks in the Postfix main.cf configuration file. This will tell postfix where to look for the header checks file.
To do this, add the following lines to main.cf:
header_checks = regexp:/etc/postfix/maps/header_checks
mime_header_checks = regexp:/etc/postfix/maps/mime_header_checks

If you are using pcre instead of regexp, you will use:
header_checks = pcre:/etc/postfix/header_checks
mime_header_checks = pcre:/etc/postfix/mime_header_checks

The format for each line in the header_checks file is as follows:
/^HEADER: .*content_to_act_on/ ACTION
The HEADER listed can be any header available in an email. The Subject header is the most popular to reject on for key words or phrases in spam filtering, but others can be very useful as well. The X-Mailer header can be used to identify some software or mail clients that are used almost exclusively for spam. Please see the last version of the header checks file for more examples of header checks.
The content to act on is preceded by a .* which specifies that it doesn’t matter what characters were before the content to act on.
The ACTION that will be taken has a number of options available:
REJECT is the most common, and this will cause the email to be rejected by Postfix. In this case, the incoming email will be blocked before it can enter your server. As an option, you can add text after the work REJECT, whereas that text will appear in both your log and the bounce message to the sender of the email. It is a good practice to number your lines in any checks file, as you may sometimes have difficulty identifying which rule caused a particular email to be rejected. A sample reject is as follows:
/^Subject .*Free Money/ REJECT Spam Header Rule #42
This will cause any email that has the words “Free Money” in the subject line to be rejected. The bounce message to the sender and your mail log will both have the text “Spam Header Rule #42” in them. This will allow you to more efficiently find what rule is causing problems or false rejects.
IGNORE will cause that particular header to be removed from the email, and will continue to process the email as normal. This can be useful in some situations. Please seethe Header Removal Guide for more information.
WARN can be very useful when testing new spam filters. An entry will be made in your mail log with a warning on the header, as well as any text that you place after the word “WARN” like with REJECT. It is often advisable to test new filters for a day or two with WARN before implementing them in production. This especially applies to complex rules that could easily have errors.
HOLD will hold the email in a hold queue, so that the system administrator can later take action (delete or release the email).
DISCARD will cause the sending server to think that the email was sent properly, but your Postfix server will silently discard (delete) the email. This option is for instances where you don’t want the remote person or server to know that the email was deleted.
FILTER will allow you to specify another instance of postfix, filter, or server where to send the email. After the word FILTER, you will add an entry like in the transport map file of transport:nexthop. Please see the transport map documentation for more information.
As spammers have become a lot more devious in finding ways to slip their emails past filters, header_checks has become a lot more useful in defining complex filtering schemes. Following are a few examples.
/^Subject: .*        / REJECT Spam Header Many Spaces 1
In this example, any subject with more than eight spaces will be rejected. In normal circumstances, there are very few reasons for someone to put eight spaces in a subject. Many automates spam sending tools and systems will add spaces at the end of a subject, and then place a code identifying the message or some other details.
/^Date: .* 200[0-2]/ REJECT Spam Header Past Date 1
/^Date: .* 19[0-9][0-9]/ REJECT Spam Header Past Date 2

These two examples will reject emails that appear to have been sent in the past (it is currently 2003 as of the time of this writing). Many spammers use dates far in the past (or the future) to make their emails appear at the top of your list.
/^Subject: .*f[ _\.\*\-]+r[ _\.\*\-]+e[ _\.\*\-]+e/ REJECT Hidden Word 1
This example shows how some spammers use different characters in between words to slip their messages past filters. In this example, the word “free” can be disguised with various characters in between the letters, and the header check will still reject it.
MIME HEADER CHECKS
In the mime_header_checks file, you will place a restriction for any file extentsons that you do not want to have passing through your system. For example:
/name=[^>]*\.(bat|com|exe)/ REJECT
This will reject any messages that have attachments whose files end in .bat, .com, or .exe. There are many more file extensions that can be considered dangerous. Please see the latest mime_header_checks file for more information.
You will have to deal with false rejects now and again. Either when users complain that they are not getting email, or when in looking at the mail logs you find that there are apparently valid emails being rejected. In this case, it should not be difficult to find the culprit rule, as you’ve added a rule number to the end of the reject string.
As you can see, header checks are not just about the words in the subject. They can be detailed and granular enough to catch even the strangest spam headers.

apt gpg key error on ubuntu 14.04.3

solution 1
==============
 # apt-get clean
 # cd /var/lib/apt
 # mv lists lists.old
 # mkdir -p lists/partial
 # apt-get clean
 # apt-get update

solution 2
===============
Run below script
===============
 #!/bin/bash

OLDIFS=$IFS
IFS=$'\n'

lines=`sudo apt-get update 2>&1 | grep "NO_PUBKEY"`

for line in $lines
do

        key=`echo $line | tail --bytes=17`

        sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key

        SOMETHINGDONE="true"

done

IFS=$OLDIFS

if [ $SOMETHINGDONE ]
then
        sudo apt-get update
fi