Ubuntu20.04 set static IP, install Samba service, realize win10 remote access folder

The road is hindered and long, and the line is approaching. Keep your head down and work hard, if you don't talk, you will be a blockbuster! Come on, Sao Nian!

1 Reference

2 Talking

1. Why is there this article? Haven't you written several similar articles before?

  This article is a review of the results after I have used it for so long, so I feel it is necessary to summarize and record it for subsequent review.

  As for a few similar articles before, why write it? Because in the actual use of Ubuntu this time, I refer to my previous experience, and suddenly I feel that my previous experience is endless. I can only read a part of the content when reading an article. So it feels a bit awkward to operate.

2. Is there any difference or improvement between this article and the previous similar articles?

  There must be differences and improvements!

  • The first is the difference in the Ubuntu version. Before it was 18.04, this time I used the latest 20.04;

  • Secondly, this article will summarize a bit more comprehensively. It is not necessary to read it in conjunction with the referenced article to avoid abnormal results caused by understanding errors;

  • Also, as my thinking ability improves, the ideas of this article will be clearer and the reading experience will be better!

3 Ubuntu20.04 set static IP

3.1 Basic environment

  List my own basic environment first, so that we can find the differences between us through comparison

  • win10 professional edition system;
  • VMware 15 Pro;
  • Installed Ubuntu20.04 LTS 64-bit system; (refer to [Link 3] for installation)
  • One Dell laptop, which is only connected to the Internet via wifi;
  • One router that can be networked normally;

3.2 Configuration process record

3.2.1 Configure Bridge Mode

  If you installed Ubuntu 20.04 by referring to the tutorial of [Link 3], then Ubuntu should use NAT mode for Internet access.

image-20201018210834774

  At this time, you need to open the virtual machine settings and modify this method to: use a bridged network; the specific steps are as follows:

  • Open the current system of Ubuntu virtual machine tab;

    image-20201018211019891

  • Open Settings

image-20201018211324219

  • Find the Network Adapter Options, select the first bridge mode , then click OK , to exit;

image-20201018211449048

3.2.2 Set fixed IP

  The method used here is the netplan method used in the previous configuration of Ubuntu18.04. This method is more convenient to configure a fixed IP. Here is a brief summary of the configuration process:

  • Configure netplan's yaml syntax file, remember to back up the file first
# 备份文件
sudo cp /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all.yaml.bak

# 使用 vim 编辑配置文件
sudo vim /etc/netplan/01-network-manager-all.yaml
  • The contents of the original configuration file are as follows
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  • Need to be modified according to the following content format
# 此句前边的 # ,是注释的意思;
# 翻译:让NetworkManager管理此系统上的所有设备
# Let NetworkManager manage all devices on this system
 
# 网络,此处是设置参数的主要地方
network:
 
    # 此段为新增语句,需要有4个空格来对齐位置,且冒号后边也需要有一个空格,再回车;
    ethernets:
 
        # ens33 代表网卡,可以先去终端输入 ifconfig 命令查看;
        ens33:
 
            # IP地址:192.168.1.105
            # 后边的 “/24” :参考之前的文章确实是子网掩码中1的个数,代表 255.255.255.0,不过不是
            #               八进制,而是十进制,我还特意算了一下,一个255有8个1,三个255就是24个 
            #               1,这可能是一种简便写法吧;
            addresses: [192.168.1.105/24]
 
            gateway4: 192.168.1.1        # 网关,跟路由器的保持一致即可;
            nameservers:
                addresses: [192.168.1.1] # 代理服务器,就是常说的DNS,可根据需要自行更改;
    version: 2                           # 原语句,保留;
 
# 此句需要注释掉,可能是因为我们修改了固定IP的原因
# renderer: NetworkManager

Precautions:

1. Between each level, 4 spaces are required to align the position;

2. You need to add a space after each colon, and then wrap;

  • After the configuration is completed, ESC -> colon -> wq, save and exit the file;
  • Use the following command to make the newly configured content effective
sudo netplan apply
  • At this point, you can use the ifconfig command again to view the current network configuration, and you can find that the IP has been modified to a static IP;

3.2.3 Matters needing attention

  During the installation process, you need to pay attention to the following

  1. The above operations are carried out under the root user, if you are a normal user, please add sudo by yourself;
  2. Comment the renderer: NetworkManager in the /etc/netplan/01-network-manager-all.yaml file, otherwise the netplan command will not take effect;
  3. The IP configuration information should be in the above format, using the yaml syntax format, and each configuration item should be indented with a space to indicate the level;
  4. The corresponding configuration item is followed by a colon, followed by a space, otherwise the netplan command will report an error;

