# How to share directories in LAN?

## pmam

Hi,

How to share directories in Local Network - It is a simple sharing, between machines which connected to the same router. 

I installed Samba according this HowTo and it is working, but the smb.conf file found in this HowTo - http://wiki.gentoo.org/wiki/Samba/HOWTO -

not suitable for me or I do not know how to adjust it with my data - Please inform me with smb.conf that would be relevant to my simple sharing.

The result should be - Ability to see and transfer files between machines of the same Local Network.

EDIT: When I press on Network>Network Services in Dolphin I get this message: 'KDE has been built without Zeroconf support.' - 

Should I install 'dev-dotnet/mono-zeroconf' or 'kde-base/zeroconf-ioslave [ Masked ]'?

----------

## cwr

 *pmam wrote:*   

> Hi,
> 
> How to share directories in Local Network - It is a simple sharing, between machines which connected to the same router. 
> 
> I installed Samba according this HowTo and it is working, but the smb.conf file found in this HowTo - http://wiki.gentoo.org/wiki/Samba/HOWTO -
> ...

 

I use a public directory set up in /etc/samba.smb conf as follows:

```

# A publicly accessible directory, read/write to all users. Note that all files

# created in the directory by users will be owned by the default user, so

# any user with access can delete any other user's files. Obviously this

# directory must be writable by the default user. Another user could of course

# be specified, in which case all files would be owned by that user instead.

# The default create mask is 0744.  The default force create mode is 0000.

[public]

    comment = Public directory

    path = /home/public

    public = yes

    guest ok = yes

    guest only = yes

    writable = yes

    printable = no

    create mask = 0644

    force create mode = 0660

```

The directory itself has permissions:

```

drwxrwsr-x 2 guest users 4096 2013-12-30 20:42 /home/public

```

where a typical user belongs to the "users" group.

That works for various version of Windows and Linux.

Will

----------

## pmam

Will Hi,

I am quite lost in this sharing issue... I followed the HowTo Samba but I think it is not so clear, 

at least for someone like me, that doing it first time. Anyway, something is missing and I do not know what.

I tried to edit smb.conf and put only the code you post here - Is it enough or I need to add something to this file? 

Also, my path is a little different from yours (but I created a /home/public directory like yours for the testing) - My is: /home/my_username/public.

Here are the things I have done according this HowTo:  

```
emerge --ask net-fs/samba

root # mkdir /etc/samba/printer

root # mkdir /var/spool/samba

root # mkdir /home/samba/public

root # mkdir /home/samba

root # mkdir /home/samba/public

root # chmod 755 /home/samba

root # chmod 755 /home/samba/public
```

Initiating samba service - I have one machine with systemd so:

```
systemctl enable smbd.service

systemctl enable nmbd.service
```

And start them. For the other machine with openRC:

```
root # rc-update add samba default

root # /etc/init.d/samba start
```

I checked with this command from the HowTo and it seems OK - /usr/bin/testparm.

Please advise!

Thanks

----------

## pmam

I do not know how to work it out... 

There is 'share' feature in DE settings -Should I use it together with samba?

Oh, I made a salad of all this sharing - All I wanted is to share directories between Linux machines...

Can someone help with a few lines of the necessary steps to do in order to dance Samba...

Please advise!

BTW: I could not connect Gentoo's Forum for long time today - Is it global problem or only local?

----------

## cwr

There should be a full smb.conf.default in your /etc/samba directory; the code I posted

is just a stanza to share a directory (any directory can be shared, the name doesn't matter,

it just has to have the right permissions).  There are several like it towards the end of

smb.conf.default.

The default smb.conf is pretty long, but the defaults work and it doesn't need much

editing - the changes I've made are all toward the head of the file:

```

#======================= Global Settings =====================================

[global]

# 1. Server Naming Options:

# workgroup = NT-Domain-Name or Workgroup-Name

    workgroup = WORKGROUP

# netbios name is the name you will see in "Network Neighbourhood",

# but defaults to your hostname

;   netbios name = <name_of_this_server>

   netbios name = MOULDYWARP

# server string is the equivalent of the NT Description field

    server string = Samba Server %v

# 2. Printing Options:

# CHANGES TO ENABLE PRINTING ON ALL CUPS PRINTERS IN THE NETWORK

# if you want to automatically load your printer list rather

# than setting them up individually then you'll need this

    printcap name = cups

    load printers = yes

# It should not be necessary to spell out the print system type unless

# yours is non-standard. Currently supported print systems include:

# bsd, sysv, plp, lprng, aix, hpux, qnx, cups

    printing = cups

# 3. Logging Options:

# this tells Samba to use a separate log file for each machine

# that connects

    log file = /var/log/samba/log.%m

# Put a capping on the size of the log files (in Kb).

    max log size = 50

# Set the log (verbosity) level (0 <= log level <= 10)

;  log level = 3

# 4. Security and Domain Membership Options:

# This option is important for security. It allows you to restrict

# connections to machines which are on your local network. The

# following example restricts access to two C class networks and

# the "loopback" interface. For more examples of the syntax see

# the smb.conf man page. Do not enable this if (tcp/ip) name resolution does

# not work for all the hosts in your network.

;   hosts allow = 192.168.1. 192.168.2. 127.

# Uncomment this if you want a guest account, you must add this to /etc/passwd

# otherwise the user "nobody" is used

    guest account = guest

# Allow unknown users to map to guest:

    map to guest = bad user

```

(and my earlier public directory stuff is tacked on the end).

Will

----------

## John R. Graham

@pmam, if you're truly only wanting to share between Linux machine, Samba is not the optimal solution as it presents a Windows-centric filesystem view. What you want is NFS. See the NFSv4 topic on the Gentoo Wiki.

- John

----------

## pmam

Dear John,

 *Quote:*   

> What you want is NFS. See the NFSv4 topic on the Gentoo Wiki.

 

