Friday, October 7, 2016

VLAN in Linux - permanent solution

VLAN's in Linux - permanent solution



copy file


/etc/sysconfig/network-scripts/ifcfg-eth0 

to

/etc/sysconfig/network-scripts/ifcfg-eth0.2
  • eth0 – Your regular network interface
  • eth0.2 – Your virtual interface that use untagged frame

edit ifcfg-eth0.2
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0.2

replace 
DEVICE=ifcfg-eth0  


with
DEVICE=ifcfg-eth0.2

add
VLAN=yes

Remove gateway entry from all other network config files. Only add gateway to /etc/sysconfig/network

service  network   restart

Nginx Web Server - LEMP

Nginx Web Server - LEMP


Ubuntu 16.04 (DigitalOcean VPS)

::NGINX install::

    sudo apt-get update
    sudo apt-get install nginx

ufw app list
ufw allow 22
ufw allow "nginx http"

ufw enable
ufw status

::How to find Public IP address::

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
curl -4 icanhazip.com

Now go to visit http://<server-ip/dns>
 If you see Welcome to NGINX! -- nginx working ok

::MySQL Server setup::

sudo apt-get install mysql-server
sudo mysql_secure_installation

..on all Q answer yes.. only root pass N!


::PHP install::
sudo apt-get install php-fpm php-mysql

sudo nano /etc/php/7.0/fpm/php.ini
ctrl+w --> search for cgi.fix_pathinfo

uncomment and change to 0 (zero) -- Security Reasons

sudo service php7.0-fpm restart

sudo nano /etc/nginx/sites-available/default

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name server_domain_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}


-- Check syntax errors
sudo nginx -t 

sudo systemctl reload nginx
sudo service nginx reload

touch /var/www/html/info.php

echo "<?php" >> /var/www/html/test.php
echo "phpinfo();" > /var/www/html/test.php
(sudo nano /var/www/html/info.php)

Now go to visit http://<server-ip/dns>/test.php

If you see PHP info page -- > DONE!

Almost ... just remove test.php file if you don't want to be hacked soon...

sudo rm /var/www/html/info.php

Docker 32bit on VPS Ubuntu

Docker 32bit on VPS Ubuntu

:~# git clone https://github.com/docker/docker.git
:~# cd docker/
:~/docker#  mv Dockerfile Dockerfile.backup

:~/docker# sudo apt-get install build-essential
:~/docker# sudo make build
:~/docker# git clone https://github.com/docker-32bit/ubuntu.git
:~/docker# cd ubuntu

:~/docker/ubuntu# bash build-image.sh

:~/docker/ubuntu# sudo service docker start

:~/docker/ubuntu# sudo groupadd docker

:~/docker/ubuntu# sudo usermod -aG docker magvpn
:~/docker/ubuntu# exit
logout
Connection to <ip address> closed.

:~# apt-cache policy docker-engine


:~# uname -r
4.4.0-38-generic

:~# sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

:~#sudo reboot




:~# sudo service docker restart

:~#sudo service docker status

:~# sudo nano /etc/apt/sources.list.d/docker.list


:~# sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
:~# sudo reboot

#  docker images -a
# docker ps -a

# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
52bb703212fa        1c76a4c59dc5        "/bin/bash"         55 minutes ago      Exited (0) 55 minutes ago                       32buntu


from command docker ps -a use Image-ID and run with -ti options

#docker run -t -i 1c76a4c59dc5 /bin/bash

 

root@4e8daaf147d5:/# uname -a
Linux 4e8daaf147d5 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:41:41 UTC 2016 i686 i686 i686 GNU/Linuxroot@4e8daaf147d5:/#
oot@4e8daaf147d5:/# uname -m
i686
root@4e8daaf147d5:/



root@ubuntu-512mb-fra1-01:~# docker run hello-world
docker: Error response from daemon: rpc error: code = 2 desc = "oci runtime error: exec format error".


# docker version
Client:
 Version:      1.11.2
 API version:  1.23
 Go version:   go1.6.2
 Git commit:   b9f10c9
 Built:        Thu, 16 Jun 2016 21:17:51 +1200
 OS/Arch:      linux/386

Server:
 Version:      1.11.2
 API version:  1.23
 Go version:   go1.6.2
 Git commit:   b9f10c9
 Built:        Thu, 16 Jun 2016 21:17:51 +1200
 OS/Arch:      linux/386


#

Docker 32bit on VPS Ubuntu

