Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Sunday, June 4, 2017

Local DNS resolution

We can always run a DNS server and resolve a URL/URI to a specific IP address. But in development  environment there is no point running a beast to resolve url to ip address.

Let's say your URL : myServer.companyName.com
IP address : 10.20.30.40

So there is an easy alternative if you don't want to modify your source code and change the IP address.
You can add entry in /etc/hosts

MacBook-Pro-2:~ Siddheshwar$ sudo vi /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
172.24.1.5 myServer.companyName.com
127.0.0.1        localhost
255.255.255.255 broadcasthost
::1 localhost
#172.24.1.5              abc.sid.com
# BEGIN section for OpenVPN Client SSL sites
127.94.0.1 client.openvpn.net
# END section for OpenVPN Client SSL sites

:wq (enter)
to save



Tuesday, December 6, 2016

Show Directory Tree structure in Unix

Graphics based operating systems provide the option for you to see the complete directory structure graphically. But, in console-based Linux/Unix operating systems this is not possible (by default). At most, you can go inside each directory and do ls or if you are a scripting geek you can create one to do the same for you.

Recently, I came across directory listing program, tree which makes this job possible in Unix/Linux from the terminal. 

Installation

CentoOs/RHEL: $sudo yum install tree -y

Ubuntu: $sudo apt-get install tree

Using Tree

Use tree and the directory name. That's it!

$tree cookbooks/
cookbooks/
`-- learn_chef_httpd
    |-- Berksfile
    |-- chefignore
    |-- metadata.rb
    |-- README.md
    |-- recipes
    |   `-- default.rb
    |-- spec
    |   |-- spec_helper.rb
    |   `-- unit
    |       `-- recipes
    |           `-- default_spec.rb
    `-- test
        `-- recipes
            `-- default_test.rb

7 directories, 8 files

Friday, November 11, 2016

IP Address in Private Range

Ah, again; I forgot the range of private IP address. So, no more cursing of my memory. Now...instead of googling I will search on my blog :D

Below are permissible private IP ranges:
  • 10.0.0.0        - 10.255.255.255
  • 172.16.0.0    - 172.31.255.255
  • 192.168.0.0  - 192.168.255.255
These IP address are used for computers inside a network which needs to access inside resources. Routers inside the private network can route traffic between these private addresses. However, if they want to access resource in outside world (like internet) these network entities have to have a public address in order for response to reach to them. This is where NATing is used. 


Representing IP address in CIDR format


The number following the forward slash (/) is the prefix length, the number of shared initial bits, counting from the most significant bit of the address. 

Thus, a /20 block is a CIDR block with an unspecified 20-bit prefix. 

In below example, 10.0 is the network address and last two segments are device addresses. 



Thursday, June 18, 2015

Running a class from a Jar file

This post talks about executing a jar file and the jar could have one or more than one class with the main method.  Remember that, you need a main method in the class to be called from outside.  So if you want to run a class contained inside jar file:
Either it should have a main method or Other class have the main method which calls appropriate method of your target class.

Pre-condition 
Make sure that java and jar are on your PATH. This is how you set on Linux/Unix systems:

export PATH=$PATH:/full_path_java_bin_directory

Otherwise, you will have to run below command from bin directory inside the Java installer. I am covering here only Unix/Linux system (windows will be similar, though).



Running a Particular Class

$java -cp <jar_path> <className> [OPTIONAL_PARAMS]

The first argument JAR_PATH should give the fully qualified path of the jar file. Similarly, class name should be complete. One quick way is, check out the package name of the class which you want to run. If the package name is com.blogger then the class name should be com.blogger.ClassName. 

$java -cp lib/my.jar com.blogger.PostDetails   //no param

$java -cp lib/my.jar com.blogger.PostDetails postName   //main expects param with name postName
$java -cp my.jar PostDetails  //running from jar directory, and class is in default package

You can also use -classpath instead of -cp 


If the jar is executable

$java -jar <jar_path> [OPTIONAL_PARAMS]

If the jar is executable (i.e. it has manifest file inside META-INF directory and specifies the name of the class file which has main method), the command to run it is slightly different. 

$java -jar lib/my.jar

So basically we don't specify the class name in the command (as it's implicitly understood).

You can check if the jar has a manifest file by running below command:
$java -jar my.jar


--
keep coding !!!