Yes, that what was missing to me - I thought Samba is the only solution for Linux and for Windows -

but after your post I see that if all machines are Linux, It is preferred to use NFS - You really put your finger on my confusion... and you deserve to a lot of thanks  :Smile: 

Actually this is the situation right now - all machines are Linux - But there are some points to consider: 

First, I have a TV receiver that based on Linux image - I know that it has Samba installed, and there is an option to choose NFS or CIFS sharing - 

OK - I need to choose NFS,  but what happens if a machine has NFS and Samba - which sharing system is active - they can work together?

Second, In the future I will add Windows machine so it means I will need Samba, as well - so I will try to follow Will's tip.

Anyway -  I starting to follow the NFSv4 topic on Gentoo Wiki that you gave me, but get the following mounting problem of 'data' directory:

```
mount --bind /home /export/home && mount --bind /data /export/data

mount: special device /data does not exist
```

Do not know why home mounts ok but data not??

Dear Will,

Thanks for your smb.conf example - I will try to implement it -

I think that in addition to the right smb.conf, I do not know how to define the right permission of the directory and the users, as you noted:

 *Quote:*   

> it just has to have the right permissions

 

Thanks you all

----------

## John R. Graham

 *pmam wrote:*   

> Do not know why home mounts ok but data not??

 Could you post the output of

```
ls -ld /data /export
```

please?

- John

----------

## pmam

Dear John,

Strange... I followed  NFS Wiki and did this command (now it is the second time... so it says 'File exists'):

```
 cd /export && mkdir {home,data}

mkdir: cannot create directory ‘home’: File exists

mkdir: cannot create directory ‘data’: File exists
```

So why your command says 'No such directory'??

```
 ls -ld /data /export

ls: cannot access /data: No such file or directory

drwxr-xr-x 4 root root 4096 Apr 26 21:42 /export
```

And here is the comman ls -l:

```
ls -l

total 8

drwxr-xr-x 2 root root 4096 Apr 26 21:42 data

drwxr-xr-x 6 root root 4096 Apr 24 22:35 home
```

Thanks

----------

## John R. Graham

Because /data doesn't exist. Just create it.

```
mkdir /data
```

Then your bind mount will succeed.

- John

----------

## pmam

Dear John,

OK, I created data directory (I thought this command: cd /export && mkdir {home,data} suppose to do it - Still there is a long way for me...   :Smile:  ),

and bind is OK. Now I need to start NFS - What is the relevant command for Systemd instead of: /etc/init.d/nfs start? 

Did not find this service for Systemd... 

EDIT: BTW - This data directory should be created under /export  - so the result is /export/data    - Is it right?

EDIT: Sorry... I missed the first line of NFS Wiki - 'install net-fs/nfs-utils' - Ignore this post   :Crying or Very sad: 

Thanks

----------

## John R. Graham

Sorry; I don't speak systemd. Regarding your question about /data vs. /export/data, apparently the guide is showing you an example, not saying this is how you have to do it. (Which makes sense, right?) It's good to collect all of the exported directories in /export but they may not actually be there. Say you have a directory you want to export named, oh, let's choose an example at random, say /data. But the standard export location is /export. The solution is to --bind mount /data to /export/data, which is what this command on the Wiki

```
mount --bind /data /export/data 
```

did.  :Wink: 

- John

----------

## pmam

Dear John,

OK, now I see...I am not familiar with this  '--bind mount' so it confused me... 

Please see also my last EDIT on my last post...

I will continue with Sytemd, and also with my other machine with openRC 

Thanks a lot

----------

## pmam

Dear Will,

 *Quote:*   

> There should be a full smb.conf.default in your /etc/samba directory;

 

Yes, I already tried this example without success...

I edited smb.conf with the the code in your last post and the public directory at the end, but still it is not working - 

Maybe something wrong with my user permissions, I do not know... - How can I check it?

Anyway, I'm trying to debug it and here are outputs according the HowTo - Maybe it can helps:

```
/usr/bin/testparm

Load smb config files from /etc/samba/smb.conf

rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)

Processing section "[public]"

Loaded services file OK.

Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

[global]

   server string = Samba Server %v

   map to guest = Bad User

   guest account = guest

   log file = /var/log/samba/log.%m

   max log size = 50

   printcap name = cups

   idmap config * : backend = tdb

[public]

   comment = Public directory

   path = /home/public

   read only = No

   create mask = 0644

   force create mode = 0660

   guest only = Yes

   guest ok = Yes
```

And here it is failed:

```
smbclient -L localhost

Enter root's password: 

Connection to localhost failed (Error NT_STATUS_CONNECTION_REFUSED)
```

Is there another way to debug?

Thanks

----------

## pmam

Dear John,

In NFSv4 Wiki there are two configurations of /etc/fstab:

For server is:

```
/home    /export/home   none    bind  0  0

/data    /export/data   none    bind  0  0
```

And for client is (BTW: there is another option for client):

```
server:/         /mnt     nfs     rw,_netdev,auto   0  0
```

My target is to have some Linux machines connected to the same LAN,

with ability to see and transfer between them any files from /home - This is not so ambitious  - right?

As far as I understand, it means - Each machine can be server or client sometime - So please let me know what configuration I need to choose?

As for your previous post - I understood that Wiki gives a suggestion only, with data directory etc - 

However due to my target as described above - Please let me know your suggestion for /export?

Thanks

----------

## cwr

 *pmam wrote:*   

> Dear Will,
> 
> ....
> 
> And here it is failed:
> ...

 

It looks as if Samba is working, but can't find localhost for some reason;  it might not recognise

the name.  You could try the -I option to smbclient (man smbclient for more information).  If that

works it's a question of finding out how Samba gets the name of the client system.

Will

AFAIK you can crank up the logging level with:

```

# Set the log (verbosity) level (0 <= log level <= 10)

  log level = 3

```

in smb.conf

----------

## szatox

 *Quote:*   

> It looks as if Samba is working, but can't find localhost for some reason;

 

is there a line

127.0.0.1 localhost

in /etc/hosts?

Is local loopback up?

also, in mixed networks (linux, windows and perhaps others) FTP is pretty convenient. To share fiels with it you will likely want to add a user for this purpose (either `anonymous`  if you want it to be completly open or for example `ftp` if it's for friends only) and store files in /home/<your choosen username>. For purely personal use you can login wit  your own login and password, but keep in mind FTP sends everything in plain text. 

For linux-only file shareing NFS seems to  be even easier though

----------

## pmam

Dear Szatox,

I did not get any email alert regarding your reply (instead I got a spam email with this title: 'This Mother's Day, get her the gift of spam, spam, spam, ...'   :Smile:  ) - 

So sorry for my delay response...

It seems that you, incorporate with Cwr and John, put the finger on the right place - There is an important improvement as you can see in the following outputs below.

I checked /etc/hosts and remove # from  127.0.0.1 localhost (it was comment) - I did not know it is needed, and do not remember if it is with # or not in the default example of /etc/hosts, that comes with Gentoo's installation. Now these lines are like this:

```
# IPv4 and IPv6 localhost aliases

127.0.0.1   localhost

::1      localhost
```

Hope now is ok - Please explain what do you mean by:  *Quote:*   

> Is local loopback up? 

  And if you can give a short explanation or a link of this issue!

When I use smb.conf.default from /etc/samba directory, as smb.conf, it does not work, but when I use the below smb.conf, that I copied from my old machine - Suse/openRC (with a little change: security=user instead of share) - It is working as you can see from the outputs afterword. Please let me know why smb.conf.default from /etc/samba directory does not work - It is important to me to figure out this issue!

```

[global]

   workgroup = WORKGROUP

   server string = mg_6300

   security = user

   map to guest = Bad User

      os level = 2

   preferred master = No

   local master = No

   domain master = No

      cups options = raw

   usershare max shares = 100

   restrict anonymous = no

   usershare allow guests = yes

   idmap config * : backend = tdb

   

[printers]

   comment = All Printers

   path = /var/tmp

   create mask = 0600

   printable = Yes

   browseable = No

[print$]

   comment = Printer Drivers

   path = /var/lib/samba/drivers

   write list = @ntadmin, root

   force group = ntadmin

   create mask = 0664

   directory mask = 0775

[home]

   path = /home

   read only = No

   guest ok = Yes

   force user = mg

   force group = users

   comment = all users

   public = yes

[store]

   path = /mnt/store/

   read only = No

   guest ok = Yes

   force user = mg

   force group = users

   public = yes
```

```
/usr/bin/testparm

Load smb config files from /etc/samba/smb.conf

rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)

Processing section "[printers]"

Processing section "[print$]"

Processing section "[home]"

Processing section "[store]"

Loaded services file OK.

Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

[global]

        server string = mg

        map to guest = Bad User

        os level = 2

        local master = No

        domain master = No

        usershare allow guests = Yes

        usershare max shares = 100

        idmap config * : backend = tdb

        cups options = raw

[printers]

        comment = All Printers

        path = /var/tmp

        create mask = 0600

        printable = Yes

        print ok = Yes

        browseable = No

[print$]

        comment = Printer Drivers

        path = /var/lib/samba/drivers

        write list = @ntadmin, root

        force group = ntadmin

        create mask = 0664

        directory mask = 0775

[home]

        comment = all users

        path = /home

        force user = mg

        force group = users

        read only = No

        guest ok = Yes

[store]

        path = /mnt/store/

        force user = mg

        force group = users

        read only = No

        guest ok = Yes
```

```
smbclient -L localhost

Enter root's password: 

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23]

        Sharename       Type      Comment

        ---------       ----      -------

        print$          Disk      Printer Drivers

        home            Disk      all users

        store           Disk      

        IPC$            IPC       IPC Service (mg)

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23]

        Server               Comment

        ---------            -------

        Workgroup            Master

        ---------            -------

        MYGROUP              MG_6300

        WORKGROUP            MG_HOST
```

Now I want to give the machines details: All the above refers to the KDE/openRC machine! I have another machine - Gnome/Systemd that I am trying to install Samba sharing, as well - For this Systemd's machine, the smb.conf of KDE/openRC does not work, so I copied from another old machine Suse/Systemd. I had two types of smb.conf from Suse/Systemd, so you can see the different outputs of smbclient -L localhost:

The first Systemd's smb.conf:

```
[global]

   workgroup = WORKGROUP

   server string = mg_host

   security = user

   map to guest = Bad User

   os level = 2

   preferred master = No

   local master = No

   domain master = No

   cups options = raw

   restrict anonymous = no

   

[printers]

   comment = All Printers

   path = /var/tmp

   create mask = 0600

   printable = Yes

   browseable = No

[print$]

   comment = Printer Drivers

   path = /var/lib/samba/drivers

   write list = @ntadmin, root

   force group = ntadmin

   create mask = 0664

   directory mask = 0775

[home]

   path = /home

   read only = No

   guest ok = Yes

   force user = mg

   force group = users

   comment = all users

   public = yes
```

```
/usr/bin/testparm

Load smb config files from /etc/samba/smb.conf

rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)

Processing section "[printers]"

Processing section "[print$]"

Processing section "[home]"

Loaded services file OK.

Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

[global]

   server string = mg_host

   map to guest = Bad User

   os level = 2

   local master = No

   domain master = No

   idmap config * : backend = tdb

   cups options = raw

[printers]

   comment = All Printers

   path = /var/tmp

   create mask = 0600

   printable = Yes

   print ok = Yes

   browseable = No

[print$]

   comment = Printer Drivers

   path = /var/lib/samba/drivers

   write list = @ntadmin, root

   force group = ntadmin

   create mask = 0664

   directory mask = 0775

[home]

   comment = all users

   path = /home

   force user = mg

   force group = users

   read only = No

   guest ok = Yes

```

```
smbclient -L localhost

Enter root's password: 

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23]

   Sharename       Type      Comment

   ---------       ----      -------

   print$          Disk      Printer Drivers

   home            Disk      all users

   IPC$            IPC       IPC Service (mg_host)

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23]

   Server               Comment

   ---------            -------

   MG_6300              mg_6300

   MG_HOST              mg_host

   Workgroup            Master

   ---------            -------

   WORKGROUP            MG_HOST
```

The second Systemd's smb.conf

```
# smb.conf is the main Samba configuration file. You find a full commented

# version at /usr/share/doc/packages/samba/examples/smb.conf.SUSE if the

# samba-doc package is installed.

[global]

   workgroup = WORKGROUP

              server string = mg_host

   passdb backend = tdbsam

        security = user

        map to guest = Bad User

   printing = cups

   printcap name = cups

   printcap cache time = 750

   cups options = raw

   include = /etc/samba/dhcp.conf

   logon path = \\%L\profiles\.msprofile

   logon home = \\%L\%U\.9xprofile

   logon drive = P:

   usershare allow guests = Yes

[home]

   comment = all users

   path = /home/mg

   read only = No

   guest ok = Yes

   force user = mg

   force group = users

   public = yes

    

[printers]

   comment = All Printers

   path = /var/tmp

   printable = Yes

   create mask = 0600

   browseable = No

[print$]

   comment = Printer Drivers

   path = /var/lib/samba/drivers

   write list = @ntadmin root

   force group = ntadmin

   create mask = 0664

   directory mask = 0775
```

```
/usr/bin/testparm

Load smb config files from /etc/samba/smb.conf

rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)

Can't find include file /etc/samba/dhcp.conf

Processing section "[home]"

Processing section "[printers]"

Processing section "[print$]"

Loaded services file OK.

Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

[global]

   server string = mg_host

   map to guest = Bad User

   printcap name = cups

   logon path = \\%L\profiles\.msprofile

   logon drive = P:

   logon home = \\%L\%U\.9xprofile

   usershare allow guests = Yes

   idmap config * : backend = tdb

   cups options = raw

[home]

   comment = all users

   path = /home/mg

   force user = mg

   force group = users

   read only = No

   guest ok = Yes

[printers]

   comment = All Printers

   path = /var/tmp

   create mask = 0600

   printable = Yes

   print ok = Yes

   browseable = No

[print$]

   comment = Printer Drivers

   path = /var/lib/samba/drivers

   write list = @ntadmin, root

   force group = ntadmin

   create mask = 0664

   directory mask = 0775

```

```
smbclient -L localhost

Enter root's password: 

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23]

   Sharename       Type      Comment

   ---------       ----      -------

   IPC$            IPC       IPC Service (mg_host)

   print$          Disk      Printer Drivers

   home            Disk      all users

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23]

   Server               Comment

   ---------            -------

   MG_HOST              mg_host

   Workgroup            Master

   ---------            -------

   WORKGROUP            

```

Summery of this long story: According the above outputs, It seems that it is working, but I do not know where I can see the other machine in the network - When I enter 'Network' in Dolphin - I do not see it?? In the HowTo Wiki Samba they create directory: /home/samba/public - maybe it is just an example, and I did it - However, I do not know if it is necessary due to my target, as I described in previous post - To see and transfer files from /home directories between each machine.   

 FTP: Yes I know this option (like filezilla) but as you said NFS easier - However, I do not know what are the equivalent Systemd's services needed instead of  '/etc/init.d/nfs start' - You may see my separate Topic regarding this issue. 

Thanks a lot

----------

## pmam

Hi,

Regarding NFS: I had some mistakes in configuration, and found the relevant services for NFS/Systemd - I followed NFS Wiki and now can see and share home directory of my  machine (server) from my SAT TV receiver (client).

However - I do not know why can not see and share directories between two Linux machines - One is Gnome/Systemd and the other is KDE/openRC??

Maybe something missing regarding the configuration of Server and Client - Should I define one machine as a Server and the other as Client, or both of them can be Server and Client? Actually, each machine sometime is Server and sometime is Client - Right?  

As far as I know, when NFS is working I can see and transfer files between Linux machines by enter the 'Network' in Dolphin - Right? Or there is another way to do it?

----------

## pmam

Hi,

I can see Samba's share directories from my Linux's SAT TV receiver, but can not mount them - 

I saw this mount command in HowTo Smaba: 

```
 mount -t cifs [-o username=xxx,password=xxx] //server/share /mnt/point
```

and if we ignore Windows/cifs at the moment, and focus on Linux share with Samba - 

Should I add any mount command to fstab in order to enable mounting from my SAT receiver?

----------

## pmam

Still can not establish Samba sharing...

Here is a command I took from this HowTo: http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/install.html - 

Maybe the failure output can help:

```
smbclient  //mg_host/mg

Enter root's password: 

Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.23]

tree connect failed: NT_STATUS_BAD_NETWORK_NAME
```

Please advise!

----------

## cwr

 *pmam wrote:*   

> Still can not establish Samba sharing...
> 
> Here is a command I took from this HowTo: http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/install.html - 
> 
> Maybe the failure output can help:
> ...

 

The fstab entry I use to export a Samba directory is:

```

# farthing's public Samba directory.

//farthing/public /home/farthing cifs guest,sec=none,uid=1001,gid=100,dir_mode=0775,file_mode=0664,noauto 0 0

```

"mount /home/farthing" then gets me the exported directory, with pretty low security, but it's on a network disconnected

from the Internet.

As far as the network name is concerned, you may need something like the following in /etc/samba/smb.conf:

```

# 1. Server Naming Options:

# workgroup = NT-Domain-Name or Workgroup-Name

    workgroup = WORKGROUP

# netbios name is the name you will see in "Network Neighbourhood",

# but defaults to your hostname

;   netbios name = <name_of_this_server>

   netbios name = SIXPENCE

```

(Note the capitals - the Unix name is "sixpence").

Will

----------

## pmam

I made a nice progress regarding NFS, however, there are some issues:

As John noted earlier in this topic, the example in NFS WIKI tutorial, describes a particular case of export/data and home directories - 

This example quite confused me and as far as I am concerned it is not the right idea,

at least to someone like me who try to establish NFS for the first time - This is only my opinion...

My simple goal is to share home directories, see and transfer files between each Linux machines connected to LAN.

At the moment, I can mount, as a client, to home directory on the server -

Since I need this mounting will be done during booting, I add this line to /etc/fstab:

```
10.0.0.6:/home/mg    /home/mg     nfs   rw,users  0 0
```

When the server is connected, this mounting is ok and the sharing is enabled - However if the server is not connected or turned off, 

the booting of the client stuck during booting, in nfs mounting stage – How to change it so it will skip, in case of server not connected? 

As you see I am using the ip address of the server - when I replaced it with the server's name, it did not mount - Any idea why?

If you have any tips on the above fstab mounting line - regarding security or any other issue.. - You will be welcomed   :Smile: 

----------

## khayyam

 *pmam wrote:*   

> When the server is connected, this mounting is ok and the sharing is enabled - However if the server is not connected or turned off, the booting of the client stuck during booting, in nfs mounting stage – How to change it so it will skip, in case of server not connected?

 

pmam ... you might use autofs, the kernel automounter. This will allow you to set a '--timeout='.

 *pmam wrote:*   

> As you see I am using the ip address of the server - when I replaced it with the server's name, it did not mount - Any idea why?

 

Because the hostname probably isn't resolvable via DNS.

best ... khay

----------

## pmam

Dear Khay,

It really seems that AutoFS is what I need - I am going to figure out how to impliment...

If I use it - Does it mean that I do not need the additional mounting nfs line in fstab?

 *Quote:*   

> Because the hostname probably isn't resolvable via DNS.

 

How can I work it out?

Thanks

----------

## szatox

you can set static IP in /etc/hosts

you can configure your local DNS server (there is even some DNS+DHCP server that gives IP to clients and resolves their names)

you can use avahi and nss-mdns to resolve names and find services

----------

## pmam

Dear Szatox,

 *Quote:*   

> you can set static IP in /etc/hosts 

 

I already configured static IP in /etc/hosts as following:

```
10.0.0.6    mg_e2180.mg_dom_2180 mg_e2180 localhost
```

Mounting work with 10.0.0.6 - with mg_e2180 it does not work???

Thanks

----------

## szatox

 *pmam wrote:*   

> 
> 
> I already configured static IP in /etc/hosts as following:
> 
>  *Quote:*   10.0.0.6    mg_e2180.mg_dom_2180 mg_e2180 localhost 

 

Clients' /etc/hosts

----------

## pmam

Szatox,

I'm not sure I understand... Here is my client's /etc/hosts:

```
10.0.0.7 mg_6300.mg_dom_6300 mg_6300 localhost
```

I am testing the NFS sharing with this client and the server in the previous post.

Thanks

----------

## khayyam

 *pmam wrote:*   

> I'm not sure I understand... Here is my client's /etc/hosts:

 

pmam ... ok, so add the NFS server

```
10.0.0.7 mg_6300.mg_dom_6300 mg_6300 localhost

10.0.0.8 nfs.lan nfs
```

... test

```
# ping -c 1 nfs.lan

# ping -c 1 nfs
```

best ... khay

----------

## pmam

Dear Khay,

You meant 10.0.0.6 (not 8 )  - I added it and the test is ok.

Please explain what this addition is for?

Thanks

----------

## khayyam

 *pmam wrote:*   

> You meant 10.0.0.6 (not 8 )  - I added it and the test is ok.

 

pmam ... oh, thats psychic powaz for you ... of course I could guess again if you like, or choose an adjacent number to your client's IP ... I'm sure to get it :)

 *pmam wrote:*   

> Please explain what this addition is for?

 

Take a quick look at /etc/nsswitch.conf ... you'll see "hosts: files dns", this states that in resolving hostnames it looks to "files" then "dns", /etc/hosts is such a file. So, with the above you state that 10.0.0.{N} is the host nfs/nfs.lan. Once this is added, like dns (which translates hostnames to IP addresses) the host can be addressed as "nfs" or "nfs.lan".

best ... khay

----------

## szatox

First you show line from fstab that shows NFS server with IP 10.0.0.6.

then you show line from hosts that conatins IP10.0.0.6 and name localhost

Hence my conclusion: it's config from server's /etc/hosts.

Now, localhost should point to 127.0.0.1, that's first thing. Then, "localhost" is computer's version of "me". You never refer to remote machine as "localhost" as I don't refer to YOU as "me". Whan I say "me" it means zzatox, not pman, and when you call "localhost" you mean the pc running your session.

Anyway, we need mroe info if we are t obe of any help right now.

So, now, if you still have problems with that NFS setup we need:

IP for NFS server

IP of client machine/ client network

/etc/exports from NFS server

/etc/hosts from client

some info on what you consider your problem

then maybe we will be able to sort it out

----------

## khayyam

 *szatox wrote:*   

> then you show line from hosts that conatins IP10.0.0.6 and name localhost

 

szatox ... completely missed that in the above, yes, no routable address is required, it should be the loopback. Not sure what the purpose of ".mg_dom_6300" as localdomain is, particularly as it seems to be similarly named to the hostname (thats probably also an error).

/etc/hosts

```
127.0.0.1 mg_6300.lan mg_6300 localhost

10.0.0.6 nfs.lan nfs
```

best ... khay

----------

## pmam

OK my Dears...

Thought I followed the HandBook but it is not exactly... 

Yes - I made a mistake regarding the IP of localhost - Thought that if using static IP the local host address should be the static IP - 

I mean: The server static IP=10.0.0.6 - So why do you call it 'remote' - for me it is local, the server - . 

However according your remarks, I understand it is a mistake and I should change it 127.0.0.1 (and make some fine tunning to my logical network thinking...   :Smile:  )

BTW: Now I see that static IP is defined only with /etc/conf.d/net. 

But  ".mg_dom_6300" suppose to be correct - I followed this line in the Handbook: dns_domain_lo="homenetwork"

and defined my Client's domain as: ".mg_dom_6300" (and my HostName as: "mg_6300") - What's wrong with that?

EDIT: Please let me know if to stay with mg_dom_6300 or to change to lan?

Here is the data been requested:

IP for NFS server=10.0.0.6

IP of client machine=10.0.0.7  / client network=10.0.0.0/24 - Is it right for configuring the whole network as a client?

/etc/exports from NFS server - /home/mg                10.0.0.0/24(fsid=0,rw,sync,no_root_squash,insecure,no_subtree_check) 

/etc/hosts from client - after the last change -As you can see "127.0.0.1" showed up twice - At the beginning:

127.0.0.1	localhost

::1		localhost -

and at the end of the file - Is it right? It is also in /etc/hosts of the server.

```
# /etc/hosts: Local Host Database

#

# This file describes a number of aliases-to-address mappings for the for 

# local hosts that share this file.

#

# In the presence of the domain name service or NIS, this file may not be 

# consulted at all; see /etc/host.conf for the resolution order.

#

# IPv4 and IPv6 localhost aliases

127.0.0.1   localhost

::1      localhost

#

# Imaginary network.

#10.0.0.2               myname

#10.0.0.3               myfriend

#

# According to RFC 1918, you can use the following IP networks for private 

# nets which will never be connected to the Internet:

#

#       10.0.0.0        -   10.255.255.255

#       172.16.0.0      -   172.31.255.255

#       192.168.0.0     -   192.168.255.255

#

# In case you want to be able to connect directly to the Internet (i.e. not 

# behind a NAT, ADSL router, etc...), you need real official assigned 

# numbers.  Do not try to invent your own network numbers but instead get one 

# from your network provider (if any) or from your regional registry (ARIN, 

# APNIC, LACNIC, RIPE NCC, or AfriNIC.)

#

127.0.0.1 mg_6300.mg_dom_6300 mg_6300 localhost

10.0.0.6 nfs.lan nfs

```

/etc/hosts from server - 

```
# /etc/hosts: Local Host Database

#

# This file describes a number of aliases-to-address mappings for the for 

# local hosts that share this file.

#

# In the presence of the domain name service or NIS, this file may not be 

# consulted at all; see /etc/host.conf for the resolution order.

#

# IPv4 and IPv6 localhost aliases

127.0.0.1   localhost

::1      localhost

#

# Imaginary network.

#10.0.0.2               myname

#10.0.0.3               myfriend

#

# According to RFC 1918, you can use the following IP networks for private 

# nets which will never be connected to the Internet:

#

#       10.0.0.0        -   10.255.255.255

#       172.16.0.0      -   172.31.255.255

#       192.168.0.0     -   192.168.255.255

#

# In case you want to be able to connect directly to the Internet (i.e. not 

# behind a NAT, ADSL router, etc...), you need real official assigned 

# numbers.  Do not try to invent your own network numbers but instead get one 

# from your network provider (if any) or from your regional registry (ARIN, 

# APNIC, LACNIC, RIPE NCC, or AfriNIC.)

#

127.0.0.1    mg_e2180.mg_dom_2180 mg_e2180 localhost
```

Now - As I wrote earlier - My simple goal is to share home directories, see and transfer files between each Linux machines connected to LAN. In order to establish this bi-directional goal - I mean - I will be able to share home directories between all machines of the local network - I need to configure each machine as server and client, as well.  First I need to establish one server and one client and later on I will continue. As I wrote, At the moment, I can mount, as a client, to home directory on the server -

Since I need this mounting will be done during booting, I add this line to /etc/fstab:

```
10.0.0.6:/home/mg    /home/mg     nfs   rw,users  0 0
```

The problem - When the server is connected, this mounting is ok and the sharing is enabled - However, if the server is not connected or turned off,

the client stuck during booting, in nfs mounting stage – How to change it so it will skip, in case of server not connected?

Khay suggested this:  *Quote:*   

> pmam ... you might use autofs, the kernel automounter. This will allow you to set a '--timeout='. 

  - 

I still did not figure out how exactly configure autofs - However, is it the only way or I can set any parameter with fstab, as well? 

EDIT: I did not check if now I can mount to server with server name instead of IP - I will do it after get your reply...

Thanks

----------

## szatox

 *Quote:*   

> The server static IP=10.0.0.6 - So why do you call it 'remote' - for me it is local, the server - .

 

Local domain is not a local machine. When I'm looking at the Moon, It's local to Solar System (our local domia) but it's still a remote globe. There are only a few ppl who had ever had a chance to call Moon localglobe. So, your server is a remote machine as long as you are using any kind of networking to access it. If you have 2 virtual machines running on a single host and they talk over ethernet, they are remote machines for each other even though they are phisicaly in the same box. When I'm sending files from handy to pc, I have a direct controll over one of them and I refer to it as localhost, and the other is a remote machine even though is only like a feet away from my localhost.

In /etc/hosts you can only define names for static IP. You do this manualy and it doesn't adapt if anything changes - you have to fix it to keep it in sync. It's Static doesn't mean local, those 2 are independent. Almost every PC assiciated to DNS record has static IP and you don't put it in your hosts (but you can do that if you want either faster lookups or broken IP for a particular human-readable address)

Back to making NFS work:

right now you should be able to refer to nfs using it's name which is one of: "nfs", "nfs.lan". You can replace 10.0.0.6:/home/mg with nfs:/home/mg in mount command or in fstab. Doesn't mean you have to, but names are usualy more descriptive than IPs.

/etc/hosts from server is not important as clients never read it anyway.

The way it is right now, /etc/exports allows any PC with any IP from pool 10.0.0.XXX full, unrestricted access to server's /home/mg. As long as you're aware of it and it's intended, it's fine.

I'm not familiar with mounting NFS automaticaly when you want to access it, I tend to assume server is not to be shut down. Perhaps khayyam will be of more help here

/ets/hosts is usualy read from top to the first line that resolves name you requested. Repeating a single name in multiple lines is redundant and potentialy confusing for you, but not dangerous for system, so better clean it up for sake of your own convenience if you ever have to look into that file again. If you choose to leave it it will not affect your system (but over time - and with some updates - it might turn highly magic, glow at night, kick your balls or eat your cat)

Btw:  *Quote:*   

> client network=10.0.0.0/24 - Is it right for configuring the whole network as a client? 

 

NFS is an abbreviation of No File Security, so yes, it's perfectly fine

----------

## khayyam

 *pmam wrote:*   

> Yes - I made a mistake regarding the IP of localhost - Thought that if using static IP the local host address should be the static IP - I mean: The server static IP=10.0.0.6 - So why do you call it 'remote' - for me it is local, the server

 

pmam ... as a sentance this is really hard to understand, you're switching contexts willy-nilly without really understanding what the terms mean. Szatox tried to provide an analogy of "me, you, I, etc" to outline how this terminology works, but it doesn't seem to have hit its mark. Anyhow, I'll try to make the terms absolutely explicit and so provide you with some method of understanding what *we* mean.

localhost <= every host is "localhost" to itself, it means "this computer". This is also called the "loopback" as its a TCP/IP network that operates *entirely* within the confines of each individual host. It consists of the network 127.0.0.0/8 (ipv4) but these are not routable addresses, anything sent to that address will "loopback". When querying "localhost", it should return the loopback address, 127.0.0.1

localdomain <= this describes the "local network", this will consist of an IP address space reserved for "local area networks" (LAN), 10.0.0.0/8 (which you're using) is such a reserved address space. "localdomain" could be ".lan", ".local", ".fluffy", or whatever, as this is just a name for the domain. Some local networks provide DNS entries for these addresses, but many don't. As I showed above "files" is before "dns" so /etc/hosts can be used to provide the mapping between a name and an IP address.

hostname.localdomain <= this describes the "host" and "domain" on a "local area network". They describe only "local area" addresses but are much the same as addresses on the internet, though ".lan", ".local", or what-have-you, function more like "tld" ("Top Limited Domain" ... ie, .com, .org, .net, etc).  

So for "this computer" the following are synonmous: localhost, hostname, 127.0.0.1, hostname.lan, hostname.local, etc ... dependent on whats defined in /etc/hosts. For "this computer", the following relate to other computers on the lan: host1, host2, host1.lan, host2.lan, 10.0.0.6, 10.0.0.8 ... again,  dependent on what's defined in /etc/hosts (or in DNS if such entries exist).

When you speak about "server", this too is "localhost", at least as far as loopback is concerned, but from the clients perspective its 10.0.0.6 or host1.localdomain ...  again,  dependent on what's defined in /etc/hosts on the client machine (or in DNS if such entries exist).

 *pmam wrote:*   

> But ".mg_dom_6300" suppose to be correct - I followed this line in the Handbook: dns_domain_lo="homenetwork" and defined my Client's domain as: ".mg_dom_6300" (and my HostName as: "mg_6300") - What's wrong with that? EDIT: Please let me know if to stay with mg_dom_6300 or to change to lan?

 

No, ".mg_dom_6300" is incorrect, because it is not ment to define the "hostname" but the "localdomain", also dns_domain_lo="homenetwork" is used only if DNS is providing this mapping between IP's and domain names on the LAN.

 *pmam wrote:*   

> 
> 
> ```
> 127.0.0.1 mg_6300.mg_dom_6300 mg_6300 localhost
> 
> ...

 

Besides the fact that you have two entries where there need only be one, and you define "localhost" (on the client) to have the lan IP and not the loopback address, here we can see the "localdomain" is different for both the client and the server.

client:

```
127.0.0.1 mg_6300.lan mg_6300 localhost

10.0.0.6 mg_e2180.lan mg_e2180
```

server:

```
127.0.0.1 mg_e2180.lan mg_e2180 localhost

10.0.0.7 mg_6300.lan mg_6300
```

... test

```
# hostname -f

mg_6300.lan

# ping -c 1 mg_e2180.lan

# ping -c 1 mg_e2180

# ping -c 1 10.0.0.6
```

best ... khay

----------

## pmam

Dear Khay,

Your detailed explanation is in the right place and really needed for me (and hope for others...) - each line you write worth me a few hours of wondering in the @world'  :Smile: 

Gentoo's HandBook probably assumes that user already well familiar with networking - Actually, it is not common that someone like me wakes up one morning and say to himself: Ah, let's install Gentoo...   :Smile:  However, I think it is a good idea - During Gentoo's installation, thanks to yours helpful tips, I learnt a lot of Linux and networking - It is not easy, but worth.

[quote]localhost <= every host is "localhost" to itself, it means "this computer".

OK, now I see - according your explanation I may say that local host address (127.0.0.1) is the address of the Ethernet adaptor, and using for loop-back and self testing of the adaptor itself - It makes separation between the adaptor address and the host name's IP address in the local network (10.0.0.0/24) - Hope it is quite right...

I understand all of your explanation except of the domain's name: If I can choose any domain name (except identical to host name) why can not use: "mg_dom_6300"? 

EDIT: I think finally understand: It is a mistake to call a domain with a name that refer to one of the hosts - Domain name is common to all hosts, but not associated to one of them - Right?  

Anyway, no problem to change it to "lan" - But what to do with this line: dns_domain_lo="homenetwork" - delete it?

Also, if we already talking about it...please inform me with a link regarding HowTo DNS - I think it is a good idea to be familiar with...

I am going to make your suggested changes and let you now the output...

Thanks a lot!

----------

## pmam

Dear Szatox,

Sorry, I missed your last post... All my previous compliments are for you , as well...

 *Quote:*   

> it might turn highly magic, glow at night, kick your balls or eat your cat

 

Since I do not have a cat.. I am worry about the others   :Smile: 

 *Quote:*   

> The way it is right now, /etc/exports allows any PC with any IP from pool 10.0.0.XXX full, unrestricted access to server's /home/mg. As long as you're aware of it and it's intended, it's fine.

 

Yes - It's my intention.

Dear Khay,

OK - I have done all changes, according your tips, and the testing is ok.

Now I need to solve the mounting problem in the booting stage with Autofs - need to find out how exactly use it and write down the right paramters.

Also, need to add configurations, so each machine will be server & client as well.

Please let me know what to do with this line: dns_domain_lo="homenetwork" - delete it? 

Thanks you all

----------

## khayyam

 *pmam wrote:*   

>  *khayyam wrote:*   localhost <= every host is "localhost" to itself, it means "this computer". 
> 
> OK, now I see - according your explanation I may say that local host address (127.0.0.1) is the address of the Ethernet adaptor, and using for loop-back and self testing of the adaptor itself - It makes separation between the adaptor address and the host name's IP address in the local network (10.0.0.0/24) - Hope it is quite right...

 

pmam ... no, the loopback has no relation to the network adaptor, even if a machine has no physical network device "lo" (loopback) would still be available/needed.

```
# ip addr show dev lo

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo

       valid_lft forever preferred_lft forever
```

... note the "link" has no physical hardware address (MAC address) ... its "00:00:00:00:00:00".

```
# netstat -apn | grep 127.0.0 |tr -s ' '

tcp 0 0 127.0.0.2:53 0.0.0.0:* LISTEN 2166/dnscrypt-proxy

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1215/master

udp 0 0 127.0.0.1:53 0.0.0.0:* 16278/unbound

udp 0 0 127.0.0.2:53 0.0.0.0:* 2166/dnscrypt-proxy
```

... and like a physical device (ie, eth0, wlan0, br0, etc) it provides TCP/IP networking. 

 *pmam wrote:*   

> I understand all of your explanation except of the domain's name: If I can choose any domain name (except identical to host name) why can not use: "mg_dom_6300"?

 

You could use any name you like, you can use a different "localdomain" for each host (as you did), but this somewhat defeats the point. We provide the same "localdomain" for each host as they exist on the same LAN, its a question of consistancy. Just like "forums" is part of the "gentoo.org" domain, hostname.localdomain is part of ".localdomain" (be that ".lan", ".local", or whatever it might be).

 *pmam wrote:*   

> Anyway, no problem to change it to "lan" - But what to do with this line: dns_domain_lo="homenetwork" - delete it?

 

Well, "homenetwork" is only correct if this is your "localdomain", you probably want dns_domain_lo="lan" but I've never felt the need to asign dns_domain_lo.

 *pmam wrote:*   

> Also, if we already talking about it...please inform me with a link regarding HowTo DNS - I think it is a good idea to be familiar with...

 

Not sure what you're requesting, its a big subject ...

best ... khay

----------

## pmam

Dear Khay,

As you can see in my previous post, I figured out myself, a few minutes before getting your additional explanation regarding domain name:  :Smile: 

 *Quote:*   

> EDIT: I think finally understand: It is a mistake to call a domain with a name that refer to one of the hosts - Domain name is common to all hosts, but not associated to one of them - Right? 

 

Yes - You are right - It was not a good name for domain.

OK - After your last examples,  regarding loopback, it is much clear!

Now everything regarding my goal of NFS is OK, except the auto mounting during the booting:

I followed the HowTo of Autofs but it is not perform the mounting... On the other hand I found in google this link:

https://www.digitalocean.com/community/articles/how-to-set-up-an-nfs-mount-on-ubuntu-12-04

And as you can find there this next quote that shows a timeout parameter (as far as I can see) for fstab:

```
12.34.56.789:/home  /mnt/nfs/home   nfs      auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

12.34.56.789:/var/nfs  /mnt/nfs/var/nfs   nfs     auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
```

I tried to configure this way however still not work - If it is right then i can use it instead of Autofs...

Do you familiar with fstab timeout?

Thanks

----------

## pmam

OK my dears...

I decided to give up with the booting mounting of NFS - Maybe later on I will find out what is wrong in my configuration.

At the moment I can manually mount to other machine and see and transfer files whenever I would like to - it is good enough. 

I could see between the lines that you quite do not like the idea of permanent mounting NFS -

Maybe due to security issues and /or others, so maybe I need to listen to you...  :Smile: 

Thanks

----------

## szatox

My NFS server simply tends to be online every single time I need it so I never bothered with dynamic mount there. It is insecure, particularly from server's point of view, as there is really no authentication. (You odn't log into NFS, you just connect from some IP and you present your remote UID, which is interpreted by server as local user with the same UID - extremaly stupit design.) It's still pretty convenient though, so don't hesitate in private. Even though in publick it turns a trouble-waiting-to-happen - and if you ever tried I bet it wouldn't have to wait for long

----------

