ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
I want to open a remote file.can any one tell me how to open a remote file and use its contents ,as we can read a local file,is it possible to read a remote linux system file from my local linux system.
example:
suppose I want to read a file in
IP :"10.0.3.2"
Path :/root/text1.txt"
can i use the fopen("10.0.3.2/root/text1.txt","rb"),
for this i tried it is not working ,Is there any solution for this,
The idea of local and remote is irrelevant when you think of mounted file systems.
All mounted file systems are "locally" mounted on the root folder /.
That said, yes, it exists many possibilities to access a remote file.
But first, the remote machine must expose the file (generally its folder) for others machines (such as your local machine) to access it.
So the remote machine can run softwares such as NFS, Samba, FTP, SSH that allow folders to be accessed from other machines.
According to what the remote machine server exposes, than you will use an appropriate client tool to connect to the server, and get access to the file (generally by mounting the remote folder).
I will try to outline what is required if you use NFS.
On the server:
1. Install NFS package (it is generally installed by default on Linux).
2. Configure NFS to export the folder containg the file you are interested with with the correct required rights and permissions for access.
3. Allow the traffic through the firewall, if required.
4. Adjust the SELinux, if required.
5. Run NFS server (and surely set it to start at launch).
On the client:
1. Install NFS package (it is generally installed by default on Linux).
2. Create the folder to be mounted to, if required.
3. Mount the remote folder, with command similar to mount -t nfs 10.0.3.2/path/to/exported/folder/ /path/to/folder/to/mount/to/.
4. If required, you can set the folder to be mounted at launch with appropriate entry in /etc/fstab.
Thanks for the reply.Can you tell this NFS is the only way to share a folder or file in the network to public or is there any other method available for this.
In NFS , can you tell me how to share it public means any host or client can able to use this folder or file.
Thanks
Last edited by pradiptart; 06-27-2012 at 01:46 AM.
No, NFS is not the way to share a folder. I have enumerated several others means in my previous post.
Yes, I can tell you how to share a folder for the public with NFS.
But I think it will not be really helpful to you, you need to learn it a little.
Google for "NFS tutorial" and you should find useful links returned back.
Read them, test what they suggest.
And then, and only then, if you still have problems, share with us what you had done, and we will try to assist from there.
hi,
I tried the NFS configuration.
In server[10.0.0.6]
---------------
1.started the nfs service
2.i put the line /root/wshare/ 10.0.0.3(rw) in the /etc/exports file
3.restarted the nfs service
In Client[10.0.0.3]
-----------
1.started the nfs service and checked status
2.use icpinfo -p to see all the daemons are running or not
3.created a directory as /mnt/home/
3.used mount -t nfs 10.0.0.6:/root/wshare/ /mnt/home/ command to mount from client
but now I got the error as follow mount: mount to NFS server '10.0.0.6' failed ,system error:no route to host
so ,kindly tell about this error and how to overcome this error..
It seems clear to me from the output error thrown back. ...system error:no route to host
Can you access (ping for example) 10.0.0.6 from 10.0.0.3?
Are the required port for NFS (tcp/2049 and udp/2049) opened in 10.0.0.6 firewall?
following is the content of vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
Is this ok or I need to add the port you specified,can u tell me how to do that ,I google and found as follow
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport port number -j ACCEPT,here in place of port number we have to specify the port we want is this correct and if so then how to do for udp
I added as follows -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp –dport 2049 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p udp–dport 2049 -j ACCEPT
is this correct or not ...
Kindly tell something.
Thanks
Last edited by pradiptart; 06-27-2012 at 04:57 AM.
I picked a typo in the iptables rule related to NFS UDP, It should be as below. -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp –dport 2049 -j ACCEPT
From the form of the iptables command I seems as if you are using RHEL 5.x (or something similar).
It use NFS version 3 that relies on portmap (tcp/111 and udp/111) so that also required to be allowed in your firewall.
Because of portmap it also, use random ports for other required NFS daemons.
It is possible to have those random ports "fixed" and allowed through the firewall. But my suggestion will be (hoping you can afford it without a major risk) that you frist disable the firewall, test to ensure it works, then renable the firewall, and fine tune it.
Or maybe, if the server runs SSH, you should go the way suggested by vikas027.
On the SSH way, you can achieve something mountable with the package fuse-sshfs.
I am having two doubt..
1)
steps what i did
1.as you said i disabled the firewall in server
2.restarted the nfs in both server and client
3.use the command to mount
then it is worked
and then i use umount /mnt/home/,then i tried again doing the same but it showing the permissinon denied as follow
mount.nfs: Permission denied
but then I created another folder home1 then tried the same mount command it is working !!!!!!!!!!!!!!
so my doubt is what happen to the previous folder .
when i am checking the permission with ls -l then it showing as follows
drwxr-x--- 36 root root 4096 Jun 27 18:46 home
drwxr-xr-x 3 root root 4096 May 22 21:43 home1
my second doubt is
2)
how to use this with the firewall and how to use the fixed port as you mentioned.................
Thanks
Last edited by pradiptart; 06-27-2012 at 08:25 AM.
I am glad you got something working.
So now we know it is just few things to fine tune in the firewall.
NFS (versions before 4) relies on some additional daemons, so have a look at file /etc/sysconfig/nfs.
Read the comments in there and uncomment the line with the ports (you can change the ports values to ones of your choice but ensure that they are free, the most important is MOUNTD_PORT), and then allow the ports through the firewall. Restart the firewall, restart NFS service, and then test at the client side.
I do not know what problem you faced while you tried to unmount, but let's focus first on the firewall.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.