LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2012, 02:18 AM   #1
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Rep: Reputation: 12
How to open a remote file in linux.


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,

Kindly tell me about this ..

Thanks
 
Old 06-26-2012, 02:58 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Hi,

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.

I hope it will point to right directions.
 
2 members found this post helpful.
Old 06-26-2012, 07:43 AM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Lightbulb

Code:
ssh root@10.0.3.2 "cat /root/text1.txt"
OR
Code:
ssh -t root@10.0.3.2 "vi /root/text1.txt"
This could be the simplest option.

Last edited by vikas027; 06-26-2012 at 09:28 AM.
 
1 members found this post helpful.
Old 06-27-2012, 12:18 AM   #4
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Original Poster
Rep: Reputation: 12
Hi,

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.
 
Old 06-27-2012, 02:19 AM   #5
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Hi,

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.
 
1 members found this post helpful.
Old 06-27-2012, 04:17 AM   #6
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Original Poster
Rep: Reputation: 12
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..
 
Old 06-27-2012, 04:42 AM   #7
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Hi,

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?

Please, study a little from results out of Google search for "NFS tutorial"
 
Old 06-27-2012, 04:52 AM   #8
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Original Poster
Rep: Reputation: 12
Hi,

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.
 
Old 06-27-2012, 05:23 AM   #9
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Hi,

Have you tested what you suggested?

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.
 
1 members found this post helpful.
Old 06-27-2012, 08:01 AM   #10
pradiptart
Member
 
Registered: Sep 2007
Posts: 102

Original Poster
Rep: Reputation: 12
Hi,

I disabled the firewall iptables by command

It is working WOW.................

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.
 
Old 06-28-2012, 02:41 AM   #11
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
Hi,

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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: 4 Linux programs to open a Remote Desktop on Windows LXer Syndicated Linux News 0 02-09-2012 03:20 AM
open remote file bliu Linux - Newbie 1 01-27-2009 08:58 PM
Open a CMD on a remote Windows box from Linux? humbletech99 Linux - General 5 12-05-2007 08:16 AM
Can not open Remote Graphical Display on Linux WS ppanyam Linux - Software 3 01-06-2006 02:16 PM
Open Linux Terminal from remote Windows machine m1ke Linux - Networking 5 11-12-2001 01:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration