Saturday, December 2, 2017

Where is the gateway IP address with NAT on VMware Fusion?

(1) check NAT network assigned by ifcofig


% ifconfig
......
vmnet1: flags=8863 mtu 1500
ether xxxxx
inet 192.168.167.1 netmask 0xffffff00 broadcast 192.168.167.255
vmnet8: flags=8863 mtu 1500
ether xxxxx
inet 192.168.154.1 netmask 0xffffff00 broadcast 192.168.154.255
......

vmnet1 is for host-only network. now, I use vmne8 (NAT) network to fix geteway IP of the VM.




(2) check vmnet8 config file


find gateway address on /Library/Preferences/VMware Fusion/vmnet8

/Library/Preferences/VMware Fusion/vmnet8
% cat nat.conf
# VMware NAT configuration file
# Manual editing of this file is not recommended. Using UI is preferred.
 
[host]
 
# NAT gateway address
ip = 192.168.154.2  # <== here!
netmask = 255.255.255.0
 
# VMnet device if not specified on command line
device = vmnet8

.......

Saturday, July 8, 2017

deploy proxy server with nginx

the proxy server is built on nginx. environment is shown below. two ubuntu virtual machines deployed by vagrant and each virtual machine has nginx.


one(192.168.33.10) is for webserver and the other(192.168.33.11) is for proxy.



# install virtualbox

http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html?ssSourceSiteId=otnus


# install vagrant

https://www.vagrantup.com/downloads.html

check version which installed
% vagrant --version
Vagrant 1.9.6


# deploy virtual machines

## 192.168.33.11(Proxy Server)

% cd
% mkdir vagrant_work
% cd vagrant_work
% vagrant init ubuntu/trusty64
 
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

% vagrant up --provider virtualbox


## 192.168.33.10(Web Server)

% cd
% mkdir vagrant_work2
% cd vagrant_work
% vagrant init ubuntu/trusty64
 
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
 
% vagrant up --provider virtualbox

## check point

two virtual machines are running on virtualbox.



# set IP address

## 192.168.33.11(Proxy Server)

move to directory.
% cd
% cd vagrant_work

edit file.
% vi Vagrantfile
% cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "private_network", ip: "192.168.33.11"
end

restart virtual machine.
% vagrant halt
==> default: Attempting graceful shutdown of VM...
% vagrant up

check ping echo.
 % ping -c 3 192.168.33.11


## 192.168.33.10(Web Server)

move to directory.
% cd
% cd vagrant_work2

edit file.
% vi Vagrantfile
% cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "private_network", ip: "192.168.33.10"
end

restart virtual machine.
% vagrant halt
==> default: Attempting graceful shutdown of VM...
% vagrant up

check ping echo.
 % ping -c 3 192.168.33.10


# install nginx

## 192.168.33.11(Proxy Server)

move to directory.
% cd
% cd vagrant_work
% vagrant ssh

install nginx on virtual machine.
# apt-get install nginx
# cp /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.backup

edit index.html like this.
# vi /usr/share/nginx/html/index.html
# cat /usr/share/nginx/html/index.html
192.168.33.11


## 192.168.33.10(Web Server)

move to directory.
% cd
% cd vagrant_work2
% vagrant ssh

install nginx on virtual machine.
# apt-get install nginx
# cp /usr/share/nginx/html/index.html /usr/share/nginx/html/index.html.backup

edit index.html like this.
# vi /usr/share/nginx/html/index.html
# cat /usr/share/nginx/html/index.html
192.168.33.10


## check point

then, check if http access available.
http://192.168.33.11


http://192.168.33.10



# proxy config (no ssl)

## 192.168.33.11(Proxy Server)

move to directory.
% cd
% cd vagrant_work
% vagrant ssh

edit file like this.
# vi /etc/nginx/conf.d/server.conf
# cat /etc/nginx/conf.d/server.conf
server {
  listen 80;
  server_name 192.168.33.11;
  location / {
    proxy_pass http://192.168.33.10/;
  }
}
 
# service nginx restart
 * Restarting nginx nginx                                                [ OK ]



## check point

then check again. it shows 192.168.33.10 page. it means proxy server pass to webserver.
http://192.168.33.11



# proxy config (ssl)

## 192.168.33.11(Proxy Server)

move to directory.
% cd
% cd vagrant_work
% vagrant ssh

ssl settings
# mkdir /usr/local/tmp
# cd /usr/local/tmp/
# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
Enter pass phrase for server.key:[1234]
Verifying - Enter pass phrase for server.key:[1234]
 
# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:[1234]
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:
 
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
 
# cp server.key server.key.org
# openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org:
writing RSA key
 
# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd
Getting Private key



## check point

# ls
server.crt  server.csr  server.key  server.key.org
# pwd
/usr/local/tmp

edit file.
# vi /etc/nginx/conf.d/server.conf
# cat /etc/nginx/conf.d/server.conf
server {
  listen 80;
  server_name 192.168.33.11;
  location / {
    proxy_pass http://192.168.33.10/;
  }
}
 
server {
  listen       443;
  server_name  192.168.33.11;
 
  ssl                  on;
  ssl_certificate      /usr/local/tmp/server.crt;
  ssl_certificate_key  /usr/local/tmp/server.key;
  ssl_protocols  SSLv2 SSLv3 TLSv1;
 
  location / {
    proxy_pass http://192.168.33.10/;
  }
}

nginx service restart.
# service nginx restart
 * Restarting nginx nginx                                               [ OK ]


## check point

then, access to https page.
https://192.168.33.11

Sunday, June 25, 2017

meeting timer

meeting timer
mtg_timer

you can also see remain time on the tab.
TimeKeeper

current time is

end time is

remain time is
min sec



<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <!--multi device--!>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <title>TimeKeeper</title>
    </head>
    <body>
    <!-- get current time --!>
    <p>
    current time is<label id="RealtimeClock"></label>
    </p>
    <!-- get end time --!>
    <p>
    end time is<input type="text"id="EndTime"  value="18:00" size="10">
    </p>
    <!-- get remain time and set buttons --!>
    <p>
    <form name="timer">
    remain time is</br>
    <input type="text" value="10" size="10">min
    <input type="text" value="0" size="10">sec<br>
    <input type="button" value="start" onclick="cntStart()">
    <input type="button" value="stop" onclick="cntStop()">
    <input type="button" value="reset" onclick="reSet()">
    </form>
    <!-- get aleart message --!>
    <font color="red"><label id="AlertMessage"></label></font>
    </p>
    <!-- get textbox --!>
    <p>
    <textarea name="freeans" rows="20" cols="30">Today's Agenda</textarea>
    </p>
        <!-- javascript --!>
        <script type="text/javascript">
        // display clock
        function showClock() {
           var nowTime = new Date();
           var nowHour = setfig( nowTime.getHours() );
           var nowMin = setfig( nowTime.getMinutes() );
           var nowSec = setfig( nowTime.getSeconds() );
           var msg = nowHour + ":" + nowMin + ":" + nowSec;
           document.getElementById("RealtimeClock").innerHTML = msg;
        }
        setInterval('showClock()',1000);
        // fix number of digits to two if its one
        function setfig(num) {
           var ret;
           if( num < 10 ) { ret = "0" + num; }
           else { ret = num; }
           return ret;
        }
        // set timer id
        var timer1;
        
        // get countdown timer for 1000msec
        function cntStart() {
          document.timer.elements[2].disabled=true;
          timer1=setInterval("countDown()",1000);
        }
        
        // stop timer
        function cntStop() {
          document.timer.elements[2].disabled=false;
          clearInterval(timer1);
        }
        
        // countdowm timer
        function countDown() {
          var min=document.timer.elements[0].value;
          var sec=document.timer.elements[1].value;
          
          if( (min=="") && (sec=="") ) {
            var msg="set time!";
            document.getElementById("AlertMessage").innerHTML = msg;
            reSet();
          } else {
            if (min=="") min=0;
            min=parseInt(min);
            
            if (sec=="") sec=0;
            sec=parseInt(sec);
            
            tmWrite(min*60+sec-1);
          }
        }
        
        // get remain time
        function tmWrite(int) {
          int=parseInt(int);
          
          if (int<=0)
          {
            reSet();
            var msg="it's time!";
            //alert(msg)
            document.getElementById("AlertMessage").innerHTML = msg;
            // aleart tab if remain time is zero
            document.title  = msg
          } else {
            // get remain min
            rem_min=Math.floor(int/60);
            // get remain sec
            rem_sec=int % 60;
            // get remain time
            document.timer.elements[0].value=rem_min;
            document.timer.elements[1].value=rem_sec;
            // display remain time
            document.title  = 'remain time is ' + rem_min + ':' + rem_sec;
          }
        }
        
        // reset form
        function reSet() {
          var msg="";
          document.getElementById("AlertMessage").innerHTML = msg;
          document.timer.elements[0].value="10";
          document.timer.elements[1].value="0";
          document.timer.elements[2].disabled=false;
          clearInterval(timer1);
        }
        </script>
    </body>
</html>