Docker 32bit on VPS Ubuntu

:~# git clone https://github.com/docker/docker.git
:~# cd docker/
:~/docker#  mv Dockerfile Dockerfile.backup

:~/docker# sudo apt-get install build-essential
:~/docker# sudo make build
:~/docker# git clone https://github.com/docker-32bit/ubuntu.git
:~/docker# cd ubuntu

:~/docker/ubuntu# bash build-image.sh

:~/docker/ubuntu# sudo service docker start

:~/docker/ubuntu# sudo groupadd docker

:~/docker/ubuntu# sudo usermod -aG docker magvpn
:~/docker/ubuntu# exit
logout
Connection to <ip address> closed.

:~# apt-cache policy docker-engine


:~# uname -r
4.4.0-38-generic

:~# sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

:~#sudo reboot




:~# sudo service docker restart

:~#sudo service docker status

:~# sudo nano /etc/apt/sources.list.d/docker.list


:~# sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
:~# sudo reboot

#  docker images -a
# docker ps -a

# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
52bb703212fa        1c76a4c59dc5        "/bin/bash"         55 minutes ago      Exited (0) 55 minutes ago                       32buntu


from command docker ps -a use Image-ID and run with -ti options

#docker run -t -i 1c76a4c59dc5 /bin/bash

 

root@4e8daaf147d5:/# uname -a
Linux 4e8daaf147d5 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:41:41 UTC 2016 i686 i686 i686 GNU/Linuxroot@4e8daaf147d5:/#
oot@4e8daaf147d5:/# uname -m
i686
root@4e8daaf147d5:/



root@ubuntu-512mb-fra1-01:~# docker run hello-world
docker: Error response from daemon: rpc error: code = 2 desc = "oci runtime error: exec format error".


# docker version
Client:
 Version:      1.11.2
 API version:  1.23
 Go version:   go1.6.2
 Git commit:   b9f10c9
 Built:        Thu, 16 Jun 2016 21:17:51 +1200
 OS/Arch:      linux/386

Server:
 Version:      1.11.2
 API version:  1.23
 Go version:   go1.6.2
 Git commit:   b9f10c9
 Built:        Thu, 16 Jun 2016 21:17:51 +1200
 OS/Arch:      linux/386


#

Virtual Private Server / Cloud Server


Cloud Server / VPS - Virtual Private Server in Cloud


It's really nice and easy to get 2 months free from DigitalOcean ($10 starting budget) or also you can try Amazon Free-Tier's or Google Cloud. And don't forget Azure.

ssh -l <username> <ipaddress>
sudo apt-get install knockd


sudo nano /etc/default/knockd
 
change START_KNOCKD=0 >>> 
START_KNOCKD=1
 
sudo service knockd start
 knock <server_ip_address> 65123 65321 65123
sudo nano /etc/knockd.conf
sudo service knockd restart

::Final Command::

knock <server_ip_address> 5438 3428 3280 4479 && ssh <user>@<server_ip_address>
 

Raise Network Interfaces failed... Boot.Wait.Online - howto fix it

Raise Network Interfaces failed
(& how-to fix solution)


:~$ systemctl status networking.service 
 
