How to create an autostart script in Linux (Red Hat / CentOS / Fedora)

How to create an auto start script in Linux (Red Hat / CentOS / Fedora):

Option 1: Use chkconfig script to run /etc/init.d/…

  1. Create a script and place in /etc/init.d (e.g /etc/init.d/myscript). The script should have the following format:
#!/bin/bash
# chkconfig: 2345 20 80
# Source function library.
. /etc/init.d/functions
start() {
    # code to start app comes here 
    # example: daemon program_name &
}
stop() {
    # code to stop app comes here 
    # example: killproc program_name
}
case "$1" in 
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here 
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac
exit 0 

Enable the script

  1. $ chkconfig --add myscript 
    $ chkconfig --level 2345 myscript on 
    
  2. Check the script is indeed enabled – you should see “on” for the levels you selected.
    $ chkconfig --list | grep myscript
    

You can then use the script like so /etc/init.d/myscript start or chkconfig myscript start.

Option 2: Another Option is to use crontab job and run it at Boot time.

You need to use special string called @reboot. It will run once, at startup after reboot command.

@reboot  /path/to/job
@reboot  /path/to/shell.script
@reboot  /path/to/command

This is an easy way to give your users the ability to run a shell script or command at boot time without root access. First, run crontab command:
$ crontab -e
OR
# crontab -e -u doddi

Run a script called /home/doddi/bin/myScript.sh
@reboot /home/doddi/bin/myScript.sh 

Under RHEL / CentOS / Fedora, you need to enable crond on boot:
# chkconfig crond on
# service crond restart

If you are using modern distro with systemd, try
# systemctl enable crond.service
# systemctl restart crond.service
# systemctl status crond.service

 

Description about My VMware Home Lab in MacBook Pro

I just want to write this, as a personal note for me. Since I always forget when someone ask me this question about my Personal VMware Home Lab that I used to do some researches on-premise.

As described earlier in this post: http://bicarait.com/2015/09/12/penjelasan-mengenai-my-computer-home-lab-untuk-vmware-technology/
Currently I am adding another Home Lab for my research and demo to VMware customers.

MacBook Pro Retina 15-inch, OS X El Capitan (10.11.6), Quad Core 2.5 GHz Intel i7, 16 GB Memory, NVIDIA GeForce GT750M 2GB, 1 TB Flash Storage.

Detail Components:

  • I am using VMware Fusion Professional Version 8.1.1 to create Nested Virtualisation.
  • Control Server is using CentOS Linux 7 (control01.lab.bicarait.com)
    Function: NTP (ntpd), DNS (bind), LDAP (openldap), DHCP (dhcpd)
    IP: 172.16.159.142
    Username: root, Password: VMware1!
  • Shared Storage is using Openfiler 2.6 (storage01.lab.bicarait.com)
    Access: https://172.16.159.139:446/
    Username: openfiler, Password: password
    iSCSI: iqn.2006-01.com.openfiler:tsn.a7cd1aac2554 – “fusiondisk (/mnt/fusiondisk/)” using volume name “fusioniscsi1” size 100 GB – /dev/fusiondisk/fusioniscsi1 – iSCSI target: 172.16.159.139 port 3260 – datastore: ds_fusion_01
  • Virtualisation for Management Cluster is using ESXi 6.0 U2 (esxi01.lab.bicarait.com)
    IP: 172.16.159.141 (vmkernel management)
    Username: root, Password: VMware1!
  • Virtualisation for Payload Cluster is using ESXi 6.0 U2 (esxi02.lab.bicarait.com & esxi03.lab.bicarait.com)
    IP: 172.16.159.151 & 172.16.159.152 (vmkernel management)
    Username: root, Password: VMware1!
  • vCenter is using vCenter Appliance 6.0 U2 (vcsa01.lab.bicarait.com)
    IP: https://172.16.159.150/vsphere-client
    Username: administrator@vsphere.local, Password: VMware1!
  • Virtual Machines to Play with:
    PhotonVM01 – IP:  DHCP – Username: root, Password: VMware1!

This is the screenshot of my fusion environment:

screen-shot-2016-11-03-at-15-32-42

screen-shot-2016-11-04-at-15-11-52

 

Kind Regards,
Doddi Priyambodo

How to Recover Deleted Files (rm -rf) or Accidentally click Empty Recycle Bin