3.3 Install ssh service

  If you want to use other remote connection software, you also need to install the ssh service for Ubuntu. The specific process is briefly summarized as follows

# 安装 ssh 客户端
sudo aptitude install openssh-client

# 安装 ssh 服务端
sudo aptitude install openssh-server

  After installation, use the following command to view the current ssh related process

ps -e | grep ssh

  If the sshd related process appears , it means the installation is successful; at this time, you can use the remote connection software to try to connect.

4 Ubuntu20.04 configure Samba and use

  The basic environment can directly use the previously installed environment.

  Refer to [Link 4] for the following configuration process, and the problem that cannot be written has been resolved.

4.1 Install Samba

  Some systems will come with Samba program, you can use the query version command to verify whether Samba is installed

# 注意 V 是大写
samba -V

  If the version number can be displayed normally, it means it has been installed; otherwise, use the following command to install the program

# 更新同步系统软件源
sudo aptitude update
sudo aptitude upgrade

# 安装 samba
sudo aptitude install samba

# 安装 smbclient
sudo aptitude install smbclient

  Similarly, after the installation is complete, check the Samba version

# 注意 V 是大写
samba -V

4.2 Configure Samba server

  After the Samba program is installed, we need to make some changes to the configuration file to achieve our purpose.

  • Modify the configuration file of Samba, pay attention to backup the file first;
# 备份文件
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

# 使用 vim 编辑文件
sudo vim /etc/samba/smb.conf
  • Add the following content at the end of the file, pay attention to the space indentation, then save and exit;
[share]
   comment = share folder
   browseable = yes
   path = /home
   read only = no
   create mask = 0777
   directory mask = 0777
   valid users = zhaoc
   force user = nobody
   force group = nogroup
   public = yes
   available = yes

Related description

path: represents the file path to be shared, I use home directly, which is equivalent to sharing the entire contents of the home folder;

read only: means not only read-only permission;

valid users: represents valid users; that is, the account name that needs to be entered when connecting to Ubuntu through win10;

  • Next, you need to add users to the Samba server, use the following command
# 添加用户名 zhaoc 
sudo smbpasswd -a zhaoc

# 接着会提示输入密码
# 接着会再次确认密码
  • Next, you need to give the shared path read and write permissions. Because I shared the home folder, but normally only the root user can operate it, and other users cannot operate it. At this time, the "cannot write" problem may occur. Therefore, you need to modify the folder permissions, use the following command
# 使用 -R 递归修改此目录及所有子目录
sudo chmod 777 -R /home/
  • Then try the following two commands to restart the Samba service;
# 这条命令是参考其他的经验
sudo /etc/init.d/samba-ad-dc restart

# 这条命令对我有效
sudo service smbd restart

4.3 Using Samba to remotely access folders

4.3.1 Command Window Access

  • Use windows + R, enter commands and access folders;

image-20201018234433227

  • Prompt for credentials, then enter the user password added to the Samba server. You can consider checking the credentials to facilitate the next use;

4.3.2 Shortcut access

  • Right click, new, shortcut

image-20201018234714876

  • Enter the path of the shared folder and add it to the desktop to achieve shortcut access;

image-20201018234828669

image-20201018234859191

  • The interface after successfully adding the shortcut is as follows, double-click to achieve quick access!

image-20201018234916561

5 System virtual machine backup

  The installation is complete, but don't be too happy, and you must remember to back it up, otherwise you will have to reinstall it all next time if there is a problem!

  For system backup, please refer to the "Ubuntu System Backup" chapter of [Link 3], and use the virtual machine to save the snapshot again.

6 Summary

  1. It is a meticulous summary of some basic configuration processes;
  2. Solved the problem of one-sided description of the original blog post and inconvenient access;
  3. As your own notes, it is convenient for yourself and others. I hope it will be useful to you!

If the content of the article is wrong, please comment / private message a lot of advice! If you think the content of the article is not bad, remember to click the four links (like, bookmark, leave a message, follow), if you can click a follow, that is the greatest encouragement to me, and it will be the motivation for my creation, thank you !

Guess you like

Origin blog.csdn.net/fighting_boom/article/details/109152708