GAU5S

          The teatime, forever!

          Alice. Through the Looking Glass, 2016, 01:04:04

Tips & Links: Hyper-V, TinyCore, Samba
--------------------------------------

I. Hyper-V: Let's create Kitcat 5 inch smartphone by installing standalone version of Android Simulator for Visual Studio 2015:

  vs_emulatorsetup.exe (~40MB)

Read this:

  https://blogs.msdn.microsoft.com/visualstudioalm/2014/11/12
        /introducing-visual-studios-emulator-for-android/

..You can also download the emulator without needing to install Visual Studio..

  https://aka.ms/blogdownloadvsemu

Exercise: check the IP address of emulated device: Hyper-V, Connect to.., Activate button, on terminal

  # ip addr

II. XUbuntu for Hyper-V: RAM: 1024MB, NIC on external switch, extract HD (available via school file server).

  XUbuntu-1610H-v.7z 1.4GB,

default location on my local disk:

  C:\Users\Public\Documents\Hyper-V\Virtual hard disks\XUbuntu-1610.vhdx

III. Building NAT switch on Hyper-V (Windows 10 1607 b 14393 anniversary update (Redstone-I))

Read this:

  http://www.thomasmaurer.ch/2016/05
       /set-up-a-hyper-v-virtual-switch-using-a-nat-network/

In Powershell console as administrator:

  New-VMSwitch -SwitchName "NAT_vSwitch" -SwitchType Internal -Verbose
  # Use Get-NetAdapter to retrive <N>
  New-NetIPAddress –IPAddress 10.0.1.1 -PrefixLength 24 -InterfaceIndex <N> –Verbose
  # or remove
  Remove-NetIPAddress –IPAddress 10.0.1.1 -PrefixLength 24 -InterfaceIndex 16 –Verbose
  New-NetNat –Name NATNetwork –InternalIPInterfaceAddressPrefix 10.0.1.0/24 –Verbose
  # or remove
  Remove-NetNAT –Name NATNetwork
  # Connect machine to segment:
  Get-VM | Get-VMNetworkAdapter | Connect-VMNetworkAdapter –SwitchName "NAT_vSwitch"

Disadvantage: No DHCP.
Advantages:
1. Over "bridge" aka "external": No extra IP addresses for each VM in segment
2. Over "internal": No extra IP address for gateway.
                 No need to use "gateway VM".

More Links:
-----------

1. https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows
   /user_guide/setup_nat_network

2. https://charbelnemnom.com/2016/05
   /how-to-configure-hyper-v-virtual-switch-that-supports-nat-network-
   with-powershell-hyperv-powershell/

III. Gateway.

Otherwise create gateway VM with two NIC, eth0 external, eth1 internal, masquerade, DHCP on eth1, how:

a) NIC's

