Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Wednesday, November 11, 2009

/etc/hosts file

File /etc/hosts is a configuration file you will find in almost any operating system including for example Windows. It is a very basic file for configuring the network. This one is used for locally mapping hostnames to IP addresses. The system will always prefer to use /etc/hosts file, rather than any DNS server. So if you have a record with an IP address in your /etc/hosts the system will use this one, if you try to access the hostname you specify.

The syntax is really easy. First you specify an IP address of the host and then all aliases divided by a space. You may specify unlimited number of aliases. So your /etc/host file may look like this:

127.0.0.1 localhost my-computer
10.0.0.1 server second-computer

 Once you save this file you may try a ping to second-computer or server and it will go to 10.0.0.1. The changes you made will be applied immediately once you save the file. There's no need to restart any service or run some program.

There are some limitations for the alias format. It may contain any alphanumeric character,  minus sign ("-") and a dot (".") but these two must not be located on the beginning or at the end of the alias.

You may also find this file useful, when you would like to block to some server with for example fraudulent content. If you'd like to block access to for example badsite.com you can add this line:

0.0.0.0 badsite.com

This will resolve badsite.com as 0.0.0.0, which doesn't lead anywhere.

Tuesday, November 10, 2009

Setting up NFS server

Though using samba may work really well sometimes you may like to have a more native linux solution for sharing files. A situation, where I would use NFS rather than Samba is a sharing between two linux computers.

First you will have to install a package providing nfs server on your system. On ubuntu or debian I would do that by

apt-get install nfs-kernel-server

Now, assuming that you have an NFS daemon installed it's time for configuring it. The configuration in stored in /etc/exports file and should look like this, when you open it:


# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) 
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)

Every single line in this file will create a new exported (shared) folder. Let's imagine, that you would like to make folder /sharing available to all computers in your local network. This is achieved by this line:

/sharing 10.0.0.0/24(rw,sync,no_subtree_check)

As you can see the syntax is really easy. First you specify the folder, you would like to export, and then the host, that will have access to this share. I have specified an ip address and a mask, which will allow access to all computers with ip range from 10.0.0.1-10.0.0.255. The ip address is specified in a format of address/mask. The mask may be written in both formats(255.255.255.0,24)-You can specify a hostname, or a domain as well. Setting * will allow access to anyone.

All other options are specified inside parenthesis right after the allowed clients. Let's specify at least the most important ones.

  • ro - read only
  • rw - read and write
  • sync - reply to requests only after the changes have been committed to stable storage
  • no_subtree_check - disables subtree check
  • root_squash - maps requests from uid 0 to anonymous user
  • no_root_squash - turns off root squashing - will access all files as root
  • all_squash - maps all users to anonymous user

I know, that some explanations aren't absolutely clear. You may have a look at man exports for more detailed description.

Every time you finish altering /etc/exports you must execute this:

exportfs -a

After this your nfs server is all set and you should be ready to connect.

Saturday, November 7, 2009

How to set up Samba server

Imagine, that you have a computer running linux (e.g. home server) and you would like to share some files with your windows computer. Now you have two possibilities. You can either install nfs client on your windows computer, or a samba server on linux. Today we will have a look on how to set up a samba server on your linux system.

First you will need to install the samba itself. This differs a lot according to your distribution, but on debian I would do simply

apt-get install samba

Now, that you have the samba installed on your computer, it's time for the funny part, the configuration. The main configuration file of samba should be /etc/samba/smb.conf. It will be filled with some default data, but I recommend you to delete this file and start writing a new one with your favourite editor.

rm /etc/samba/smb.conf
nano /etc/samba/smb.conf

Now fill your new file with this:


[global]
workgroup = MASLIK.CZ
server string = maslik.cz samba server
browseable = yes
hosts allow = 10.0.0.
security = user
hide dot files = yes

[sharing]
path = /export
browseable = yes
writable = yes

 This is the very basic configuration. You should of course fill your own values to workgroup and hosts allow in the global part. After that part we define all of our shares. I have one folder defined. For windows clients it will be shown as a sharing folder (the [sharing] string manages this), but the real folder shared is /export. You may of course also set writable = no, if you wish to have a read-only folder.

After changing the configuration file you should restart the samba daemons, if you are not planning to restart your computer.

/etc/init.d/samba restart

Now the last step, you have to take is to make a new samba password for any user, that will have access to your samba server. You will do that by this command:

smbpasswd -a user

After entering this command you will be prompted to enter the new password. This would create a password for user user, so fill your own username. Finally you may also like to use chmod to update the access rights to your shared folder.

So I wish you good luck with setting up your server. Samba of course gives us many more possibilities of settings. One of the most important is a printer sharing. We will have a look at that next time.