search

Loading

Sunday, December 8, 2013

Port forwarding port 80 of public static ip to internal machines port 8080 in centos using iptables

I have a centos server acting as router. It has two ethernet ports eth0 and eth1. eth0 is configured with the public static ip got from my ISP. I have my internal machines connected to this centos os router machine using LAN in eth1.

For example, assume that my public static ip given by my ISP is 123.45.567.89 and it is configured in eth0. In eth1 my internal machines are connected through LAN. Internal machines are in the ip range of 192.168.1.0 to 192.168.1.100

I have a web application running on one of my internal machines with IP 192.168.1.10 on port 8080. I can access this web app from my internal network by typing http://192.168.1.10:8080/ in a web browser. But I want to get this application from my public static ip given by ISP by simply typing http://123.45.567.89/ in the web browser. How can I achieve this? By port forwarding. Follow the below steps to achieve this.

Install MTS MBLAZE 3GPLUS/MBLAZE ULTRA dongle for ZTE in Ubuntu Linux

I had recently got MTS 3GPLUS dongle. It is made ZTE and really good news about it is that it supports Linux and it is mentioned in their website (you can view the supported os list in "tech spec"). I have tried it in Windows 8, OSX Mavericks and Ubuntu 13.04 and it works really well on all these platforms.

In mac and windows, it will auto configure everything for you. But in Linux, you need to install it manually. When I plugged it into my ubuntu, it was detected as USB drive but there was no auto configure for it. Even I was not able to load the installation files in Ubuntu. Then I have to plug it into another Windows and was able to see it includes the files for installing it in Linux too.

Saturday, November 23, 2013

How to create a user to ssh to the server and then only have super user permission to switch to root user?

I don't want to ssh to my linux server as root user. So I have disabled the direct root login through ssh. I am using a less privileged user to ssh to the server. But I don't want to give him sudo privilege. The only privileged command this user (less privileged user) should be able to run is to switch to root user. How can I achieve this?