/etc/network/interfaces

  source /etc/network/interfaces.d/*

  # The loopback network interface
  auto lo
  iface lo inet loopback

  # The primary network interface
  auto enp0s3
  iface enp0s3 inet dhcp

  # The secondary network interface
  auto enp0s8
  iface enp0s8 inet static
  address 10.0.1.1
  netmask 255.255.255.0
  network 10.0.1.0
  broadcast 10.0.1.255

b). Masquerade:

  # apt-get remove ufw
  # apt-get install iptables

Stop the firewall and delete all rules:

  # iptables -F
  # iptables -X
  # iptables -t nat -F
  # iptables -t nat -X
  # iptables -t mangle -F
  # iptables -t mangle -X
  # iptables -P INPUT ACCEPT
  # iptables -P OUTPUT ACCEPT
  # iptables -P FORWARD ACCEPT

Forward packages

  # iptables -t nat -A POSTROUTING -s 10.0.1.0/24 -o eth0 -j MASQUERADE
  # iptables -t nat -A POSTROUTING -s 10.0.1.0/24 -o enp0s3 -j MASQUERADE

  # echo 1 > /proc/sys/net/ipv4/ip_forward
  # or want to be stylish:
  $ sudo sysctl -w net.ipv4.ip_forward=1

Make it persistent:

  # apt-get install iptables-persistent
  # vi /etc/iptables/rules.v4

  *nat
  :PREROUTING ACCEPT [0:0]
  :INPUT ACCEPT [0:0]
  :OUTPUT ACCEPT [0:0]
  :POSTROUTING ACCEPT [0:0]
  -A POSTROUTING -s 10.0.1.0/24 -o eth0 -j MASQUERADE
  -A POSTROUTING -s 10.0.1.0/24 -o enp0s3 -j MASQUERADE
  COMMIT
  *filter
  :INPUT ACCEPT [0:0]
  :FORWARD ACCEPT [0:0]
  :OUTPUT ACCEPT [0:0]
  COMMIT

Edit /etc/sysctl.conf and search for the following lines:

  # Uncomment the next line to enable packet forwarding for IPv4
  net.ipv4.ip_forward=1

IV. TinyCore linux.

        They dont know how to use that OS.
        http://www.webhostingtalk.com/showthread.php?t=1023621

a) Install

Create VM, run from:

  CorePlus-current.iso

  -- TC_Install icon on "Plank" (frugal, to HD)
  -- Boot from HD
  -- Apps icon on "Plank" (onboot)
       Opera9, dropbear
     (or with command: tce-load -wi app_name.tcz)

  -- Control Panel -> Network or $ netcardconf

    Interface    [ eth0 ]   Interface    [ eth0 ]
    Use DHCP Broadcast      Use DHCP Broadcast
    yes ( ) no (*)          yes ( ) no (*)
    IP address   [      ]   IP address   [10.0.2.100]
    Network mask [      ]   Network mask [255.255.255.0]
    Broadcast    [      ]   Broadcast    [10.0.2.255]
    Gateway      [      ]   Gateway      [10.0.2.2] # see route -n DHCP
    Nameservers  [      ]   Nameservers  [8.8.8.8]
    Nameservers  [      ]   Nameservers  [8.8.4.4]

  -- /etc/resolv.conf
      nameserver 8.8.8.8
      nameserver 8.8.4.4

Notes: /opt, /home are persistent, /etc, /mnt, /tmp are not.
       $ xterm -font 12x24 for bigger font while in X.

------

b) Startup scripts are

  /opt/bootsync.sh  # early
  /opt/bootlocal.sh # late
  /opt/shutdown.sh. # before shutdown

c) DHCP

  $ udhcpd /opt/udhcpd.conf &
  # vi /opt/udhcpd.conf

  start 10.0.2.20
  end 10.0.2.50
  interface eth0
  option subnet 255.255.255.0
  option router 10.0.2.2
  option lease 259200
  option dns 8.8.8.8
  lease_file /tmp/udhcpd.leases
  option domain HYPERNAT
  pidfile /tmp/udhcpd.pid

d) DROPBEAR (ssh)

Note: Default user is "tc". Have sudo w/o password:

  ..
  # User privilege specification
  tc ALL=NOPASSWD: ALL

  $ sudo -s
  # passwd tc

First run

  # dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
  # dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key
  # dropbearkey -t ecdsa -f /etc/dropbear/dropbear_ecdsa_host_key

  -- Save this files

      /etc/dropbear/dropbear_rsa_host_key
      /etc/dropbear/dropbear_dss_host_key
      /etc/dropbear/dropbear_ecdsa_host_key

     dropbear service script

      /etc/init.d/dropbear

     dns resolution data

      /etc/resolv.conf

     to /opt and restore them back on next boot.

  -- Automate this in /opt/bootlocal.sh.

  -- Use dropbear -E to dispay errors on console.

V. Samba
--------

Example: Create Share on Windows 10 (host)

  Network And Sharing Center ->
    Change Advanced Sharing Settings ->
      Change sharing options for different network profiles ->
        All Networks
          (x) Turn on sharing so anyone with network access
              can read and write files in the Public folders
          (x) Turn off password protected sharing

  Folder properties:
    Sharing (share) -> Everyone [v] -> Add ->
    EveryOne -> Permission Level [v] Read/Write
    [Share]

  Advanced Sharing

    [v] Share this folder
    Share Name: [VM]
    Share permissions: Everyone

    Permissions for Everyone
    Full control [x]
    Change       [x]
    Read         [x]

    [ OK ]

Use this Share in XUbuntu 1610 VM (Oracle VirtualBox, Bridged)

  sudo mkdir /mnt/W10
  sudo mount -t cifs //DESKTOP-PP9G844/VM /mnt/W10
  ls -l /mnt/W10
  ..

Links

  1. https://www.howtoforge.com/tutorial/samba-server-ubuntu-16-04/
  2. https://help.ubuntu.com/community/Samba/SambaClientGuide

Annex A. Tiny Core 7.2 as DHCP server for NAT Network
-----------------------------------------------------

tc@box:/opt$ ls -l
total 36
drwxrwsr-x    2 root     staff           40 Nov  2 07:34 backgrounds/
-rwxrwxr-x    1 root     staff          334 Nov  2 08:59 bootlocal.sh
-rwxrwxr-x    1 root     staff          272 Jul  4 12:00 bootsync.sh
-rw-r--r--    1 root     staff         1614 Nov  2 07:53 dropbear.sh
-rwxr-xr-x    1 root     staff          209 Nov  2 08:52 eth0.sh
-rw-r-----    1 root     staff          135 Nov  2 08:31 shadow
-rwxrwxr-x    1 root     staff          613 Jul  4 12:00 shutdown.sh
-rw-rw-r--    1 root     staff           31 Jul  4 12:00 tcemirror
-rw-r--r--    1 root     staff          213 Nov  2 09:07 udhcpd.conf
-rw-r--r--    1 root     staff           29 Nov  2 07:45 xt.sh

new/modified files in /opt

bootlocal.sh
------------

#!/bin/sh
# put other system startup commands here
touch /var/log/lastlog
sh /opt/eth0.sh &
cp /opt/shadow /etc/shadow
cp /opt/xt.sh /usr/local/bin/xt
chmod 775 /usr/local/bin/xt
cp /opt/dropbear.sh /etc/init.d/dropbear.sh
chmod 755 /etc/init.d/dropbear.sh
mkdir /etc/dropbear
/etc/init.d/dropbear.sh start
udhcpd /opt/udhcpd.conf &

dropbear.sh
-----------

#!/bin/sh
NAME=Dropbear
DESC="SSH server"
DAEMON=/usr/local/sbin/dropbear
OPTIONS="-w -g -E"
# -w disallow root logins
# -g disable password logins for root
# -E print errors to console
PIDFILE=/var/run/dropbear.pid

case "$1" in
  start)
    # We need rsa and dss host key file to start dropbear.
    if [ ! -f /etc/dropbear/dropbear_rsa_host_key ] ; then
      echo "Generating $NAME rsa key... "
      dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
    fi
    if [ ! -f /etc/dropbear/dropbear_dss_host_key ] ; then
      echo "Generating $NAME dss key... "
      dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key
    fi
    if [ ! -f /etc/dropbear/dropbear_dss_host_key ] ; then
      echo "Generating $NAME dss key... "
      dropbearkey -t ecdsa -f /etc/dropbear/dropbear_ecdsa_host_key
    fi
    if [ -f $PIDFILE ] ; then
      echo "$NAME already running."
      exit 1
    fi
    echo "Starting $DESC: $NAME... "
    $DAEMON $OPTIONS
    ;;
  stop)
    if [ ! -f $PIDFILE ] ; then
      echo "$NAME is not running."
      exit 1
    fi
    echo "Stopping $DESC: $NAME... "
    kill `cat $PIDFILE`
    ;;
  restart)
    if [ ! -f $PIDFILE ] ; then
      echo "$NAME is not running."
      exit 1
    fi
    echo "Restarting $DESC: $NAME... "
    kill `cat $PIDFILE`
    sleep 2
    $DAEMON $OPTIONS
    ;;
  status)
    if [ -f $PIDFILE ]; then
  echo "$NAME is running."
  exit 0
    else
      echo "$NAME not running."
      exit 1
    fi
  ;;
  *)
    echo ""
    echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart|status]"
    echo ""
    exit 1
    ;;
esac

exit 0

eth0.sh
-------

#!/bin/sh
pkill udhcpc
ifconfig eth0 10.0.2.5 netmask 255.255.255.0 broadcast 10.0.2.255 up
route add default gw 10.0.2.2
echo nameserver 8.8.8.8 > /etc/resolv.conf
echo nameserver 8.8.4.4 >> /etc/resolv.conf

shadow (user "tc" password is "tc" now)
------

root:*:13525:0:99999:7:::
lp:*:13510:0:99999:7:::
nobody:*:13509:0:99999:7:::
tc:$1$STFUDxs.$pgONVsNjOsS/Bn.0rjpWG1:17107:0:99999:7:::

udhcpd.conf
-----------

start 10.0.2.20
end 10.0.2.50
interface eth0
option subnet 255.255.255.0
option router 10.0.2.2
option lease 259200
option dns 8.8.8.8
lease_file /tmp/udhcpd.leases
option domain HYPERNAT
pidfile /tmp/udhcpd.pid

xt.sh
-----

#!/bin/sh
xterm -font 12x24
