# Setting up NFS and SMB in a AWS Environment Owner: 侯智晟 meowheckerouo@gmail.com [TOC]  # Creating a Virtual Private Network(VPC) in AWS  # Creating a Public Subnet:   ## Auto-Assign Public IP   ## Creating a Private Subnet  ## Internet Gateway Configuration and Attachment  ### Attach Internet Gateway to VPC   ## Routing Table ### Public Subnet Routing Table Configuration    ### Associate Subnets  ## Routing table associate with subnet  ## Creating an EC2 instance in a public subnet ### AWS Linux(public SubNET)  ### AMS Linux (private subNET) ### Network Configuration  ## To upload an access key for logging into a private host Upload Access key ``` scp -i meowheckerKey2.pem meowheckerKey2.pem ec2-user@54.174.144.134:/tmp ``` Prepare ``` [ec2-user@ip-10-10-0-30 ~]$ cd /tmp [ec2-user@ip-10-10-0-30 tmp]$ sudo -s [root@ip-10-10-0-30 tmp]# mv meowheckerKey2.pem /home/ec2-user/ [root@ip-10-10-0-30 ~]# cd /home/ec2-user/ [root@ip-10-10-0-30 ec2-user]# chmod 400 meowheckerKey2.pem ``` ### Login to the Private Host ``` [root@ip-10-10-0-30 ec2-user]# ssh -i meowheckerKey2.pem ec2-user@10.10.1.19 ```  ## Private host connect to the internet. ## Create NAT GAT way on public subnet Allocate an Elastic IP Address FOR NAT  ## Configure Route Table for Private Subnet   ## Association a private route table with a private subnet   NAT allows instances in a private subnet to access the internet by using their private IP addresse  # Samba (Server Message block) SMB port: 139/445 Samba ``` [root@ip-10-10-0-30 ec2-user]# yum install samba samba-client samba-common -y ``` ## Configuration ``` [ec2-user@ip-10-10-0-30 ~]$ mkdir windowShare [ec2-user@ip-10-10-0-30 ~]$ sudo -s [root@ip-10-10-0-30 ec2-user]# chown nobody windowShare/ ```  ``` vim /etc/samba/smb.conf ``` ``` [publicMeowHeckerFolder] comment = meowmeow path = /home/ec2-user/windowShare guest ok = Yes read only = No writable = yes ``` ``` testparm ```  Writing passwords into the `passdb.tdb` file ``` [root@ip-10-10-0-30 ec2-user]# smbpasswd -a ec2-user New SMB password: Retype new SMB password: Added user ec2-user. ``` password -> meXXXXXXer ``` [root@ip-10-10-0-30 ec2-user]# systemctl restart smb ```  ``` \\54.174.144.134 ```   # NFS (Network File System) https://qizhanming.com/blog/2018/08/08/how-to-install-nfs-on-centos-7 AWS NFS https://medium.com/tensult/nfs-configuration-on-aws-environment-95fad703a78e ## Setting UP NFS server: Port: 2049 RPC ## RPC timeouts and communication issues the issues is dut to the firewall blockd (whitlist) ### BIND the RPC port Remote procedure call (Default: Dynamic Assignment) reference https://blog.csdn.net/Micha_Lu/article/details/125082164 ``` Identify the Required Ports: ``` ### Configure Static Ports ``` [root@ip-10-10-1-19 ec2-user]# echo "mountd 20048/tcp" >> /etc/services [root@ip-10-10-1-19 ec2-user]# echo "mountd 20048/udp" >> /etc/services ``` ``` [root@ip-10-10-1-19 ec2-user]# echo "fs.nfs.nlm_udpport=42315" >> /etc/sysctl.conf [root@ip-10-10-1-19 ec2-user]# echo "fs.nfs.nlm_tcpport=42315" >> /etc/sysctl.conf [root@ip-10-10-1-19 ec2-user]# sysctl -p ``` ``` [root@ip-10-10-1-19 ec2-user]# systemctl restart rpcbind [root@ip-10-10-1-19 ec2-user]# systemctl restart nfs-server.service ``` ### Port information ``` [root@ip-10-10-1-19 ec2-user]# rpcinfo -p | grep nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 3 tcp 2049 nfs_acl ```   ### SG-rules configuration Open Firewall Ports  ## Setting UP NFS server Private subNET 10.10.1.0/24 ``` [ec2-user@ip-10-10-1-19 ~]$ sudo yum install nfs-utils Amazon Linux 2023 repository 40 MB/s | 20 MB 00:00 Amazon Linux 2023 Kernel Livepatch repository 782 kB/s | 160 kB 00:00 Package nfs-utils-1:2.5.4-2.rc3.amzn2023.0.3.x86_64 is already installed. Dependencies resolved. Nothing to do. Complete! ``` ``` [root@ip-10-10-1-19 ec2-user]# systemctl enable rpcbind Created symlink /etc/systemd/system/multi-user.target.wants/rpcbind.service → /usr/lib/systemd/system/rpcbind.service. [root@ip-10-10-1-19 ec2-user]# systemctl enable nfs-server Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service. ``` ``` [root@ip-10-10-1-19 ec2-user]# mkdir nfsShare [root@ip-10-10-1-19 ec2-user]# ls nfsShare [root@ip-10-10-1-19 ec2-user]# chmod 755 nfsShare/ [root@ip-10-10-1-19 ec2-user]# vim /etc/exports ``` /etc/exports ``` /home/ec2-user/nfsShare 10.10.0.30(rw,sync,no_root_squash,no_all_squash) ``` ``` [root@ip-10-10-1-19 ec2-user]# systemctl restart nfs-server ``` ``` [root@ip-10-10-1-19 ec2-user]# showmount -e localhost Export list for localhost: /nfsShare/ 10.10.0.30 ``` ## Client  ``` [root@ip-10-10-0-30 windowShare]# yum install nfs-utils Last metadata expiration check: 4:04:07 ago on Sat Oct 21 13:15:44 2023. Package nfs-utils-1:2.5.4-2.rc3.amzn2023.0.3.x86_64 is already installed. Dependencies resolved. Nothing to do. Complete! ``` ``` [root@ip-10-10-0-30 windowShare]# systemctl enable rpcbind [root@ip-10-10-0-30 windowShare]# systemctl start rpcbind ``` ### Creating share folder ``` [root@ip-10-10-0-30 ec2-user]# mkdir -p /mnt/nfsShare ``` ### Showmount ``` [root@ip-10-10-0-30 ec2-user]# showmount -e 10.10.1.19 Export list for 10.10.1.19: /home/ec2-user/nfsShare 10.10.0.0/24 ``` ``` mount -t nfs 10.10.1.19:/home/ec2-user/nfsShare /home/ec2-user/mnt/nfsShare ``` ``` [root@ip-10-10-0-30 nfsShare]# mount -t nfs 10.10.1.19:/home/ec2-user/nfsShare /home/ec2-user/mnt/nfsShare ``` Result  # SMB + NFS + AWS ``` [smbAndNFS] comment = homework guest ok = Yes path = /home/ec2-user/mnt/nfsShare read only = No ``` ``` [root@ip-10-10-0-30 nfsShare]# systemctl enable smb.service Created symlink /etc/systemd/system/multi-user.target.wants/smb.service → /usr/lib/systemd/system/smb.service. [root@ip-10-10-0-30 nfsShare]# systemctl restart smb.service ```  
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up