Thursday, March 13, 2014

Adding Secondary IP Address in Ubuntu (Linux in general)

In my works, sometimes I need to configure router/wireless router with my PC. But since my PC only has one ethernet port that configured with static IP address, I have to find a way to be able to configure the router/wireless router without unplug it. One way is by adding secondary (virtual) IP address on existing ethernet port.

You can do this by using temporary or permanent way.

Temporary way:
Pretend that your ethernet is eth0, and you know that DHCP block IP from the router/wireless router is 192.168.1.0/24, you can set static IP address in that range:
$ sudo ip addr add 192.168.1.11/24 dev eth0
And when you finished, you can just delete that temporary additional IP:
$ sudo ip addr del 192.168.1.11/24 dev eth0

Permanent way:
You can add permanently by adding config in /etc/network/interfaces file:
auto eth0:1
iface eth0:1 inet DHCP
Then you set eth0:1 to be up:
$ sudo ifup eth0:1
Check to make sure you've got the correct IP address assignment:
$ sudo ifconfig -a | grep eth0 
 

Wednesday, March 12, 2014

Using and Samba Share External HardDisk on CentOS (Linux in General)

The scenario is I want to use an old PC (1GB RAM, HDD 20GB, Pentium-class) as a Samba share (file server). So I installed CentOS 6.5 on it, put a 3TB external HDD on it and then doing this configuration:
1. Migrating /home partition to 3TB external HDD
2. Configuring samba
3. Adding user and share

1. Migrating /home partition to 3TB external HDD:
I'm using this URL as a guidance, but I re-write this as simple as I have done:
a. Check the UUID of external HDD
$ sudo blkid
b. Backup /etc/fstab
$ sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d) 
c. Compare the two fstab files
$ cmp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
d. Edit original /etc/fstab
# (identifier) (location) (format) (some settings)
UUID=???   /mnt/home   ext3   defaults   0   2
replace the ??? in UUID with the one you've got from blkid command for your HDD

e. Create the mount folder
$ sudo mkdir /mnt/home
f. Reload the updated /etc/fstab
$  sudo mount -a
g. Copy existing /home to new partition
$ sudo rscync -aXS --exclude='/*/.gvfs' /home/. /mnt/home/
h. Confirm that all files and folders are copied successfully
$ sudo diff -r /home /mnt/home
i. Edit /etc/fstab, preparing for switch
# (identifier) (location) (format) (some settings)
UUID=???   /home      ext3       defaults   0   2
j. Moving /home to /old_home
$ cd / && sudo mv /home /old_home && sudo mkdir /home
k. Reload the updated /etc/fstab
$ sudo mount -a 
2. Configuring Samba:
a. Edit /etc/samba/smb.conf
security = user
[share]
     path = /home
     browseable = yes
     writable = yes
     public = yes
     guest ok = yes
b. Restart Samba service
$ service smb restart
$ service nmb restart 
3. Adding User and share:
a. Add samba user without UNIX login:
$ useradd -s /sbin/nologin [username]
b. Set samba password for new user:
$ smbpasswd -a [username]
c. Put the new user in the user group:
$ usermod -a -G [username] [usergroup] (e.g. usermod -a -G andy andy)
d. Set priviledge to certain folder only available to certain user/group:
$ chmod 775 /home/[username] 

You can check that there will be new folder created under /home with username you create. Using this command:
$ ls -lart /home
You can see that each of that folder own by username, this way when another username access the samba share, they can see another user folder, but don't have the priviledge to access them. This config already tested in my office with many users using different OS (Windows, Mac, Linux).