如何在Ubuntu中挂载网络驱动器
Here’s a concise guide to mounting network drives in Ubuntu, covering both SMB/CIFS (Windows) and NFS (Linux/Unix) protocols:
1. Mounting SMB/CIFS (Windows) Shares
Install Required Tools
First, install the cifs-utils package (needed for SMB/CIFS support):
sudo apt update &
&
sudo apt install cifs-utils
Create a Mount Point
Choose a local directory to access the shared files (e.g., /mnt/windows_share):
sudo mkdir -p /mnt/windows_share
Temporary Mount (Restart Required)
Use the mount command with your Windows share details. Replace placeholders (<
Windows_IP>
, <
share_name>
, <
username>
, <
password>
) with actual values:
sudo mount -t cifs //<
Windows_IP>
/<
share_name>
/mnt/windows_share \
-o username=<
username>
,password=<
password>
,uid=$UID
- Key Options:
uid=$UID: Grants your Ubuntu user access to the mounted files.vers=2.0: Use for older Windows systems (e.g., Win7); omit for newer versions (Win10/11).
Permanent Mount (Auto-Start)
For automatic mounting at boot, edit the /etc/fstab file:
sudo nano /etc/fstab
Add this line (replace values as above and create a credentials file for security):
//<
Windows_IP>
/<
share_name>
/mnt/windows_share cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,vers=2.0 0 0
- Credentials File: Store your username/password securely (600 permissions):
echo "username=< username> " | sudo tee /etc/samba/credentials > /dev/null echo "password=< password> " | sudo tee -a /etc/samba/credentials > /dev/null sudo chmod 600 /etc/samba/credentials
Apply changes:
sudo mount -a
Verify Mount
Check if the share is accessible:
df -h | grep windows_share
ls /mnt/windows_share
2. Mounting NFS Shares
Install Required Tools
Ensure the nfs-common package is installed (for NFS clients):
sudo apt update &
&
sudo apt install nfs-common
Create a Mount Point
Select a local directory (e.g., /mnt/nfs_share):
sudo mkdir -p /mnt/nfs_share
Temporary Mount (Restart Required)
Use the mount command with your NFS server details. Replace <
NFS_Server_IP>
and <
shared_path>
:
sudo mount -t nfs <
NFS_Server_IP>
:<
shared_path>
/mnt/nfs_share
- Example: Mount
/exports/datafrom192.168.1.100to/mnt/nfs_share:sudo mount -t nfs 192.168.1.100:/exports/data /mnt/nfs_share
Permanent Mount (Auto-Start)
Edit /etc/fstab to add the NFS share:
sudo nano /etc/fstab
Add this line (replace values as above):
<
NFS_Server_IP>
:<
shared_path>
/mnt/nfs_share nfs defaults 0 0
Apply changes:
sudo mount -a
Verify Mount
Check the mount status and access files:
df -h | grep nfs_share
ls /mnt/nfs_share
Troubleshooting Tips
- Permissions: Ensure the Windows share has read/write permissions for your user. For NFS, verify the server allows your Ubuntu IP.
- Firewall: Allow SMB (ports 445/tcp, 137-139/udp) or NFS (port 2049/tcp) traffic in your firewall.
- Network: Confirm the server is reachable (
ping < IP>). - Logs: Check system logs (
dmesg | tailor/var/log/syslog) for mount errors.
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 如何在Ubuntu中挂载网络驱动器
本文地址: https://pptw.com/jishu/747634.html
