Monday, April 18, 2016

Ping with Real time (Timestamp)

Ping with Real time (Timestamp)

ping google.com | awk '/^[0-9]+ bytes from / { "date" | getline pong; close("date"); print pong":",$0; }'

You can also save the results with a txt file with simply adding > after the command

ping google.com | awk '/^[0-9]+ bytes from / { "date" | getline pong; close("date"); print pong":",$0; }' >results.txt


If you’re interested in all types of replies (unreachable, no route to host, etc), the following should work on most systems;

ping google.com | while read pong; do echo "$(date): $pong"; done


You can also save the results with a txt file with simply adding > after the command

ping google.com | while read pong; do echo "$(date): $pong"; done > results.txt

Cron job not running after a timezone change

New time is not reflecting on crons logs even after chaning timezone & time.
Here is the simple trick to fix this

Restart the rsyslog service with below command to sync the new time with all applications (including cron)

service rsyslog restart

Thursday, April 14, 2016

Forward SMPT port 25 with other port


Linux does not allow root users to bind port traffic to ports 1024 and below. However, the simple mail transfer protocol (SMTP) has a default value of port 25. If you are running Linux, you must configure the reserve SMTP agent to listen to a custom port instead of the default port 25.

Before you begin
Run the commands in the following procedure as a root user.

Update your firewall to open the port above port 1024 by adding the following lines to your

vim /etc/sysconfig/iptables file:

-A OUTPUT -p tcp -s serverIP -d 0/0 --dport Port_Above_1024   -m state --state ESTABLISHED -j ACCEPT
-A INPUT -s 0/0 -d serverIP -m state --state NEW,ESTABLISHED  -p tcp --dport Port_Above_1024 -i eth0 -j ACCEPT

Restart your firewall:

/etc/init.d/iptables restart

Open port 25 for forwarding:

iptables -A FORWARD -p tcp --destination-port 25 -j ACCEPT;

Forward port 25 to your custom port above 1024:

iptables -t nat -A PREROUTING -j REDIRECT   -p tcp --destination-port 25 --to-port Port_Above_1024

To verify that port 25 is forwarding, Run a telnet command:

telnet yourServer 25

If you do not receive a successful response, forward port 25 to a different custom port.

Port_Above_1024 change the same to any port no. above 1024