Tag Archives: ubuntu server

How to find the Linux Distribution Name and Version

In this post, I will try to show you that how we can check the version of Linux (Debian, Fedora, Ubuntu, CentOS), a particular system is running. Sometime we login to the system but we don’t know that which Linux distribution is running on it, So in this post, we will try to find it by using the lsb_release command that displays certain Linux Standard Base(LSB) and distribution-specific information.

To show the release number of installed distribution:
lsb_release -r

To show the distributor ID:
lsb_release -i

 To show all of the above information:
lsb_release -a

To find Out the Kernel Version by using this command:
uname -mrs

Where:

Linux – Kernel name
3.2.0-24-generic – Kernel version
x86_64 – Kernel is 64-bit

Hope this will help you!

Please Remember me in your prayers!

How to delete a file in linux with spaces

If you create a file in Linux with special character like %,$, * etc then you cannot remove it simply with rm command. In order to delete this kind of file, you need to use the inode number of this file. In this tutorial, I will try to show you that how we can delete the file in Linux that contains the special character and spaces in it’s name.

First, we will create a file with special character as well as spaces in it’s name:

touch "$this is %a +bad -example"

Let’s check the created file and it’s ownership information:

ls -l

From the ownership information, it is clear that I have rights to delete this file, now we try to delete this file:

rm is %a +bad -example

Note: You can if you add the \ before the name, but you’d have to guess as a user that it was used in the file creation.

To delete this file, we need to know it’s inode number by using this command:

ls -il

Then use the find command to delete the file by it’s inode:

find . -inum 270016 -exec rm -i {} \;

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

Access Control in SVN with authz_svn

In this post I will show you, how to control access in SVN using builtin moudle called authz_svn.It allows you to control the access in such a way that who can access the repository and what they can do on the repository (read or read-write), it even allows you to make groups and define access permission for groups. Above than that, you don’t need to change the underlay structure of your svn server.

Note: If you want to install the SVN Server then, please refer this post:

These are the same usernames that we created in previous tutorial, using this command:

sudo htpasswd -m /etc/apache2/dav_svn.passwd arbab

For this post, we will use these repositories :

cd /svn
ls -l

Read more of this post

Ubuntu as a firewall/gateway router

In this simple tutorial, I will show you how to configure the Ubuntu server as Internet gateway, which also serves as DHCP and DNS Server!

Scenario:
  1.  Ubuntu server with 2 Network Cards 1 is connected to Internet and named as WAN,which takes the ip address through dhcp and the other one is connected to the Local Network and named as LAN,which has static ip address 10.10.10.1/24.
  2. Windows Client(s), which takes ip address from Ubuntu Server, also use it as name resolution server (Internet) and gateway.
Prerequisite(s):
  1. Change the Network Cards name using this Tutorial.
  2. Install the Webmin, also using this Tutorial.

First, We will check the ip address setting for the above scenario:

sudo nano /etc/network/interfaces

It will show the ip address that associated with the each interface:

Now, we also examine the output of ifconfig command:

ifconfig

We need to install two packages to accomplish the goal of this tutorial:

sudo apt-get install isc-dhcp-server bind9

Because there is more than one network card(s) in Ubuntu server, so we need to select the network card on which our server will be listen for dhcp request. (By default, it listens on eth0/WAN in this case).
We can change this by editing the  /etc/default/isc-dhcp-server file:

sudo nano /etc/default/isc-dhcp-server 

Put LAN in the INTERFACES place:

Now we will change the default configuration by editing /etc/dhcp/dhcpd.conf, I normally delete everything inside the file and manually add the configuration that suits my needs :-)

sudo nano /etc/dhcp/dhcpd.conf

Here is my dhcpd.conf file, you need to change it according to your needs:

ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
option subnet-mask 255.255.255.0;
option broadcast-address 10.10.10.255;
option routers 10.10.10.1;
option domain-name-servers 10.10.10.1;
option domain-name "ubuntu.firewall";
subnet 10.10.10.0 netmask 255.255.255.0 {
range 10.10.10.50 10.10.10.200;
}

Restart dhcp service using the following command:

sudo service isc-dhcp-server restart 

To enable ip forwarding, edit /etc/sysctl.conf file:

sudo nano /etc/sysctl.conf