So, sometimes “shit” can happen. Accidentally do rm -rf in linux OS, or click empty recycle bin in windows. Or, disk is corrupt, boot sector is broken, etc. This is a very useful tool to help you to “try” to fix it. Sometimes it works, and sometimes it doesn’t. At least you try… 😉 Err, wrong emoticon, it should be 🙁

TestDisk is OpenSource software and is licensed under the terms of the GNU General Public License (GPL v2+).

TestDisk is powerful free data recovery software! It was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software: certain types of viruses or human error (such asaccidentally deleting a Partition Table). Partition table recovery using TestDisk is really easy.

TestDisk can

  • Fix partition table, recover deleted partition
  • Recover FAT32 boot sector from its backup
  • Rebuild FAT12/FAT16/FAT32 boot sector
  • Fix FAT tables
  • Rebuild NTFS boot sector
  • Recover NTFS boot sector from its backup
  • Fix MFT using MFT mirror
  • Locate ext2/ext3/ext4 Backup SuperBlock
  • Undelete files from FAT, exFAT, NTFS and ext2 filesystem
  • Copy files from deleted FAT, exFAT, NTFS and ext2/ext3/ext4 partitions.

Download the file from here: http://www.cgsecurity.org/wiki/TestDisk_Download

 

Kind Regards,
Doddi Priyambodo

Important Message from Pat Gelsinger (CEO of VMware Inc.)

Last week, Pat sent a twitter message. I felt really grateful that he is the CEO of VMware (http://www.vmware.com/company).

“Remember, we work to live, not live to work. Hope you all get extra time with family”.

Thanks Pat for reminding us again about this (read: me)!

 

Kind Regards,
Doddi Priyambodo

YUM Repository Installation for RedHat / CentOS / Fedora

 

There are several people still asking about how to create YUM Repository in their Local Linux distribution. So, here you go…

Step 1: Install “createrepo”

To create Custom YUM Repository we need to install additional software called “createrepo” on our cloud server. We can install “createrepo” by running the following command from console:

yum install createrepo

Step 2: Create Repository directory

We need to create a new directory that will be the location of our Custom YUM Repository and will hold the desired RPM package files. We can do this with the following command from console (choose a different /repository1 directory name if you like):

mkdir /repository1

Step 3: Put RPM files to Repository directory

If RPM package files are not yet present on our VPS we need to transfer them to our cloud server via FTP or SSH – use software like WinSCP (free SFTP client and FTP) or similar. We can also download RPM package files directly to our VPS (internet connection needed) with “wget” command from console (please change HTTP link accordingly): Continue reading YUM Repository Installation for RedHat / CentOS / Fedora

Configure a Wi-Fi router to share your computer’s 3G data stick connection

How to configure a Wi-Fi router to share your computer’s 3G data stick connection to everyone.

  1. Connect to the Internet on your 3G data stick.
  2. Plug your laptop to one of the router’s LAN ports. Wait until the router connects correctly.
  3. Click Start > Control Panel > View Network status and tasks > Change adapter settings
  4. Right click the modem (or the connection where you get Internet from) > Status > Details. Write down the “IPv4 DNS Servers” on a piece of paper. Click Close once.
  5. Right click the Local Area Network > Status > Details. Write down the “IPv4 Default Gateway”. Click Close > Close.
  6. Open the browser and type the IPv4 Default Gateway on the addressbar. Routers are all different so you need to figure out where to find and configure the following:
    • Review your wireless security settings. What is your SSID? What is your security key? Write this down.
    • Under WAN, choose “Static IP” instead of “PPPoE” or “Automatic – DHCP”.
    • Under WAN, set the WAN IP to 192.168.137.2
    • Under WAN, set the Netmask to 255.255.255.0
    • Under WAN, set the Gateway to 192.168.137.1
    • Under WAN, set the DNS Server(s) to the “IPv4 DNS Servers” you got from step 4.
    • Click Save.
  7. Unplug your laptop from the router’s LAN port and plug it to the WAN port. Wait until the router connects correctly.
  8. Go back to the “Network connection” screen on Step 4 > Properties > Sharing >
    • Check “Allow other network users to connect through this computer’s Internet connection.”
    • Under Home networking connection choose “Local Area Connection”
    • Click OK then OK.
  9. Right click the Local Area Network > Status > Details. Is the IPv4 address “192.168.137.1”? If yes, then you’re done! Tell everyone to connect to the wireless router and they will be online.

NOTE: There’s a router-less method using “ad-hoc networks”, but using a router provides more range and can handle more connected computers or wifi phones.


To put things back to before.

  1. Uncheck the “Allow other network users to connect through this computer’s Internet connection.” on Step 7. Click OK.
  2. Unplug the laptop from the router’s WAN port and plug it into one of its LAN ports.
  3. Open a browser and visit the “IPv4 Default Gateway” address you got from Step 5.
  4. Switch the WAN setting from “Fixed IP” back to “Automatic – DHCP”. Save changes.
  5. You’re done!

Only one more thing: Sometimes, after the configuration, it is necessary to restart your modem, computer and router. In one situation, I connected them in this way. Modem ? My Computer ? Router ? all other devices (like laptop, network printer, other computer).

 

Source : http://superuser.com/questions/241651/setting-up-wifi-router-as-a-switch-for-internet-connection-sharing

Mekanisme IP Port Forward di Linux, Mikrotik, Windows

IP & Port Forwarding. Mekanisme port forward adalah sebuah cara untuk melakukan penerusan paket ke tempat lain, tanpa client perlu mengetahui dan merasakan bahwa sebenarnya paket itu bukan ditembak ke server tujuan dari client. Melainkan dialihkan ke server yang lain.

Konfigurasi : CLIENT —>SERVER (published) —> SERVER (local)

Mekanisme untuk melakukan Port Forwarding adalah sebagai berikut :

1. LINUX

http://www.uday.com.np/tools/iptables.php (ini untuk wizard secara visualisasi)
http://linux.about.com/od/ipm_howto/a/hwtipm52t00.htm (ini script otomatisnya)

Contoh Kasus :

1). Kita ingin mengalihkan seluruh request dari client yang masuk dengan port 15035 menuju ke 192.168.121.5:15035

# iptables -t nat -I PREROUTING -p tcp –dport 15035 -j DNAT –to 192.168.121.5

Contoh lain :
# iptables -t nat -A PREROUTING -p tcp –dport 90080 -j DNAT –to 10.4.1.15:80

Contoh lain :
# iptables -t nat -A PREROUTING -d 192.168.204.90 -j DNAT –to-destination 10.19.184.2
# iptables -A FORWARD -j LOG –log-prefix ‘DROPPING: ‘ –log-level info
# tail -fn100 /dev/log/messages | grep DROPPING

2). Kita ingin menjalankan APACHE TOMCAT yang berjalan secara lokal di port 8080, tetapi kita ingin menampilkan keluar sebagai port 80 tanpa merubah konfigurasi TOMCAT, tetapi menggunakan iptables.

# iptables –table nat –append PREROUTING –protocol tcp –destination-port 80 –in-interface eth0 –jump REDIRECT –to-port 8080

Catatan:
Aturan diatas tidak bisa melakukan redirect permintaan lokal. Karena menggunakan perintah PREROUTING. Jika ada client yang jalan langsung di server, maka gunakan port 8080.

2. MIKROTIK

Berikut ini mekanisme untuk membelokkan paket dari server 202.162.111.111:80 ke 10.14.1.101:8080

/ip firewall nat add chain=dstnat dst-address=202.162.111.111 protocol=tcp dst-port=80
action=dst-nat to-addresses=10.14.1.101 to-ports=8080

3. WINDOWS

Biasanya saya menggunakan aplikasi Free dari Internet untuk tujuan ini, yaitu :
– http://www.simpleportforwarding.com/
– http://www.quantumg.net/portforward.php

Launching site bicarait.com | Let’s Talk about IT

I believe, ketika kita hendak melakukan sesuatu. Kita harus memiliki Visi, Misi, dan Nilai Inti (Vission, Mission, Core Values) yang kita anut dalam pelaksanaan pekerjaan tersebut.

Well, hari ini adalah hari kelahiran BicaraIT.com. The Birth Date of this blog was on THURSDAY, March 11 2010 at 20:55 GMT+7 in Jakarta Indonesia.

Langsung saja… Vission, Mission, Values dari BicaraIT.com adalah :

VISSION : To Be the Most Inspirational IT Blogs in Indonesia
MISSION : Give the Best and make my self Useful to the Comunity in my capability Area
VALUES : Love, Integrity, and always Sharpen The Saw (Innovation and Continous Improvement)