I'm using Amazon Linux (which is actually centos based) in my ec2 instance. It comes with 'ec2-user' which has no password and but has sudo privilege and uses ssh key for login. I want to use password login for other users (and don't want to use ssh key for them)[So I can't disable password login "PasswordAuthentication  no" field in sshd_config file]. But I also want to set password for 'ec2-user' as I don't want to use sudo command without password. I have used below setup to achieve this.

How to delete file names with spaces older than 30 days in linux?

I want to delete files which are modified before 30 days from a public folder (uploads) in my linux server. The files are uploaded by different users so it includes white spaces and other characters in the file name. How can I automate this process?

You can use any of the below commands to achieve this:

Saturday, September 7, 2013

How to delete a user from a group using single command in linux?

I have created a user called 'sam' and he is a member of the group 'webdeveloper'. Currently he is on long leave and I want to remove him from the web developer group without deleting this user.  How can I do this? We will find below.

Thursday, August 8, 2013

How to mount NTFS filesystem as read-writable in Mac OSX 10.8 Mountain Lion

Mountain Lion has built in support for read-writable NTFS filesystem. But it is enabled as read only by Apple. This means that you can only read from an NTFS formated hard disk but cannot write data to it.

To make it is as read-writable is very easy. There is no need to install any third party half working solutions or expensive softwares. Follow below steps :

Saturday, August 3, 2013

Download and install the bleeding edge version of elementary os

This post is more like  a note to myself.

Elementary OS is a distro which uses ubuntu as its base os. But unlike the other ubuntu based distros it's a class apart. It uses its own custom developed applications,icons and themes and everything works as a coherent unit.

Tuesday, July 30, 2013

How to fix the "built in speaker not working" issue in laptops with Ubuntu 13.04 (UEFI)

Recently I have bought a new Sony Vaio touchscreen laptop with Windows 8 UEFI boot (laptop is really good and I highly recommend it) . It was fairly easy to install Ubuntu 13.04 along side windows 8. I was successfully able to dual boot Windows 8 and Ubuntu in this laptop.

In Windows 8 as expected everything worked perfectly out of the box but it was a different story in Ubuntu. I have spent almost 3 weekends for a solution and finally found the solution from some of the old bug reports dated back to Ubuntu 8.04.

Friday, July 12, 2013

How to save using vim editor with sudo privilege

Some times we will start editing the configuration files or the files which need root privilege in vi/vim and once we are about to save it, we will understand that we haven't edited it with sudo privilege.

It may be almost impossible to think quitting the editor without saving (:q!) and start it all over agin.

Thursday, June 27, 2013

Install flite (festival lite) text to speech system in linux

Flite is text to speech engine for linux. It is based on festival speech synthesis system. Most of the linux sytems comes with flite in its package manager. It's just a apt-get on debian based or yum install in rpm based systems.

For example, you can install it on centos with below command:

Sunday, June 23, 2013

How to download files recursively using wget as ftp client

I like to use rsync for scp for transferring files from another server whenever possible. But sometimes, we will be limited to use ftp for the same task due to different ssh port than the standard 22 as scp and rsync uses ssh.

Downloading each file separately one after another is tedious task than recursively download them. We can use wget with ftp protocol for recursively downloading files from another server. We will find out how to do this below.

How to autostart dropbox linux client daemon at server reboot

We have seen the script to start dropbox linux client daemon to start automatically if it is getting killed before. But how to autostart the client at server reboot?

As usual we can add the script to cronjob to take care of this. We will find this how below.

Script to check whether dropbox (dropboxd daemon) is running in linux server using command line

Now a days more people are using dropbox for backup in linux servers. Dropbox is a great product which has their client in all major platforms. So this is really ideal for using in linux servers too.

Dropbox runs dropboxd daemon in the server to check for updates and syncing the contents between its clients across different platforms. Sometimes this daemon will get killed and our backup process will be in jeopardy.

Saturday, June 8, 2013

Delete all iptables rules in linux

We have seen how to remove a particular IP from the iptables rule. Now what if we want to remove all the iptables rule?

We can use the below command to remove all iptables rule.

How to remove a rule from iptables

I want to remove a rule from iptables which used to block one of the IPs to and from the server. How can I remove it? We will find it below.

IP which is blocked: 123.456.78.90


This will basically cut off all the tcp communication from and to my server for the IP 123.456.78.90

Thursday, June 6, 2013

Wednesday, June 5, 2013

How to run a golang program

Go is a language developed at google. The golang programs are generally having the extension '.go'.

So this is how we run a golang program.

How to run bash script in debug mode

Running the bash script in debug mode help us understand what is going on in the script before getting the output. This also help us find why our program didn't run if there is any issue.

It is just like step by step processing of the bash program.

We can use the below command to run the bash script in debug mode in run time.

How to format golang code

Golang is a language developed at Google. More information can be found at the wikipedia page.

Go has an easy tool called gofmt  to format the code blocks of go program in easy readable format.

Here is the command to format the golang program using gofmt   and save it to the corresponding file.

Friday, May 31, 2013

Print sum of all numbers in a file in linux using awk

This is to print the sum of all numbers in a file using awk.

If the file which we want to process is sum.txt, and it's content is :

cat sum.txt
1
3
2
4
5


 To find the sum of all these numbers we can use below command:

How to join all lines in a file using comma as delimiter?

Sometimes we want to combine the lines in a file as single line. How to achieve this in linux using command line?

We can use the command 'paste' for this purpose.

From its man page,

paste - merge lines of files


Saturday, March 2, 2013

How to run checkdisk on windows in external hard disk

Let's assume that the external hard disk is drive H, then open windows command line 'cmd' as Administrator and run the following command

chkdsk h: /f

Here /f is used to run it in forced mode.

Friday, February 8, 2013

Finding the first day and last day of the last month using date command in linux

First day of Last Month = echo $(date --date "-1 month" +%Y-%m-01)
Last day of Last Month = echo $(date --date "-`date +%d` days -0 month" +%Y-%m-%d)

First day of Current Month = echo $(date --date "-0 month" +%Y-%m-01)
Last day of Current Month = echo $(date --date "-`date +%d` days +1 month" +%Y-%m-%d)

First day of Next Month = echo $(date --date "+1 month" +%Y-%m-01)
Last day of Next Month = echo $(date --date "-`date +%d` days +2 month" +%Y-%m-%d)