Uncomment the  net.ipv4.ip_forward=1:

Login to the Webmin using https://server-ip:10000, In my case it is,https://tendo-Firewall:10000.

Follow these steps in order to enable the MASQUERADE(NAT):

To save the Firewall(Iptables) setting, do this:

After saving the setting, check the /etc/network/interfaces file once again:

sudo nano /etc/network/interfaces

Notice that it added one line under LAN interface:

The purpose of this line is to enable the Masquerading, as soon as the interface LAN will up and running!

Test from Windows 7 that connect to LAN:

Hurry, We are able to access the Internet, this mean we configure the Ubuntu server as gateway successfully 🙂

Note: In order to secure this server we need to do some extra work, which I will show you really soon!

Hope this will help you!

Please Remember me in your prayers!

Multiple Interface DHCP Server on Ubuntu 12.04LTS

Scenario:

Ubuntu dhcp server with 3 network cards (eth0,eth1,eth2), eth0 is connected to upstream server, in order to get the internet access, eth1 is connected to the 10.10.10.0/24 subnet and serve as dhcp server  while eth2 serve for 172.16.10.0/24 subnet.

Before configuring the dhcp server on Ubuntu, we shall check the ip address setting on our Ubuntu server:

sudo nano /etc/network/interfaces

Ubuntu as DHCP Server:

To install dhcp server, enter the following command at a terminal prompt:

sudo apt-get install isc-dhcp-server

We have more than one network card(s) in our Ubuntu server, so we need  to select the network card(s) on which our server will be listen for dhcp request. (By default, it listens on eth0 but we want to change it to eth1 and eth2).

We can change this by editing  /etc/default/isc-dhcp-server file:

sudo nano /etc/default/isc-dhcp-server

Change “eth0” to the interface(s) on which we want that our server will listen for dhcp request (In this case, it’s eth1 and eth2):

It’s always a good practice to make a backup copy of /etc/dhcp/dhcpd.conf file:

sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak 

Now we will change the default configuration by editing /etc/dhcp/dhcpd.conf, I normally delete everything inside the file and manually add the configuration that suits my needs :-)

sudo nano /etc/dhcp/dhcpd.conf

Here is my dhcpd.conf file, you need to change it according to your needs:

ddns-update-style none;
authoritative;
log-facility local7;

subnet 10.10.10.0 netmask 255.255.255.0 {
 option routers 10.10.10.1;
 option subnet-mask 255.255.255.0;
 option broadcast-address 10.10.10.255;
 option domain-name-servers 10.10.10.1;
 option domain-name "eth1.lan";
 default-lease-time 600;
 max-lease-time 7200;
 range 10.10.10.10 10.10.10.100;
}

subnet 172.16.10.0 netmask 255.255.255.0 {
 option routers 172.16.10.1;
 option subnet-mask 255.255.255.0;
 option broadcast-address 172.16.10.255;
 option domain-name-servers 172.16.10.1;
 option domain-name "eth2.lan";
 default-lease-time 600;
 max-lease-time 7200;
 range 172.16.10.10 172.16.10.100;
}

Restart dhcp service using the following command:

sudo service isc-dhcp-server restart 

Confirm the IP Address on Windows 7 that connect to eth1:

Confirm the IP Address on Windows XP that connect to eth2:

To Check the DHCP Leases on Ubuntu Server:
sudo tail /var/lib/dhcp/dhcpd.leases

 

Hope this will help you!

 

Please Remember me in your prayers!


InterVLAN Routing using Ubuntu with 1 Interface

Scenario:
  • Router: Ubuntu Server with 1 network card.
  • Clients: 2 WindowsXP in VLAN10,1 Ubuntu and 1 CentOS in VLAN20.
  • Switch: Cisco 2960
Cisco 2960 Switch Configuration:
interface FastEthernet0/1
description CONNECTED TO UBUNTU ROUTER
switchport mode trunk
!
!
!
interface FastEthernet0/5
description WINXP-1
switchport access vlan 10
switchport mode access
!
interface FastEthernet0/6
description WINXP-2
switchport access vlan 10
switchport mode access
!
!
!
interface FastEthernet0/15
description UBUNTU CLIENT
switchport access vlan 20
switchport mode access
!
interface FastEthernet0/16
description CentOS CLIENT
switchport access vlan 20
switchport mode access
 Ubuntu Router Configuration:

