Create network shares

From gr0x0rd
Jump to navigation Jump to search

Configuring your System - Create network shares

Linux Shares

You may have the need to share files and folders on your Gentoo PC with other files on the network. There are two primary ways of doing this, and these methods are using nfs or samba. Samba is geared towards compatibility with Microsoft Windows, whereas nfs is an abbreviation for network file system, and has its roots in the early days of unix.

On order to create a samba or nfs share, you'll need to make sure you have the proper kernel config. The necessary options are shown in the kernel section.

To create an nfs share, you'll first need to emerge the net-fs/nfs-utils package. This is ideal if you are wanting to share files between multiple linux systems. If there is a windows machine in the mix (including virtual machines) you will probably want to use samba.

$ sudo emerge -av nfs-utils

Once the package has been emerged, we can configure the exports, which are the folders we're sharing and the access level and permissions for clients. In the example below, we will share the folder /home/gr0x0rd to some other machines on the network.

$ sudo nano -w /etc/exports

/etc/exports

# /etc/exports: NFS file systems being exported. See exports(5).
/home/gr0x0rd    192.168.0.100(rw,no_subtree_check)
/home/gr0x0rd    10.10.3.119(rw,no_subtree_check)

Once you have saved your exports file, we can start the nfs server.

$ sudo /etc/init.d/nfs start

To start the nfs server with the system,

$ sudo rc-update add nfs default

You should now be able to mount the share from another machine on your network.

Windows Shares

In order to share files with machines on your network running Microsoft Windows, you'll need to install and configure a Samba server. Before performing the emerge, be sure to check that you have the desired USE flags set.

$ sudo emerge -av samba

Once the emerge has completed, you will need to set up your shares. This is done by editing the file /etc/samba/smb.conf.

$ sudo nano -w /etc/samba/smb.conf

/etc/samba/smb.conf

The following example is comprised of three sections: global, private and public. The global section below contains the master settings for the share. Be sure to replace CYBERTRON with the name of your domain and TELETRAN4 with the name of your server. The "hosts allow" section allows connections from localhost and any IP address on the 192.168.0.x network, while the "hosts deny" section prevents connection from any IP extraneous to the local network. The share uses "user" based security, which will be explained in the next section. The commented lines at the end are for scanning the share using clamav, but this goes beyond the scope of this guide.

#######################
#
# gr0x0rd's smb.conf
#
#######################

[global]
workgroup = CYBERTRON
netbios name = TELETRAN4
server string = Samba Server %v
printcap name = cups
printing = cups
load printers = no
log file = /var/log/samba/log.%m
max log size = 50
socket options = TCP_NODELAY SO_RCVBUF=65536 SO_SNDBUF=65536
interfaces = lo eth0
bind interfaces only = yes
hosts allow = 127.0.0.1 192.168.0.
hosts deny = 0.0.0.0/0
security = user
guest ok = yes

	log level = 1                       
	read raw = yes                     
	write raw = yes                     
	oplocks = yes                       
	max xmit = 65535                    
	dead time = 15                     
	getwd cache = yes

#vfs object = vscan-clamav
#vscan-clamav: config-file = /etc/samba/vscan-clamav.conf

The private section below is a share of the files directory located in the home directory for the user gr0x0rd', the only user allowed to access this resource.

[private]
comment = Cybertron Repository
valid users = gr0x0rd
browseable = yes
writeable = yes
public = no
create mode = 0766
guest ok = no
path = /home/gr0x0rd/files

The public section below is essentially the same as above, except any user with a samba account can access it, no write permissions exist, and the folder gr0x-Z within the directory structure is not accessible.

[public]
comment = public
browseable = yes
writeable = no
public = no
create mode = 0766
guest ok = no
path = /home/gr0x0rd/files
veto files = /home/gr0x0rd/files/gr0x-Z/

Once you have set up the shares you desire, save your file. We now need to set up the samba users, which are independent from the local user accounts set up on the server. Simply replace username with your desired user. Repeat as needed for the different users you want to add.

$ sudo smbpasswd -a username

In order to browse for the share using Windows systems, you'll need to configure the networking system on the server to accommodate Windows networking.

$ sudo nano -w /etc/nsswitch.conf

Ensure the file has the following directives:

hosts: files dns wins
networks: files dns wins

Next, we'll add the server to startup and start the service.

$ sudo rc-update add samba default
$ sudo /etc/init.d/samba start

As with nfs, you should now be able to mount the share from another machine on your network.