* networking.service - Raise network interfaces
    Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
   Drop-In: /run/systemd/generator/networking.service.d
            `-50-insserv.conf-$network.conf
    Active: failed (Result: exit-code) since Sun 2016-08-14 17:02:50 PDT; 39min ago
    Docs: man:interfaces(5)
  Main PID: 893 (code=exited, status=1/FAILURE)

 Aug 14 17:02:41 sheeva systemd[1]: Starting Raise network interfaces...
 Aug 14 17:02:46 sheeva ifup[893]: /sbin/ifup: waiting for lock on /run/network/ifstate.eth0
 Aug 14 17:02:49 sheeva ifup[893]: RTNETLINK answers: File exists
 Aug 14 17:02:49 sheeva ifup[893]: Failed to bring up eth0.
 Aug 14 17:02:50 sheeva systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
 Aug 14 17:02:50 sheeva systemd[1]: Failed to start Raise network interfaces.
 Aug 14 17:02:50 sheeva systemd[1]: networking.service: Unit entered failed state.
 Aug 14 17:02:50 sheeva systemd[1]: networking.service: Failed with result 'exit-code'.

However the interface *is* up:

 :~$ ifconfig
 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

*****************************************************
Here is a possibly relevant config file
 
#Original Line
auto ens34
iface ens34 inet dhcp

#New line
allow-hotplug ens34
iface ens34 inet dhcp 
 
 --------- /etc/network/interfaces ------------
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo eth0
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
 
(iface eth0 inet static)
address 192.168.3.111
 netmask 255.255.240.000
 network 192.168.0.0
 broadcast 192.168.15.255
 gateway 192.168.1.1

iface eth0 inet6 static
       address 2001:1234:2d2:1:f2ad:4eff:fe00:3077
       netmask 64
--------- /etc/network/interfaces ------------ 
 
systemctl status <systemd or NetworkManager below>
systemd-networkd-wait-online.service
NetworkManager-wait-online.service
 
 
sudo systemctl disable systemd-networkd-wait-online.service
 sudo systemctl disable etworkManager-wait-online.service
 
...or you can also reduce the timeout
 
sudo nano /etc/systemd/system/network-online.targets.wants/networking.service 
 TimeoutStartSec=10sec
 
save (CTRL + x, y, Enter) and  
sudo systemctl daemon-reload 
 
systemctl status networking.service
networkctl
 
ifconfig enp5s0f1 up  
networkctl

ifconfig enp5s0f1 down
 ip link set enp5s0f1 name eth0

systemctl restart networking
 
 
*** ABOVE IS ONLY TEMP SOLUTION ***
 it won't persist after reboot. Create a 
 
 sudo touch /etc/udev/rules.d/70-persistent-net.rules 
 
(should contain smthng like:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="smsc95xx", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"


Saturday, October 1, 2016

iPhone 4 - untethered

If your iPhone is stuck in Recovery Mode, this fix should restore your iPhone to the factory settings, but a backup should have been created automatically when the OS was updated so you will have the option to restore from backup once the repair is made.

If iTunes is open, exit iTunes
Disconnect iPhone from computer USB
Click Start menu on desktop
Go to Control Panel
Go to Programs
Go to Programs and Features
Select Apple Mobile Device Support and click repair
Connect iPhone to computer USB (device should install automatically)
Open iTunes
When prompted, click restore iPhone
OS should install now and restore factory settings

iPhone will automatically restart when OS is successfully installed, and you will have the option to setup as new or restore from backup


Well that was a bit scary. I've just updated the firmware on my iPhone to 2.2 (the horrors!). Actually, this normally shouldn't be too much of a trial. The difference here is that I did it from Windows running inside VMWare on a Linux host.
I initially tried the naive approach of applying the update normally using iTunes (but running inside VMWware). Don't do this! The host (Linux) USB subsystem gets in the way leaving you with a somewhat useless iPhone in "recovery mode". It seems that the iPhone firmware upgrade procedure does something tricky with USB that doesn't play nicely with VMWare running on Linux.
To workaround the issue, some USB modules have to not be loaded on the Linux host during the upgrade. Extending the tips on Stephen Laniel's blog I created a blacklist file for modprobe that prevents certain USB modules from loading. Just unloading the modules manually isn't enough. The iPhone reconnects to the USB bus at least once during the upgrade process causing udev to reload the modules you've manually unloaded.
So before attempting the upgrade, create a file named something like /etc/modprobe.d/blacklist-usb with the following contents:
blacklist snd_usb_audio
blacklist usbhid
blacklist ehci_hcd
I'm not sure if ehci_hcd needs to be disabled, but I did this in my case.
Reload udev so that it knows about the new modprobe config file:
sudo /etc/init.d/udev reload
Now make sure these modules aren't already loaded:
sudo /sbin/modprobe -r snd_usb_audio
sudo /sbin/modprobe -r usbhid
sudo /sbin/modprobe -r usbhid
Now go back to VMWare, cross your fingers and attempt the firmware upgrade using iTunes. Things should progress along slowly.
You might find that at one point during the upgrade that iTunes sits there with a dialog saying "Preparing iPhone for upgrade". If this goes on for several minutes it could be that the iPhone isn't connected to VMWare anymore. iTunes is just waiting for the device to appear. If this happens, reattach the iPhone to VMWare using the "Removable Devices" option on VMWare's VM menu. It's a good idea to occasionally check that the iPhone is connected to VMWare during the upgrade.
Once the upgrade is complete you can remove the modprobe config file and reload VMWare:
sudo rm /etc/modprobe.d/blacklist-usb
sudo /etc/init.d/udev reload
For the record, this was done using iTunes 8 running on Vista running inside VMware Workstation 6.5.0 build-118166 on Ubuntu Intrepid (8.10).