To install the vlan support on ubuntu, use this command:

sudo apt-get install vlan

Now we shall configure the vlans on Ubuntu router by editing the /etc/network/interfaces:

sudo nano /etc/network/interfaces

To enable ip forwarding, edit /etc/sysctl.conf file:

sudo nano /etc/sysctl.conf

Change net.ipv4.ip_forward from 0 to 1:

Load “8021q” kernel module:

(Optional): If the Ubuntu router didn’t load the 8021q kernel module at boot time, then use this command to add  the module to the kernel on boot:

sudo su -c 'echo "8021q" >> /etc/modules'

Restart the Networking service:

sudo /etc/init.d/networking restart

Use the ifconfig command to check the newly created vlan interfaces:

ifconfig

Verify the vlan configuration:

sudo cat /proc/net/vlan/config

Test from WinXP-1:

Test from WinXP-2:

Test from Ubuntu Client:

Test from CentOS Client:

Hope this will help you!

Please Remember me in your prayers!

Mercurial Server on Ubuntu 12.04 LTS with Web Access

First we shall verify the version of the Ubuntu server that is running on our machine!

lsb_release -a

Install the Apache if you haven’t it already on your server!

sudo apt-get install apache2

Test the apache directly from the shell by doing a wget to the localhost. You will see the 200 OK response code.

Now install the Mercurial using the following command:

sudo apt-get install mercurial

Check the version of installed mercurial server:

hg --version

Let’s configure the master hgrc configuration file in order to remove the SSL restriction, allow to push the repository through web and trust the apache user (www-data).

sudo nano /etc/mercurial/hgrc

Add these lines to the hgrc file:

[web]
allow_push = *
push_ssl = false
allow_archive = gz, zip, bz2
[trusted]
users = www-data

Now configure the directory where Mercurial will keep all its repositories and serve them through Apache!

cd /
sudo mkdir mercurial
sudo mkdir mercurial/repositories
sudo chown -R www-data:www-data /mercurial

Let’s configure the hgweb.config!

cd /mercurial
sudo nano hgweb.config

Enter the following lines:

[web]
style = gitweb
[collections]
/mercurial/repositories = /mercurial/repositories

Let’s configure the hgweb.cgi script in order to serve the repositories via Apache:

sudo cp /usr/share/doc/mercurial/examples/hgweb.cgi /mercurial
cd /mercurial
sudo chmod a+x hgweb.cgi

Open hgweb.cgi with nano:

sudo nano hgweb.cgi

Find the line that reads config=”…..” and replace with the following line:

Now we shall configure the Apache so it runs the hgweb.cgi when the /mercurial virtual directory is requested.

cd /etc/apache2
sudo mkdir mercurial
cd mercurial
sudo nano mercurial.conf

Type the following in the mercurial.conf file:

Move to the apache sites directory and edit the default file:

cd /etc/apache2/sites-available
sudo nano default

Enter the command in order to link the mercurial.conf file to Apache:

Include /etc/apache2/mercurial/mercurial.conf

Restart the apache server:

sudo apache2ctl restart

Now create a first repository as test, inside the /mercurial/repositories:

cd /mercurial/repositories
sudo mkdir first_repo
cd first_repo
sudo hg init

Change the owner of the repository to the Apache user:

sudo chown -R www-data:www-data /mercurial

To configure the security, we have to tell the Apache that allow only those users who are registered in the password file.

cd /mercurial
sudo htpasswd -mc hgusers arbab 
sudo chown www-data:www-data hgusers

Note: repeat command for more users without adding c.

Time to Test, Launch your browser pointing to http://servername/mercurial:

In order to add the “Description” and “Contact” detail, do the following steps:

cd /mercurial/repositories/first_repo/
cd .hg
sudo nano hgrc

Add these lines to hgrc:

[web]
contact = Arbab Nazar
description = First Mercurial Repository!

Refresh your browser, now you will see the contact and the descriptio 🙂

To solve the push permission denied error:

cd /mercurial/repositories
cd first_repo
sudo chmod -R 777 .hg

Again do it!!!

sudo chown -R www-data:www-data /mercurial

Congrats! now we have a working Mercurial server on Ubuntu 12.04 :-)

