Posts tagged with linux - page 3

Pass output of one command to argument of other

Well Linux is famous for combining things in power full ways in which anything is possible from a command line. The real fun of Linux came when you start focusing on terminal to do everything...

It's possible to pipeline commands in terminal. Also it's possible to pass output of something as an argument of other.

For example you can ping to your own external ip by

ping $(curl -s  curlmyip.com)

curl curlmyip.com returns you ip address. This address is passed to  the telnet as an argument. Whatever you put between $( and ) will execute as if it is a bash command.


How to know external IP address from Linux terminal?

ifconfig displays only local ip address of your system. If your system is directly connected to internet then it will be your external ip address. It may not be the case always. Because you will be behind a router or a modem.
You can know the external IP address by going to www.whatismyip.com or www.ipecho.net. If you want to know it from a terminal type

curl curlmyip.com

What curl do is it fetches the content of the link to the terminal. There are also several other websites that offers this same service. Some of them are listed below.

curl ipecho.net/plain

curl myexternalip.com/raw

curl curlmyip.com


curl ifconfig.me/ip


curl icanhazip.com


curl ip.appspot.com



How to see open ports inLinux?

Type this netstat command in terminal.

netstat -tulpn

Or you can use this one.

netstat -l

Try netstat --help to go through other options also...

Testing NAT Port Forwarding and reverese NAT

For a long time I have been trying to configure port forwarding using NAT. But every attempt was futile...  Finally I found that my port forwarding works just fine. But it just appears to be not working because my router doesn't support reverse NAT. In this post I will show you guys how to test whether you configure your NAT correctly or not. (Read a detailed write up by shane. Link)

First make a port forwarding rule in your router say 1600. Download this little tool called simple internet tools. Install it and open port listener and select your internal IP(192.168.x.x). Then type your port number and press start listening.

Go to this site and check whether it says port is opened. If your connection is successful you will notice it in the port listener application.

Then go to your browser and type your internet ip address. (You can find it from www.whatismyip.com) . Tnen type your port number after a colon. (116.211.22.12:1600). Your browser shows a webpage not available window. Check your port listener. If you find a connection successful message it means your router supports reverse NAT. Otherwise reverse NAT is not available.

You can also check it by an nc command like this.

nc 116.211.22.12 1600

If you didn't want to test the connection using the above site you can do it by nc from a remote ssh account. Login to your ssh account and try to connect it with nc.

How to see DNS reply? or Testing DNS server?

Wonder how the dns works or want to know the dns reply from server? Sometimes when setting up a local dns server we have to test whether it is working or not. Here is how you can test it in Linux.

dig @127.0.0.1 www.google.com