Hope this will help you!

Please Remember me in your prayers!

SVN Server on Ubuntu 12.04 LTS with Web Access

To install SVN server, run this command at the command prompt:

sudo apt-get install subversion libapache2-svn apache2

Make the directory where you want to keep the svn repositories and edit the dav_svn.conf file:

sudo mkdir /svn
sudo nano /etc/apache2/mods-enabled/dav_svn.conf

Delete all the data and make it simple like this 🙂

<Location /svn>
DAV svn
SVNParentPath /svn
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
</Location>

To create a svn user , use the following command:

sudo htpasswd -cm /etc/apache2/dav_svn.passwd arbab

We only need to use the –c option for the FIRST TIME, when you create a user, after that you will only use the -m option.

Move to the folder, where you want to keep your repositories and create your first repository:

cd /svn
sudo svnadmin create test_repo

Make sure you set the permissions of the /svn directory to apache with the following command:

sudo chown -R www-data:www-data /svn

Restart the apache2 service:

sudo /etc/init.d/apache2 restart

On Windows machine, Right-Click  and select the SVN Checkout, inside the directory where we want to store the working copy (In my case, it’s on desktop).

Enter the repository’s URL and click OK, it will be prompted for a login and password.  Enter the login information and click OK.

We shall receive a screen that looks like this:

Create some test file inside the checkout repository, Right-Click and Select the SVN Commit:

Enter the comments that describe the purpose of this commit:

It will be prompted for a login and password.  Enter the login information and click OK.

The result of the commit will appear in a dialog window.

Congrats! now we have a working SVN server on Ubuntu 12.04 🙂

Hope this will help you!

Please Remember me in your prayers!

Time synchronization on Ubuntu 12.04LTS using NTP

To install the ntp, just enter this command at the terminal:

sudo apt-get install ntp

After installation, edit the default ntp configuration:

sudo nano /etc/ntp.conf

Commented out the default Ubuntu server,you can add your own time-servers here to synchronize with, http://www.pool.ntp.org/zone/europe or http://www.pool.ntp.org/zone/north-america lists:

After you are done with the configuration, just restart the ntp service:

sudo service ntp restart

To check if the NTP service is synchronizing:

sudo ntpq -c lpeer

To check the synchronization log:

sudo tail -f /var/log/syslog

Geeky Comparison with Windows clock after synchronization 🙂

Troubleshooting:

If you are using the firewall, then just allows port 123 on UDP level.

Hope this will help you!

Please Remember me in your prayers!

How to Install the DHCP Server on Ubuntu 12.04LTS

Ubuntu as DHCP Server:

To install dhcp server, enter the following command at a terminal prompt:

sudo apt-get install isc-dhcp-server

If there is more than one network card(s) in your Ubuntu server, then you have to select the network card on which your server will be listen for dhcp request. (By default, it listens on eth0).

You can change this by editing  /etc/default/isc-dhcp-server file:

sudo nano /etc/default/isc-dhcp-server

Change “eth0” to the interface on which you want that your server will listen for dhcp request (In my case, it is eth1):

It’s always a good practice to make a backup copy of /etc/dhcp/dhcpd.conf file:

sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak 

Now we will change the default configuration by editing /etc/dhcp/dhcpd.conf, I normally delete everything inside the file and manually add the configuration that suits my needs 🙂

sudo nano /etc/dhcp/dhcpd.conf

Here is my dhcpd.conf file, you need to change it according to your needs:

ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
option subnet-mask 255.255.255.0;
option broadcast-address 10.10.1.255;
option routers 10.10.1.1;
option domain-name-servers 10.10.1.1;
option domain-name "ubuntu.internal";
subnet 10.10.1.0 netmask 255.255.255.0 {
range 10.10.1.50 10.10.1.200;
}

Restart dhcp service using the following command:

sudo service isc-dhcp-server restart 

Configure Windows as DHCP Client:

Just follow these steps, in order to configure your Windows machine as DHCP client (In my case, it’s Windows 7):

To check the IP Address on Windows 7:

To Check the DHCP Leases on Ubuntu Server:
sudo tail /var/lib/dhcp/dhcpd.leases

Hope this will help you!

Please Remember me in your prayers!

%d bloggers like this: